@subwallet/extension-chains 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.
@@ -0,0 +1,7 @@
1
+ declare const _default: {
2
+ name: string;
3
+ path: string;
4
+ type: string;
5
+ version: string;
6
+ }[];
7
+ export default _default;
@@ -0,0 +1,4 @@
1
+ // Copyright 2017-2022 @subwallet/extension-chains authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { packageInfo as injectInfo } from '@subwallet/extension-inject/packageInfo';
4
+ export default [injectInfo];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ // Copyright 2017-2022 @subwallet/extension-chains authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // Do not edit, auto-generated by @polkadot/dev
4
+ import { detectPackage } from '@polkadot/util';
5
+ import others from "./detectOther.js";
6
+ import { packageInfo } from "./packageInfo.js";
7
+ detectPackage(packageInfo, null, others);
@@ -0,0 +1 @@
1
+ export * from './bundle';
package/build/index.js ADDED
@@ -0,0 +1,5 @@
1
+ // Copyright 2019-2022 @subwallet/extension-chains authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // Since we inject into pages, we skip this
4
+ // import './detectPackage';
5
+ export * from "./bundle.js";
@@ -0,0 +1,75 @@
1
+ {
2
+ "author": "Jaco Greeff <jacogr@gmail.com>",
3
+ "bugs": "https://github.com/Koniverse/Subwallet-V2/issues",
4
+ "contributors": [],
5
+ "description": "Definitions for all known chains as exposed by the extension.",
6
+ "homepage": "https://github.com/Koniverse/Subwallet-V2/tree/master/packages/extension-chains#readme",
7
+ "license": "Apache-2.0",
8
+ "maintainers": [],
9
+ "name": "@subwallet/extension-chains",
10
+ "repository": {
11
+ "directory": "packages/extension-chains",
12
+ "type": "git",
13
+ "url": "https://github.com/Koniverse/Subwallet-V2.git"
14
+ },
15
+ "sideEffects": [
16
+ "./detectPackage.js",
17
+ "./cjs/detectPackage.js"
18
+ ],
19
+ "type": "module",
20
+ "version": "0.3.6-0",
21
+ "main": "./cjs/index.js",
22
+ "module": "./index.js",
23
+ "types": "./index.d.ts",
24
+ "exports": {
25
+ "./cjs/package.json": "./cjs/package.json",
26
+ "./cjs/*": "./cjs/*.js",
27
+ ".": {
28
+ "types": "./index.d.ts",
29
+ "require": "./cjs/index.js",
30
+ "default": "./index.js"
31
+ },
32
+ "./bundle": {
33
+ "types": "./bundle.d.ts",
34
+ "require": "./cjs/bundle.js",
35
+ "default": "./bundle.js"
36
+ },
37
+ "./detectOther": {
38
+ "types": "./detectOther.d.ts",
39
+ "require": "./cjs/detectOther.js",
40
+ "default": "./detectOther.js"
41
+ },
42
+ "./detectPackage": {
43
+ "types": "./detectPackage.d.ts",
44
+ "require": "./cjs/detectPackage.js",
45
+ "default": "./detectPackage.js"
46
+ },
47
+ "./package.json": "./package.json",
48
+ "./packageInfo.js": {
49
+ "types": "./packageInfo.d.ts",
50
+ "require": "./cjs/packageInfo.js",
51
+ "default": "./packageInfo.js"
52
+ },
53
+ "./packageInfo": {
54
+ "types": "./packageInfo.d.ts",
55
+ "require": "./cjs/packageInfo.js",
56
+ "default": "./packageInfo.js"
57
+ },
58
+ "./types": {
59
+ "types": "./types.d.ts",
60
+ "require": "./cjs/types.js",
61
+ "default": "./types.js"
62
+ }
63
+ },
64
+ "dependencies": {
65
+ "@babel/runtime": "^7.16.7",
66
+ "@polkadot/networks": "^8.3.1",
67
+ "@polkadot/util": "^8.3.1",
68
+ "@polkadot/util-crypto": "^8.3.1",
69
+ "@subwallet/extension-inject": "^0.3.6-0"
70
+ },
71
+ "peerDependencies": {
72
+ "@polkadot/api": "*",
73
+ "@polkadot/types": "*"
74
+ }
75
+ }
@@ -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-chains 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-chains',
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,15 @@
1
+ import type { MetadataDef } from '@subwallet/extension-inject/types';
2
+ import type { Registry } from '@polkadot/types/types';
3
+ export interface Chain {
4
+ definition: MetadataDef;
5
+ genesisHash?: string;
6
+ hasMetadata: boolean;
7
+ icon: string;
8
+ isUnknown?: boolean;
9
+ name: string;
10
+ registry: Registry;
11
+ specVersion: number;
12
+ ss58Format: number;
13
+ tokenDecimals: number;
14
+ tokenSymbol: string;
15
+ }
package/build/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.addMetadata = addMetadata;
7
+ exports.findChain = findChain;
8
+ exports.knownMetadata = knownMetadata;
9
+ exports.metadataExpand = metadataExpand;
10
+ Object.defineProperty(exports, "packageInfo", {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _packageInfo.packageInfo;
14
+ }
15
+ });
16
+
17
+ var _types = require("@polkadot/types");
18
+
19
+ var _utilCrypto = require("@polkadot/util-crypto");
20
+
21
+ var _packageInfo = require("./packageInfo");
22
+
23
+ // Copyright 2019-2022 @subwallet/extension-chains authors & contributors
24
+ // SPDX-License-Identifier: Apache-2.0
25
+ // imports chain details, generally metadata. For the generation of these,
26
+ // inside the api, run `yarn chain:info --ws <url>`
27
+ const definitions = new Map();
28
+ const expanded = new Map();
29
+
30
+ function metadataExpand(definition) {
31
+ let isPartial = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
32
+ const cached = expanded.get(definition.genesisHash);
33
+
34
+ if (cached && cached.specVersion === definition.specVersion) {
35
+ return cached;
36
+ }
37
+
38
+ const {
39
+ chain,
40
+ genesisHash,
41
+ icon,
42
+ metaCalls,
43
+ specVersion,
44
+ ss58Format,
45
+ tokenDecimals,
46
+ tokenSymbol,
47
+ types,
48
+ userExtensions
49
+ } = definition;
50
+ const registry = new _types.TypeRegistry();
51
+
52
+ if (!isPartial) {
53
+ registry.register(types);
54
+ }
55
+
56
+ registry.setChainProperties(registry.createType('ChainProperties', {
57
+ ss58Format,
58
+ tokenDecimals,
59
+ tokenSymbol
60
+ }));
61
+ const hasMetadata = !!metaCalls && !isPartial;
62
+
63
+ if (hasMetadata) {
64
+ registry.setMetadata(new _types.Metadata(registry, (0, _utilCrypto.base64Decode)(metaCalls)), undefined, userExtensions);
65
+ }
66
+
67
+ const isUnknown = genesisHash === '0x';
68
+ const result = {
69
+ definition,
70
+ genesisHash: isUnknown ? undefined : genesisHash,
71
+ hasMetadata,
72
+ icon: icon || 'substrate',
73
+ isUnknown,
74
+ name: chain,
75
+ registry,
76
+ specVersion,
77
+ ss58Format,
78
+ tokenDecimals,
79
+ tokenSymbol
80
+ };
81
+
82
+ if (result.genesisHash && !isPartial) {
83
+ expanded.set(result.genesisHash, result);
84
+ }
85
+
86
+ return result;
87
+ }
88
+
89
+ function findChain(definitions, genesisHash) {
90
+ const def = definitions.find(def => def.genesisHash === genesisHash);
91
+ return def ? metadataExpand(def) : null;
92
+ }
93
+
94
+ function addMetadata(def) {
95
+ definitions.set(def.genesisHash, def);
96
+ }
97
+
98
+ function knownMetadata() {
99
+ return [...definitions.values()];
100
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _packageInfo = require("@subwallet/extension-inject/cjs/packageInfo");
9
+
10
+ // Copyright 2017-2022 @subwallet/extension-chains authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+ var _default = [_packageInfo.packageInfo];
13
+ 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-chains 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-chains 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-chains',
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,33 @@
1
+ {
2
+ "author": "Jaco Greeff <jacogr@gmail.com>",
3
+ "bugs": "https://github.com/Koniverse/Subwallet-V2/issues",
4
+ "contributors": [],
5
+ "description": "Definitions for all known chains as exposed by the extension.",
6
+ "homepage": "https://github.com/Koniverse/Subwallet-V2/tree/master/packages/extension-chains#readme",
7
+ "license": "Apache-2.0",
8
+ "maintainers": [],
9
+ "name": "@subwallet/extension-chains",
10
+ "repository": {
11
+ "directory": "packages/extension-chains",
12
+ "type": "git",
13
+ "url": "https://github.com/Koniverse/Subwallet-V2.git"
14
+ },
15
+ "sideEffects": [
16
+ "./detectPackage.js",
17
+ "./detectPackage.cjs"
18
+ ],
19
+ "type": "module",
20
+ "version": "0.3.6-0",
21
+ "main": "index.js",
22
+ "dependencies": {
23
+ "@babel/runtime": "^7.16.7",
24
+ "@polkadot/networks": "^8.3.1",
25
+ "@polkadot/util": "^8.3.1",
26
+ "@polkadot/util-crypto": "^8.3.1",
27
+ "@subwallet/extension-inject": "^0.3.6-0"
28
+ },
29
+ "peerDependencies": {
30
+ "@polkadot/api": "*",
31
+ "@polkadot/types": "*"
32
+ }
33
+ }
package/src/bundle.ts ADDED
@@ -0,0 +1,87 @@
1
+ // Copyright 2019-2022 @subwallet/extension-chains authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { MetadataDef } from '@subwallet/extension-inject/types';
5
+ import type { ChainProperties } from '@polkadot/types/interfaces';
6
+ import type { Chain } from './types';
7
+
8
+ import { Metadata, TypeRegistry } from '@polkadot/types';
9
+ import { base64Decode } from '@polkadot/util-crypto';
10
+
11
+ export { packageInfo } from './packageInfo';
12
+
13
+ // imports chain details, generally metadata. For the generation of these,
14
+ // inside the api, run `yarn chain:info --ws <url>`
15
+
16
+ const definitions = new Map<string, MetadataDef>(
17
+ // [kusama].map((def) => [def.genesisHash, def])
18
+ );
19
+
20
+ const expanded = new Map<string, Chain>();
21
+
22
+ export function metadataExpand (definition: MetadataDef, isPartial = false): Chain {
23
+ const cached = expanded.get(definition.genesisHash);
24
+
25
+ if (cached && cached.specVersion === definition.specVersion) {
26
+ return cached;
27
+ }
28
+
29
+ const { chain, genesisHash, icon, metaCalls, specVersion, ss58Format, tokenDecimals, tokenSymbol, types, userExtensions } = definition;
30
+ const registry = new TypeRegistry();
31
+
32
+ if (!isPartial) {
33
+ registry.register(types);
34
+ }
35
+
36
+ registry.setChainProperties(registry.createType('ChainProperties', {
37
+ ss58Format,
38
+ tokenDecimals,
39
+ tokenSymbol
40
+ }) as unknown as ChainProperties);
41
+
42
+ const hasMetadata = !!metaCalls && !isPartial;
43
+
44
+ if (hasMetadata) {
45
+ registry.setMetadata(new Metadata(registry, base64Decode(metaCalls)), undefined, userExtensions);
46
+ }
47
+
48
+ const isUnknown = genesisHash === '0x';
49
+
50
+ const result = {
51
+ definition,
52
+ genesisHash: isUnknown
53
+ ? undefined
54
+ : genesisHash,
55
+ hasMetadata,
56
+ icon: icon || 'substrate',
57
+ isUnknown,
58
+ name: chain,
59
+ registry,
60
+ specVersion,
61
+ ss58Format,
62
+ tokenDecimals,
63
+ tokenSymbol
64
+ };
65
+
66
+ if (result.genesisHash && !isPartial) {
67
+ expanded.set(result.genesisHash, result);
68
+ }
69
+
70
+ return result;
71
+ }
72
+
73
+ export function findChain (definitions: MetadataDef[], genesisHash?: string | null): Chain | null {
74
+ const def = definitions.find((def) => def.genesisHash === genesisHash);
75
+
76
+ return def
77
+ ? metadataExpand(def)
78
+ : null;
79
+ }
80
+
81
+ export function addMetadata (def: MetadataDef): void {
82
+ definitions.set(def.genesisHash, def);
83
+ }
84
+
85
+ export function knownMetadata (): MetadataDef[] {
86
+ return [...definitions.values()];
87
+ }
@@ -0,0 +1,6 @@
1
+ // Copyright 2017-2022 @subwallet/extension-chains authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { packageInfo as injectInfo } from '@subwallet/extension-inject/packageInfo';
5
+
6
+ export default [injectInfo];
@@ -0,0 +1,11 @@
1
+ // Copyright 2017-2022 @subwallet/extension-chains 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-chains 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-chains 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-chains', path: 'auto', type: 'auto', version: '0.3.6-0' };
package/src/types.ts ADDED
@@ -0,0 +1,19 @@
1
+ // Copyright 2019-2022 @subwallet/extension-chains authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { MetadataDef } from '@subwallet/extension-inject/types';
5
+ import type { Registry } from '@polkadot/types/types';
6
+
7
+ export interface Chain {
8
+ definition: MetadataDef;
9
+ genesisHash?: string;
10
+ hasMetadata: boolean;
11
+ icon: string;
12
+ isUnknown?: boolean;
13
+ name: string;
14
+ registry: Registry;
15
+ specVersion: number;
16
+ ss58Format: number;
17
+ tokenDecimals: number;
18
+ tokenSymbol: string;
19
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "baseUrl": "..",
5
+ "outDir": "./build",
6
+ "rootDir": "./src"
7
+ },
8
+ "references": [
9
+ { "path": "../extension-inject/tsconfig.build.json"
10
+ }
11
+ ]
12
+ }