@subwallet/extension-inject 0.3.6-0

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.
Files changed (50) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +19 -0
  3. package/build/LICENSE +201 -0
  4. package/build/README.md +19 -0
  5. package/build/bundle.d.ts +3 -0
  6. package/build/bundle.js +20 -0
  7. package/build/chrome.d.ts +2 -0
  8. package/build/chrome.js +4 -0
  9. package/build/cjs/bundle.js +35 -0
  10. package/build/cjs/chrome.js +13 -0
  11. package/build/cjs/crossenv.js +7 -0
  12. package/build/cjs/detectOther.js +11 -0
  13. package/build/cjs/detectPackage.js +14 -0
  14. package/build/cjs/index.js +18 -0
  15. package/build/cjs/package.json +3 -0
  16. package/build/cjs/packageInfo.js +16 -0
  17. package/build/cjs/types.js +1 -0
  18. package/build/crossenv.d.ts +1 -0
  19. package/build/crossenv.js +4 -0
  20. package/build/detectOther.d.ts +2 -0
  21. package/build/detectOther.js +4 -0
  22. package/build/detectPackage.d.ts +1 -0
  23. package/build/detectPackage.js +7 -0
  24. package/build/index.d.ts +1 -0
  25. package/build/index.js +5 -0
  26. package/build/package.json +82 -0
  27. package/build/packageInfo.d.ts +6 -0
  28. package/build/packageInfo.js +9 -0
  29. package/build/types.d.ts +88 -0
  30. package/build/types.js +1 -0
  31. package/build-cjs/bundle.js +35 -0
  32. package/build-cjs/chrome.js +13 -0
  33. package/build-cjs/crossenv.js +7 -0
  34. package/build-cjs/detectOther.js +11 -0
  35. package/build-cjs/detectPackage.js +14 -0
  36. package/build-cjs/index.js +18 -0
  37. package/build-cjs/packageInfo.js +16 -0
  38. package/build-cjs/types.js +1 -0
  39. package/package.json +34 -0
  40. package/src/bundle.ts +24 -0
  41. package/src/chrome.ts +6 -0
  42. package/src/crossenv.ts +6 -0
  43. package/src/detectOther.ts +6 -0
  44. package/src/detectPackage.ts +11 -0
  45. package/src/index.ts +7 -0
  46. package/src/packageInfo.ts +6 -0
  47. package/src/types.ts +117 -0
  48. package/tsconfig.build.json +9 -0
  49. package/tsconfig.build.tsbuildinfo +1 -0
  50. package/tsconfig.json +9 -0
