@polkadot/extension-inject 0.44.6 → 0.44.7

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/bundle.js CHANGED
@@ -1,20 +1,51 @@
1
1
  // Copyright 2019-2022 @polkadot/extension-inject authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- export { packageInfo } from "./packageInfo.js"; // It is recommended to always use the function below to shield the extension and dapp from
3
+
4
+ import { cyrb53 } from "./cyrb53.js";
5
+ export { packageInfo } from "./packageInfo.js";
6
+
7
+ // setting for new-style connect (more-secure with no details exposed without
8
+ // user acknowledgement, however slightly less-compatible with all dapps, some
9
+ // may have not upgraded and don't have access to the latest interfaces)
10
+ //
11
+ // NOTE: In future versions this will be made the default
12
+ const IS_CONNECT_CAPABLE = false;
13
+
14
+ // It is recommended to always use the function below to shield the extension and dapp from
4
15
  // any future changes. The exposed interface will manage access between the 2 environments,
5
16
  // be it via window (current), postMessage (under consideration) or any other mechanism
6
-
7
17
  export function injectExtension(enable, {
8
18
  name,
9
19
  version
10
20
  }) {
11
21
  // small helper with the typescript types, just cast window
12
- const windowInject = window; // don't clobber the existing object, we will add it (or create as needed)
13
-
14
- windowInject.injectedWeb3 = windowInject.injectedWeb3 || {}; // add our enable function
22
+ const windowInject = window;
15
23
 
16
- windowInject.injectedWeb3[name] = {
17
- enable: origin => enable(origin),
18
- version
19
- };
24
+ // don't clobber the existing object, we will add it (or create as needed)
25
+ windowInject.injectedWeb3 = windowInject.injectedWeb3 || {};
26
+ if (IS_CONNECT_CAPABLE) {
27
+ // expose our extension on the window object, new-style with connect(origin)
28
+ windowInject.injectedWeb3[cyrb53(`${name}/${version}`)] = {
29
+ connect: origin => enable(origin).then(({
30
+ accounts,
31
+ metadata,
32
+ provider,
33
+ signer
34
+ }) => ({
35
+ accounts,
36
+ metadata,
37
+ name,
38
+ provider,
39
+ signer,
40
+ version
41
+ })),
42
+ enable: () => Promise.reject(new Error('This extension does not have support for enable(...), rather is only supports the new connect(...) variant (no extension name/version metadata without specific user-approval)'))
43
+ };
44
+ } else {
45
+ // expose our extension on the window object, old-style with enable(origin)
46
+ windowInject.injectedWeb3[name] = {
47
+ enable: origin => enable(origin),
48
+ version
49
+ };
50
+ }
20
51
  }
package/chrome.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // Copyright 2019-2022 @polkadot/extension-inject authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  import { extractGlobal, xglobal } from '@polkadot/x-global';
4
5
  export const chrome = extractGlobal('chrome', xglobal.browser);
package/cjs/bundle.js CHANGED
@@ -10,11 +10,18 @@ Object.defineProperty(exports, "packageInfo", {
10
10
  return _packageInfo.packageInfo;
11
11
  }
12
12
  });
13
-
13
+ var _cyrb = require("./cyrb53");
14
14
  var _packageInfo = require("./packageInfo");
15
-
16
15
  // Copyright 2019-2022 @polkadot/extension-inject authors & contributors
17
16
  // SPDX-License-Identifier: Apache-2.0
17
+
18
+ // setting for new-style connect (more-secure with no details exposed without
19
+ // user acknowledgement, however slightly less-compatible with all dapps, some
20
+ // may have not upgraded and don't have access to the latest interfaces)
21
+ //
22
+ // NOTE: In future versions this will be made the default
23
+ const IS_CONNECT_CAPABLE = false;
24
+
18
25
  // It is recommended to always use the function below to shield the extension and dapp from
19
26
  // any future changes. The exposed interface will manage access between the 2 environments,
20
27
  // be it via window (current), postMessage (under consideration) or any other mechanism
@@ -24,12 +31,36 @@ function injectExtension(enable, _ref) {
24
31
  version
25
32
  } = _ref;
26
33
  // 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)
34
+ const windowInject = window;
28
35
 
