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