@@ -0,0 +1,82 @@
1
+ {
2
+ "author": "Jaco Greeff <jacogr@gmail.com>",
3
+ "bugs": "https://github.com/Koniverse/Subwallet-V2/issues",
4
+ "contributors": [],
5
+ "description": "A generic injector (usable to any extension), that populates the base exposed interfaces to be used by dapps.",
6
+ "homepage": "https://github.com/Koniverse/Subwallet-V2/tree/master/packages/extension-inject#readme",
7
+ "license": "Apache-2.0",
8
+ "maintainers": [],
9
+ "name": "@subwallet/extension-inject",
10
+ "repository": {
11
+ "directory": "packages/extension-inject",
12
+ "type": "git",
13
+ "url": "https://github.com/Koniverse/Subwallet-V2.git"
14
+ },
15
+ "sideEffects": true,
16
+ "type": "module",
17
+ "version": "0.3.6-0",
18
+ "main": "./cjs/index.js",
19
+ "module": "./index.js",
20
+ "types": "./index.d.ts",
21
+ "exports": {
22
+ "./cjs/package.json": "./cjs/package.json",
23
+ "./cjs/*": "./cjs/*.js",
24
+ ".": {
25
+ "types": "./index.d.ts",
26
+ "require": "./cjs/index.js",
27
+ "default": "./index.js"
28
+ },
29
+ "./bundle": {
30
+ "types": "./bundle.d.ts",
31
+ "require": "./cjs/bundle.js",
32
+ "default": "./bundle.js"
33
+ },
34
+ "./chrome": {
35
+ "types": "./chrome.d.ts",
36
+ "require": "./cjs/chrome.js",
37
+ "default": "./chrome.js"
38
+ },
39
+ "./crossenv": {
40
+ "types": "./crossenv.d.ts",
41
+ "require": "./cjs/crossenv.js",
42
+ "default": "./crossenv.js"
43
+ },
44
+ "./detectOther": {
45
+ "types": "./detectOther.d.ts",
46
+ "require": "./cjs/detectOther.js",
47
+ "default": "./detectOther.js"
48
+ },
49
+ "./detectPackage": {
50
+ "types": "./detectPackage.d.ts",
51
+ "require": "./cjs/detectPackage.js",
52
+ "default": "./detectPackage.js"
53
+ },
54
+ "./package.json": "./package.json",
55
+ "./packageInfo.js": {
56
+ "types": "./packageInfo.d.ts",
57
+ "require": "./cjs/packageInfo.js",
58
+ "default": "./packageInfo.js"
59
+ },
60
+ "./packageInfo": {
61
+ "types": "./packageInfo.d.ts",
62
+ "require": "./cjs/packageInfo.js",
63
+ "default": "./packageInfo.js"
64
+ },
65
+ "./types": {
66
+ "types": "./types.d.ts",
67
+ "require": "./cjs/types.js",
68
+ "default": "./types.js"
69
+ }
70
+ },
71
+ "dependencies": {
72
+ "@babel/runtime": "^7.16.7",
73
+ "@polkadot/rpc-provider": "^7.3.1",
74
+ "@polkadot/types": "^7.3.1",
75
+ "@polkadot/util": "^8.3.1",
76
+ "@polkadot/util-crypto": "^8.3.1",
77
+ "@polkadot/x-global": "^8.3.1"
78
+ },
79
+ "peerDependencies": {
80
+ "@polkadot/api": "*"
81
+ }
82
+ }
@@ -0,0 +1,6 @@
1
+ export declare const packageInfo: {
2
+ name: string;
3
+ path: string;
4
+ type: string;
5
+ version: string;
6
+ };
@@ -0,0 +1,9 @@
1
+ // Copyright 2017-2022 @subwallet/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // Do not edit, auto-generated by @polkadot/dev
4
+ export const packageInfo = {
5
+ name: '@subwallet/extension-inject',
6
+ path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
7
+ type: 'esm',
8
+ version: '0.3.6-0'
9
+ };
@@ -0,0 +1,88 @@
1
+ import type { Signer as InjectedSigner } from '@polkadot/api/types';
2
+ import type { ProviderInterface } from '@polkadot/rpc-provider/types';
3
+ import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
4
+ import type { KeypairType } from '@polkadot/util-crypto/types';
5
+ declare type This = typeof globalThis;
6
+ export declare type Unsubcall = () => void;
7
+ export interface InjectedAccount {
8
+ address: string;
9
+ genesisHash?: string | null;
10
+ name?: string;
11
+ type?: KeypairType;
12
+ }
13
+ export interface InjectedAccountWithMeta {
14
+ address: string;
15
+ meta: {
16
+ genesisHash?: string | null;
17
+ name?: string;
18
+ source: string;
19
+ };
20
+ type?: KeypairType;
21
+ }
22
+ export interface InjectedAccounts {
23
+ get: (anyType?: boolean) => Promise<InjectedAccount[]>;
24
+ subscribe: (cb: (accounts: InjectedAccount[]) => void | Promise<void>) => Unsubcall;
25
+ }
26
+ export interface InjectedExtensionInfo {
27
+ name: string;
28
+ version: string;
29
+ }
30
+ export interface ProviderMeta {
31
+ network: string;
32
+ node: 'full' | 'light';
33
+ source: string;
34
+ transport: string;
35
+ }
36
+ export interface MetadataDefBase {
37
+ chain: string;
38
+ genesisHash: string;
39
+ icon: string;
40
+ ss58Format: number;
41
+ chainType?: 'substrate' | 'ethereum';
42
+ }
43
+ export interface MetadataDef extends MetadataDefBase {
44
+ color?: string;
45
+ specVersion: number;
46
+ tokenDecimals: number;
47
+ tokenSymbol: string;
48
+ types: Record<string, Record<string, string> | string>;
49
+ metaCalls?: string;
50
+ userExtensions?: ExtDef;
51
+ }
52
+ export interface InjectedMetadataKnown {
53
+ genesisHash: string;
54
+ specVersion: number;
55
+ }
56
+ export interface InjectedMetadata {
57
+ get: () => Promise<InjectedMetadataKnown[]>;
58
+ provide: (definition: MetadataDef) => Promise<boolean>;
59
+ }
60
+ export declare type ProviderList = Record<string, ProviderMeta>;
61
+ export interface InjectedProvider extends ProviderInterface {
62
+ listProviders: () => Promise<ProviderList>;
63
+ startProvider: (key: string) => Promise<ProviderMeta>;
64
+ }
65
+ export interface InjectedProviderWithMeta {
66
+ provider: InjectedProvider;
67
+ meta: ProviderMeta;
68
+ }
69
+ export interface Injected {
70
+ accounts: InjectedAccounts;
71
+ metadata?: InjectedMetadata;
72
+ provider?: InjectedProvider;
73
+ signer: InjectedSigner;
74
+ }
75
+ export interface InjectedWindowProvider {
76
+ enable: (origin: string) => Promise<Injected>;
77
+ version: string;
78
+ }
79
+ export interface InjectedWindow extends This {
80
+ injectedWeb3: Record<string, InjectedWindowProvider>;
81
+ }
82
+ export declare type InjectedExtension = InjectedExtensionInfo & Injected;
83
+ export declare type InjectOptions = InjectedExtensionInfo;
84
+ export interface Web3AccountsOptions {
85
+ ss58Format?: number;
86
+ accountType?: KeypairType[];
87
+ }
88
+ export {};
package/build/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.injectExtension = injectExtension;
7
+ Object.defineProperty(exports, "packageInfo", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _packageInfo.packageInfo;
11
+ }
12
+ });
13
+
14
+ var _packageInfo = require("./packageInfo");
15
+
16
+ // Copyright 2019-2022 @subwallet/extension-inject authors & contributors
17
+ // SPDX-License-Identifier: Apache-2.0
18
+ // It is recommended to always use the function below to shield the extension and dapp from
19
+ // any future changes. The exposed interface will manage access between the 2 environments,
20
+ // be it via window (current), postMessage (under consideration) or any other mechanism
21
+ function injectExtension(enable, _ref) {
22
+ let {
23
+ name,
24
+ version
25
+ } = _ref;
26
+ // small helper with the typescript types, just cast window
27
+ const windowInject = window; // don't clobber the existing object, we will add it (or create as needed)
28
+
29
+ windowInject.injectedWeb3 = windowInject.injectedWeb3 || {}; // add our enable function
30
+
31
+ windowInject.injectedWeb3[name] = {
32
+ enable: origin => enable(origin),
33
+ version
34
+ };
35
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.chrome = void 0;
7
+
8
+ var _xGlobal = require("@polkadot/x-global");
9
+
10
+ // Copyright 2019-2022 @subwallet/extension-inject authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+ const chrome = (0, _xGlobal.extractGlobal)('chrome', _xGlobal.xglobal.browser);
13
+ exports.chrome = chrome;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ var _xGlobal = require("@polkadot/x-global");
4
+
5
+ // Copyright 2019-2022 @subwallet/extension-inject authors & contributors
6
+ // SPDX-License-Identifier: Apache-2.0
7
+ (0, _xGlobal.exposeGlobal)('chrome', _xGlobal.xglobal.browser);
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ // Copyright 2017-2022 @subwallet/extension-inject authors & contributors
8
+ // SPDX-License-Identifier: Apache-2.0
9
+ // Empty template, auto-generated by @polkadot/dev
10
+ var _default = [];
11
+ exports.default = _default;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _util = require("@polkadot/util");
6
+
7
+ var _detectOther = _interopRequireDefault(require("./detectOther"));
8
+
9
+ var _packageInfo = require("./packageInfo");
10
+
11
+ // Copyright 2017-2022 @subwallet/extension-inject authors & contributors
12
+ // SPDX-License-Identifier: Apache-2.0
13
+ // Do not edit, auto-generated by @polkadot/dev
14
+ (0, _util.detectPackage)(_packageInfo.packageInfo, null, _detectOther.default);
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _bundle = require("./bundle");
8
+
9
+ Object.keys(_bundle).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _bundle[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _bundle[key];
16
+ }
17
+ });
18
+ });
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.packageInfo = void 0;
7
+ // Copyright 2017-2022 @subwallet/extension-inject authors & contributors
8
+ // SPDX-License-Identifier: Apache-2.0
9
+ // Do not edit, auto-generated by @polkadot/dev
10
+ const packageInfo = {
11
+ name: '@subwallet/extension-inject',
12
+ path: typeof __dirname === 'string' ? __dirname : 'auto',
13
+ type: 'cjs',
14
+ version: '0.3.6-0'
15
+ };
16
+ exports.packageInfo = packageInfo;
@@ -0,0 +1 @@
1
+ "use strict";
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "author": "Jaco Greeff <jacogr@gmail.com>",
3
+ "bugs": "https://github.com/Koniverse/Subwallet-V2/issues",
4
+ "contributors": [],
5
+ "description": "A generic injector (usable to any extension), that populates the base exposed interfaces to be used by dapps.",
6
+ "homepage": "https://github.com/Koniverse/Subwallet-V2/tree/master/packages/extension-inject#readme",
7
+ "license": "Apache-2.0",
8
+ "maintainers": [],
9
+ "name": "@subwallet/extension-inject",
10
+ "repository": {
11
+ "directory": "packages/extension-inject",
12
+ "type": "git",
13
+ "url": "https://github.com/Koniverse/Subwallet-V2.git"
14
+ },
15
+ "sideEffects": true,
16
+ "type": "module",
17
+ "version": "0.3.6-0",
18
+ "main": "index.js",
19
+ "dependencies": {
20
+ "@babel/runtime": "^7.16.7",
21
+ "@polkadot/rpc-provider": "^7.3.1",
22
+ "@polkadot/types": "^7.3.1",
23
+ "@polkadot/util": "^8.3.1",
24
+ "@polkadot/util-crypto": "^8.3.1",
25
+ "@polkadot/x-global": "^8.3.1"
26
+ },
27
+ "devDependencies": {
28
+ "@types/chrome": "^0.0.175",
29
+ "@types/firefox-webext-browser": "^94.0.1"
30
+ },
31
+ "peerDependencies": {
32
+ "@polkadot/api": "*"
33
+ }
34
+ }
package/src/bundle.ts ADDED
@@ -0,0 +1,24 @@
1
+ // Copyright 2019-2022 @subwallet/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Injected, InjectedWindow, InjectOptions } from './types';
5
+
6
+ export { packageInfo } from './packageInfo';
7
+
8
+ // It is recommended to always use the function below to shield the extension and dapp from
9
+ // any future changes. The exposed interface will manage access between the 2 environments,
10
+ // be it via window (current), postMessage (under consideration) or any other mechanism
11
+ export function injectExtension (enable: (origin: string) => Promise<Injected>, { name, version }: InjectOptions): void {
12
+ // small helper with the typescript types, just cast window
13
+ const windowInject = window as Window & InjectedWindow;
14
+
15
+ // don't clobber the existing object, we will add it (or create as needed)
16
+ windowInject.injectedWeb3 = windowInject.injectedWeb3 || {};
17
+
18
+ // add our enable function
19
+ windowInject.injectedWeb3[name] = {
20
+ enable: (origin: string): Promise<Injected> =>
21
+ enable(origin),
22
+ version
23
+ };
24
+ }
package/src/chrome.ts ADDED
@@ -0,0 +1,6 @@
1
+ // Copyright 2019-2022 @subwallet/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { extractGlobal, xglobal } from '@polkadot/x-global';
5
+
6
+ export const chrome = extractGlobal('chrome', xglobal.browser);
@@ -0,0 +1,6 @@
1
+ // Copyright 2019-2022 @subwallet/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { exposeGlobal, xglobal } from '@polkadot/x-global';
5
+
6
+ exposeGlobal('chrome', xglobal.browser);
@@ -0,0 +1,6 @@
1
+ // Copyright 2017-2022 @subwallet/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Empty template, auto-generated by @polkadot/dev
5
+
6
+ export default [];
@@ -0,0 +1,11 @@
1
+ // Copyright 2017-2022 @subwallet/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Do not edit, auto-generated by @polkadot/dev
5
+
6
+ import { detectPackage } from '@polkadot/util';
7
+
8
+ import others from './detectOther';
9
+ import { packageInfo } from './packageInfo';
10
+
11
+ detectPackage(packageInfo, null, others);
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ // Copyright 2019-2022 @subwallet/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Since we inject into pages, we skip this
5
+ // import './detectPackage';
6
+
7
+ export * from './bundle';
@@ -0,0 +1,6 @@
1
+ // Copyright 2017-2022 @subwallet/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Do not edit, auto-generated by @polkadot/dev
5
+
6
+ export const packageInfo = { name: '@subwallet/extension-inject', path: 'auto', type: 'auto', version: '0.3.6-0' };
package/src/types.ts ADDED
@@ -0,0 +1,117 @@
1
+ // Copyright 2019-2022 @subwallet/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Signer as InjectedSigner } from '@polkadot/api/types';
5
+ import type { ProviderInterface } from '@polkadot/rpc-provider/types';
6
+ import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
7
+ import type { KeypairType } from '@polkadot/util-crypto/types';
8
+
9
+ // eslint-disable-next-line no-undef
10
+ type This = typeof globalThis;
11
+
12
+ export type Unsubcall = () => void;
13
+
14
+ export interface InjectedAccount {
15
+ address: string;
16
+ genesisHash?: string | null;
17
+ name?: string;
18
+ type?: KeypairType;
19
+ }
20
+
21
+ export interface InjectedAccountWithMeta {
22
+ address: string;
23
+ meta: {
24
+ genesisHash?: string | null;
25
+ name?: string;
26
+ source: string;
27
+ };
28
+ type?: KeypairType;
29
+ }
30
+
31
+ export interface InjectedAccounts {
32
+ get: (anyType?: boolean) => Promise<InjectedAccount[]>;
33
+ subscribe: (cb: (accounts: InjectedAccount[]) => void | Promise<void>) => Unsubcall;
34
+ }
35
+
36
+ export interface InjectedExtensionInfo {
37
+ name: string;
38
+ version: string;
39
+ }
40
+
41
+ // Metadata about a provider
42
+ export interface ProviderMeta {
43
+ // Network of the provider
44
+ network: string;
45
+ // Light or full node
46
+ node: 'full' | 'light';
47
+ // The extension source
48
+ source: string;
49
+ // Provider transport: 'WsProvider' etc.
50
+ transport: string;
51
+ }
52
+
53
+ export interface MetadataDefBase {
54
+ chain: string;
55
+ genesisHash: string;
56
+ icon: string;
57
+ ss58Format: number;
58
+ chainType?: 'substrate' | 'ethereum'
59
+ }
60
+
61
+ export interface MetadataDef extends MetadataDefBase {
62
+ color?: string;
63
+ specVersion: number;
64
+ tokenDecimals: number;
65
+ tokenSymbol: string;
66
+ types: Record<string, Record<string, string> | string>;
67
+ metaCalls?: string;
68
+ userExtensions?: ExtDef;
69
+ }
70
+
71
+ export interface InjectedMetadataKnown {
72
+ genesisHash: string;
73
+ specVersion: number;
74
+ }
75
+
76
+ export interface InjectedMetadata {
77
+ get: () => Promise<InjectedMetadataKnown[]>;
78
+ provide: (definition: MetadataDef) => Promise<boolean>;
79
+ }
80
+
81
+ export type ProviderList = Record<string, ProviderMeta>
82
+
83
+ export interface InjectedProvider extends ProviderInterface {
84
+ listProviders: () => Promise<ProviderList>;
85
+ startProvider: (key: string) => Promise<ProviderMeta>;
86
+ }
87
+
88
+ export interface InjectedProviderWithMeta {
89
+ // provider will actually always be a PostMessageProvider, which implements InjectedProvider
90
+ provider: InjectedProvider;
91
+ meta: ProviderMeta;
92
+ }
93
+
94
+ export interface Injected {
95
+ accounts: InjectedAccounts;
96
+ metadata?: InjectedMetadata;
97
+ provider?: InjectedProvider;
98
+ signer: InjectedSigner;
99
+ }
100
+
101
+ export interface InjectedWindowProvider {
102
+ enable: (origin: string) => Promise<Injected>;
103
+ version: string;
104
+ }
105
+
106
+ export interface InjectedWindow extends This {
107
+ injectedWeb3: Record<string, InjectedWindowProvider>;
108
+ }
109
+
110
+ export type InjectedExtension = InjectedExtensionInfo & Injected;
111
+
112
+ export type InjectOptions = InjectedExtensionInfo;
113
+
114
+ export interface Web3AccountsOptions {
115
+ ss58Format?: number,
116
+ accountType?: KeypairType[]
117
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "baseUrl": "..",
5
+ "outDir": "./build",
6
+ "rootDir": "./src"
7
+ },
8
+ "references": []
9
+ }