@pezkuwi/extension-dapp 0.62.11 → 0.62.13
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 +201 -0
- package/bundle-pezkuwi-extension-dapp.js +205 -0
- package/bundle.js +139 -302
- package/cjs/bundle.d.ts +61 -0
- package/cjs/bundle.js +246 -0
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +4 -0
- package/cjs/package.json +3 -0
- package/cjs/packageDetect.d.ts +1 -0
- package/cjs/packageDetect.js +6 -0
- package/cjs/packageInfo.d.ts +6 -0
- package/cjs/packageInfo.js +4 -0
- package/cjs/util.d.ts +1 -0
- package/cjs/util.js +13 -0
- package/cjs/wrapBytes.d.ts +7 -0
- package/cjs/wrapBytes.js +10 -0
- package/index.js +0 -4
- package/package.json +112 -7
- package/packageDetect.js +0 -4
- package/packageInfo.js +1 -4
- package/util.js +2 -4
- package/wrapBytes.js +6 -8
package/bundle.js
CHANGED
|
@@ -1,138 +1,66 @@
|
|
|
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
1
|
import { isPromise, objectSpread, u8aEq } from '@pezkuwi/util';
|
|
40
2
|
import { decodeAddress, encodeAddress } from '@pezkuwi/util-crypto';
|
|
41
3
|
import { documentReadyPromise } from './util.js';
|
|
42
|
-
// expose utility functions
|
|
43
4
|
export { packageInfo } from './packageInfo.js';
|
|
44
5
|
export { unwrapBytes, wrapBytes } from './wrapBytes.js';
|
|
45
|
-
|
|
46
|
-
var win = window;
|
|
47
|
-
// don't clobber the existing object, but ensure non-undefined
|
|
6
|
+
const win = window;
|
|
48
7
|
win.injectedWeb3 = win.injectedWeb3 || {};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// we keep the last promise created around (for queries)
|
|
52
|
-
var web3EnablePromise = null;
|
|
8
|
+
let isWeb3Injected = web3IsInjected();
|
|
9
|
+
let web3EnablePromise = null;
|
|
53
10
|
export { isWeb3Injected, web3EnablePromise };
|
|
54
11
|
/** @internal true when anything has been injected and is available */
|
|
55
12
|
function web3IsInjected() {
|
|
56
13
|
return Object
|
|
57
14
|
.values(win.injectedWeb3)
|
|
58
|
-
.filter(
|
|
59
|
-
var connect = _a.connect, enable = _a.enable;
|
|
60
|
-
return !!(connect || enable);
|
|
61
|
-
})
|
|
15
|
+
.filter(({ connect, enable }) => !!(connect || enable))
|
|
62
16
|
.length !== 0;
|
|
63
17
|
}
|
|
64
18
|
/** @internal throw a consistent error when not extensions have not been enabled */
|
|
65
19
|
function throwError(method) {
|
|
66
|
-
throw new Error(
|
|
20
|
+
throw new Error(`${method}: web3Enable(originName) needs to be called before ${method}`);
|
|
67
21
|
}
|
|
68
22
|
/** @internal map from Array<InjectedAccount> to Array<InjectedAccountWithMeta> */
|
|
69
23
|
function mapAccounts(source, list, ss58Format) {
|
|
70
|
-
return list.map(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
type: type
|
|
78
|
-
});
|
|
79
|
-
});
|
|
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
|
+
}));
|
|
80
31
|
}
|
|
81
32
|
/** @internal filter accounts based on genesisHash and type of account */
|
|
82
33
|
function filterAccounts(list, genesisHash, type) {
|
|
83
|
-
return list.filter(
|
|
84
|
-
|
|
85
|
-
(!a.genesisHash || !genesisHash || a.genesisHash === genesisHash);
|
|
86
|
-
});
|
|
34
|
+
return list.filter((a) => (!a.type || !type || type.includes(a.type)) &&
|
|
35
|
+
(!a.genesisHash || !genesisHash || a.genesisHash === genesisHash));
|
|
87
36
|
}
|
|
88
37
|
/** @internal retrieves all the extensions available on the window */
|
|
89
38
|
function getWindowExtensions(originName) {
|
|
90
39
|
return Promise
|
|
91
40
|
.all(Object
|
|
92
41
|
.entries(win.injectedWeb3)
|
|
93
|
-
.map(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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; }); });
|
|
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));
|
|
114
55
|
}
|
|
115
56
|
/** @internal Ensure the enable promise is resolved and filter by extensions */
|
|
116
|
-
function filterEnable(caller, extensions) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
});
|
|
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));
|
|
136
64
|
}
|
|
137
65
|
/**
|
|
138
66
|
* @summary Enables all the providers found on the injected window interface
|
|
@@ -140,46 +68,36 @@ function filterEnable(caller, extensions) {
|
|
|
140
68
|
* Enables all injected extensions that has been found on the page. This
|
|
141
69
|
* should be called before making use of any other web3* functions.
|
|
142
70
|
*/
|
|
143
|
-
export function web3Enable(originName, compatInits) {
|
|
144
|
-
if (compatInits === void 0) { compatInits = []; }
|
|
71
|
+
export function web3Enable(originName, compatInits = []) {
|
|
145
72
|
if (!originName) {
|
|
146
73
|
throw new Error('You must pass a name for your app to the web3Enable function');
|
|
147
74
|
}
|
|
148
|
-
|
|
149
|
-
? Promise.all(compatInits.map(
|
|
75
|
+
const initCompat = compatInits.length
|
|
76
|
+
? Promise.all(compatInits.map((c) => c().catch(() => false)))
|
|
150
77
|
: Promise.resolve([true]);
|
|
151
|
-
web3EnablePromise = documentReadyPromise(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
});
|
|
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
|
+
})));
|
|
183
101
|
return web3EnablePromise;
|
|
184
102
|
}
|
|
185
103
|
/**
|
|
@@ -190,47 +108,24 @@ export function web3Enable(originName, compatInits) {
|
|
|
190
108
|
* per-genesisHash basis. Optionally the accounts can be encoded with the provided
|
|
191
109
|
* ss58Format
|
|
192
110
|
*/
|
|
193
|
-
export function web3Accounts() {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
});
|
|
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);
|
|
233
126
|
});
|
|
127
|
+
console.info(`web3Accounts: Found ${accounts.length} address${accounts.length !== 1 ? 'es' : ''}`);
|
|
128
|
+
return accounts;
|
|
234
129
|
}
|
|
235
130
|
/**
|
|
236
131
|
* @summary Subscribes to all the accounts across all providers
|
|
@@ -239,48 +134,32 @@ export function web3Accounts() {
|
|
|
239
134
|
* updates as to when new accounts do become available. The list of filtering
|
|
240
135
|
* options are the same as for the web3Accounts interface.
|
|
241
136
|
*/
|
|
242
|
-
export function web3AccountsSubscribe(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
}];
|
|
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);
|
|
281
152
|
}
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
console.error(error);
|
|
156
|
+
}
|
|
157
|
+
}));
|
|
158
|
+
return () => {
|
|
159
|
+
unsubs.forEach((unsub) => {
|
|
160
|
+
unsub();
|
|
282
161
|
});
|
|
283
|
-
}
|
|
162
|
+
};
|
|
284
163
|
}
|
|
285
164
|
/**
|
|
286
165
|
* @summary Finds a specific provider based on the name
|
|
@@ -290,29 +169,16 @@ export function web3AccountsSubscribe(cb_1) {
|
|
|
290
169
|
* by calls such as web3FromAddress) but would allow operation on a specific
|
|
291
170
|
* known extension.
|
|
292
171
|
*/
|
|
293
|
-
export function web3FromSource(source) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
-
});
|
|
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;
|
|
316
182
|
}
|
|
317
183
|
/**
|
|
318
184
|
* @summary Find a specific provider that provides a specific address
|
|
@@ -320,29 +186,20 @@ export function web3FromSource(source) {
|
|
|
320
186
|
* Based on an address, return the provider that has makes this address
|
|
321
187
|
* available to the page.
|
|
322
188
|
*/
|
|
323
|
-
export function web3FromAddress(address) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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
|
-
});
|
|
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);
|
|
346
203
|
}
|
|
347
204
|
/**
|
|
348
205
|
* @summary List all providers exposed by one source
|
|
@@ -350,22 +207,13 @@ export function web3FromAddress(address) {
|
|
|
350
207
|
* For extensions that supply RPC providers, this call would return the list
|
|
351
208
|
* of RPC providers that any extension may supply.
|
|
352
209
|
*/
|
|
353
|
-
export function web3ListRpcProviders(source) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
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
|
-
});
|
|
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();
|
|
369
217
|
}
|
|
370
218
|
/**
|
|
371
219
|
* @summary Start an RPC provider provider by a specific source
|
|
@@ -374,22 +222,11 @@ export function web3ListRpcProviders(source) {
|
|
|
374
222
|
* enabled provider (initialized with the specific key) from the
|
|
375
223
|
* specified extension source.
|
|
376
224
|
*/
|
|
377
|
-
export function web3UseRpcProvider(source, key) {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
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
|
-
});
|
|
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 };
|
|
395
232
|
}
|
package/cjs/bundle.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { InjectedAccountWithMeta, InjectedExtension, InjectedProviderWithMeta, ProviderList, Unsubcall, Web3AccountsOptions } from '@pezkuwi/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>;
|