29
- windowInject.injectedWeb3 = windowInject.injectedWeb3 || {}; // add our enable function
30
-
31
- windowInject.injectedWeb3[name] = {
32
- enable: origin => enable(origin),
33
- version
34
- };
36
+ // don't clobber the existing object, we will add it (or create as needed)
37
+ windowInject.injectedWeb3 = windowInject.injectedWeb3 || {};
38
+ if (IS_CONNECT_CAPABLE) {
39
+ // expose our extension on the window object, new-style with connect(origin)
40
+ windowInject.injectedWeb3[(0, _cyrb.cyrb53)(`${name}/${version}`)] = {
41
+ connect: origin => enable(origin).then(_ref2 => {
42
+ let {
43
+ accounts,
44
+ metadata,
45
+ provider,
46
+ signer
47
+ } = _ref2;
48
+ return {
49
+ accounts,
50
+ metadata,
51
+ name,
52
+ provider,
53
+ signer,
54
+ version
55
+ };
56
+ }),
57
+ enable: () => Promise.reject(new Error('This extension does not have support for enable(...), rather is only supports the new connect(...) variant (no extension name/version metadata without specific user-approval)'))
58
+ };
59
+ } else {
60
+ // expose our extension on the window object, old-style with enable(origin)
61
+ windowInject.injectedWeb3[name] = {
62
+ enable: origin => enable(origin),
63
+ version
64
+ };
65
+ }
35
66
  }
package/cjs/chrome.js CHANGED
@@ -4,10 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.chrome = void 0;
7
-
8
7
  var _xGlobal = require("@polkadot/x-global");
9
-
10
8
  // Copyright 2019-2022 @polkadot/extension-inject authors & contributors
11
9
  // SPDX-License-Identifier: Apache-2.0
10
+
12
11
  const chrome = (0, _xGlobal.extractGlobal)('chrome', _xGlobal.xglobal.browser);
13
12
  exports.chrome = chrome;
package/cjs/crossenv.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  var _xGlobal = require("@polkadot/x-global");
4
-
5
4
  // Copyright 2019-2022 @polkadot/extension-inject authors & contributors
6
5
  // SPDX-License-Identifier: Apache-2.0
6
+
7
7
  (0, _xGlobal.exposeGlobal)('chrome', _xGlobal.xglobal.browser);
package/cjs/cyrb53.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.cyrb53 = cyrb53;
7
+ // Copyright 2019-2022 @polkadot/extension-inject authors & contributors
8
+ // SPDX-License-Identifier: Apache-2.0
9
+
10
+ // cyrb53 (c) 2018 bryc (github.com/bryc)
11
+ // A fast and simple hash function with decent collision resistance.
12
+ // Largely inspired by MurmurHash2/3, but with a focus on speed/simplicity.
13
+ // Public domain. Attribution appreciated.
14
+ //
15
+ // From https://github.com/bryc/code/blob/fed42df9db547493452e32375c93d7854383e480/jshash/experimental/cyrb53.js
16
+ // As shared in https://stackoverflow.com/a/52171480
17
+ //
18
+ // Small changes made to the code as linked above:
19
+ // . - Seed value is required (set as Date.now() in usage, could change)
20
+ // - Return value is a hex string (as per comment in SO answer)
21
+ // - TS typings added
22
+ // - Non-intrusive coding-style variable declaration changes
23
+ function cyrb53(input) {
24
+ let seed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now();
25
+ let h1 = 0xdeadbeef ^ seed;
26
+ let h2 = 0x41c6ce57 ^ seed;
27
+ for (let i = 0; i < input.length; i++) {
28
+ const ch = input.charCodeAt(i);
29
+ h1 = Math.imul(h1 ^ ch, 2654435761);
30
+ h2 = Math.imul(h2 ^ ch, 1597334677);
31
+ }
32
+ h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
33
+ h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
34
+
35
+ // https://stackoverflow.com/a/52171480
36
+ return (h2 >>> 0).toString(16).padStart(8, '0') + (h1 >>> 0).toString(16).padStart(8, '0');
37
+ }
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  var _util = require("@polkadot/util");
6
-
7
5
  var _detectOther = _interopRequireDefault(require("./detectOther"));
8
-
9
6
  var _packageInfo = require("./packageInfo");
10
-
11
7
  // Copyright 2017-2022 @polkadot/extension-inject authors & contributors
12
8
  // SPDX-License-Identifier: Apache-2.0
9
+
13
10
  // Do not edit, auto-generated by @polkadot/dev
11
+
14
12
  (0, _util.detectPackage)(_packageInfo.packageInfo, null, _detectOther.default);
package/cjs/index.js CHANGED
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  var _bundle = require("./bundle");
8
-
9
7
  Object.keys(_bundle).forEach(function (key) {
10
8
  if (key === "default" || key === "__esModule") return;
11
9
  if (key in exports && exports[key] === _bundle[key]) return;
@@ -6,11 +6,13 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.packageInfo = void 0;
7
7
  // Copyright 2017-2022 @polkadot/extension-inject authors & contributors
8
8
  // SPDX-License-Identifier: Apache-2.0
9
+
9
10
  // Do not edit, auto-generated by @polkadot/dev
11
+
10
12
  const packageInfo = {
11
13
  name: '@polkadot/extension-inject',
12
14
  path: typeof __dirname === 'string' ? __dirname : 'auto',
13
15
  type: 'cjs',
14
- version: '0.44.6'
16
+ version: '0.44.7'
15
17
  };
16
18
  exports.packageInfo = packageInfo;
package/crossenv.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // Copyright 2019-2022 @polkadot/extension-inject authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  import { exposeGlobal, xglobal } from '@polkadot/x-global';
4
5
  exposeGlobal('chrome', xglobal.browser);
package/cyrb53.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function cyrb53(input: string, seed?: number): string;
package/cyrb53.js ADDED
@@ -0,0 +1,30 @@
1
+ // Copyright 2019-2022 @polkadot/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // cyrb53 (c) 2018 bryc (github.com/bryc)
5
+ // A fast and simple hash function with decent collision resistance.
6
+ // Largely inspired by MurmurHash2/3, but with a focus on speed/simplicity.
7
+ // Public domain. Attribution appreciated.
8
+ //
9
+ // From https://github.com/bryc/code/blob/fed42df9db547493452e32375c93d7854383e480/jshash/experimental/cyrb53.js
10
+ // As shared in https://stackoverflow.com/a/52171480
11
+ //
12
+ // Small changes made to the code as linked above:
13
+ // . - Seed value is required (set as Date.now() in usage, could change)
14
+ // - Return value is a hex string (as per comment in SO answer)
15
+ // - TS typings added
16
+ // - Non-intrusive coding-style variable declaration changes
17
+ export function cyrb53(input, seed = Date.now()) {
18
+ let h1 = 0xdeadbeef ^ seed;
19
+ let h2 = 0x41c6ce57 ^ seed;
20
+ for (let i = 0; i < input.length; i++) {
21
+ const ch = input.charCodeAt(i);
22
+ h1 = Math.imul(h1 ^ ch, 2654435761);
23
+ h2 = Math.imul(h2 ^ ch, 1597334677);
24
+ }
25
+ h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
26
+ h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
27
+
28
+ // https://stackoverflow.com/a/52171480
29
+ return (h2 >>> 0).toString(16).padStart(8, '0') + (h1 >>> 0).toString(16).padStart(8, '0');
30
+ }
package/detectOther.js CHANGED
@@ -1,4 +1,6 @@
1
1
  // Copyright 2017-2022 @polkadot/extension-inject authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  // Empty template, auto-generated by @polkadot/dev
5
+
4
6
  export default [];
package/detectPackage.js CHANGED
@@ -1,6 +1,8 @@
1
1
  // Copyright 2017-2022 @polkadot/extension-inject authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  // Do not edit, auto-generated by @polkadot/dev
5
+
4
6
  import { detectPackage } from '@polkadot/util';
5
7
  import others from "./detectOther.js";
6
8
  import { packageInfo } from "./packageInfo.js";
package/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  // Copyright 2019-2022 @polkadot/extension-inject authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  // Since we inject into pages, we skip this
4
5
  // import './detectPackage';
6
+
5
7
  export * from "./bundle.js";
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "sideEffects": true,
16
16
  "type": "module",
17
- "version": "0.44.6",
17
+ "version": "0.44.7",
18
18
  "main": "./cjs/index.js",
19
19
  "module": "./index.js",
20
20
  "types": "./index.d.ts",
@@ -41,6 +41,11 @@
41
41
  "require": "./cjs/crossenv.js",
42
42
  "default": "./crossenv.js"
43
43
  },
44
+ "./cyrb53": {
45
+ "types": "./cyrb53.d.ts",
46
+ "require": "./cjs/cyrb53.js",
47
+ "default": "./cyrb53.js"
48
+ },
44
49
  "./detectOther": {
45
50
  "types": "./detectOther.d.ts",
46
51
  "require": "./cjs/detectOther.js",
@@ -69,12 +74,12 @@
69
74
  }
70
75
  },
71
76
  "dependencies": {
72
- "@babel/runtime": "^7.18.9",
73
- "@polkadot/rpc-provider": "^9.2.3",
74
- "@polkadot/types": "^9.2.3",
75
- "@polkadot/util": "^10.1.5",
76
- "@polkadot/util-crypto": "^10.1.5",
77
- "@polkadot/x-global": "^10.1.5"
77
+ "@babel/runtime": "^7.20.7",
78
+ "@polkadot/rpc-provider": "^9.10.4",
79
+ "@polkadot/types": "^9.10.4",
80
+ "@polkadot/util": "^10.2.1",
81
+ "@polkadot/util-crypto": "^10.2.1",
82
+ "@polkadot/x-global": "^10.2.1"
78
83
  },
79
84
  "peerDependencies": {
80
85
  "@polkadot/api": "*"
package/packageInfo.js CHANGED
@@ -1,9 +1,11 @@
1
1
  // Copyright 2017-2022 @polkadot/extension-inject authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  // Do not edit, auto-generated by @polkadot/dev
5
+
4
6
  export const packageInfo = {
5
7
  name: '@polkadot/extension-inject',
6
8
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
7
9
  type: 'esm',
8
- version: '0.44.6'
10
+ version: '0.44.7'
9
11
  };
package/types.d.ts CHANGED
@@ -2,8 +2,8 @@ import type { Signer as InjectedSigner } from '@polkadot/api/types';
2
2
  import type { ProviderInterface } from '@polkadot/rpc-provider/types';
3
3
  import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
4
4
  import type { KeypairType } from '@polkadot/util-crypto/types';
5
- declare type This = typeof globalThis;
6
- export declare type Unsubcall = () => void;
5
+ type This = typeof globalThis;
6
+ export type Unsubcall = () => void;
7
7
  export interface InjectedAccount {
8
8
  address: string;
9
9
  genesisHash?: string | null;
@@ -57,7 +57,7 @@ export interface InjectedMetadata {
57
57
  get: () => Promise<InjectedMetadataKnown[]>;
58
58
  provide: (definition: MetadataDef) => Promise<boolean>;
59
59
  }
60
- export declare type ProviderList = Record<string, ProviderMeta>;
60
+ export type ProviderList = Record<string, ProviderMeta>;
61
61
  export interface InjectedProvider extends ProviderInterface {
62
62
  listProviders: () => Promise<ProviderList>;
63
63
  startProvider: (key: string) => Promise<ProviderMeta>;
@@ -73,17 +73,19 @@ export interface Injected {
73
73
  signer: InjectedSigner;
74
74
  }
75
75
  export interface InjectedWindowProvider {
76
- enable: (origin: string) => Promise<Injected>;
77
- version: string;
76
+ connect?: (origin: string) => Promise<InjectedExtension>;
77
+ enable?: (origin: string) => Promise<Injected>;
78
+ version?: string;
78
79
  }
79
80
  export interface InjectedWindow extends This {
80
81
  injectedWeb3: Record<string, InjectedWindowProvider>;
81
82
  }
82
- export declare type InjectedExtension = InjectedExtensionInfo & Injected;
83
- export declare type InjectOptions = InjectedExtensionInfo;
83
+ export type InjectedExtension = InjectedExtensionInfo & Injected;
84
+ export type InjectOptions = InjectedExtensionInfo;
84
85
  export interface Web3AccountsOptions {
85
- ss58Format?: number;
86
86
  accountType?: KeypairType[];
87
87
  extensions?: string[];
88
+ genesisHash?: string | null;
89
+ ss58Format?: number;
88
90
  }
89
91
  export {};