@pezkuwi/extension-inject 0.62.16 → 0.62.18

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 (47) hide show
  1. package/package.json +7 -138
  2. package/src/bundle.ts +47 -0
  3. package/{chrome.js → src/chrome.ts} +4 -0
  4. package/src/crossenv.ts +6 -0
  5. package/src/cyrb53.spec.ts +30 -0
  6. package/src/cyrb53.ts +33 -0
  7. package/src/index.ts +7 -0
  8. package/src/packageDetect.ts +11 -0
  9. package/src/packageInfo.ts +6 -0
  10. package/src/types.ts +122 -0
  11. package/tsconfig.build.json +12 -0
  12. package/tsconfig.build.tsbuildinfo +1 -0
  13. package/tsconfig.spec.json +16 -0
  14. package/tsconfig.spec.tsbuildinfo +1 -0
  15. package/LICENSE +0 -201
  16. package/bundle.js +0 -25
  17. package/cjs/bundle.d.ts +0 -3
  18. package/cjs/bundle.js +0 -30
  19. package/cjs/chrome.d.ts +0 -1
  20. package/cjs/chrome.js +0 -5
  21. package/cjs/crossenv.js +0 -4
  22. package/cjs/cyrb53.js +0 -16
  23. package/cjs/index.js +0 -4
  24. package/cjs/package.json +0 -3
  25. package/cjs/packageDetect.js +0 -5
  26. package/cjs/packageInfo.js +0 -4
  27. package/cjs/types.js +0 -2
  28. package/crossenv.d.ts +0 -1
  29. package/crossenv.js +0 -2
  30. package/cyrb53.d.ts +0 -1
  31. package/cyrb53.js +0 -13
  32. package/index.d.ts +0 -1
  33. package/index.js +0 -1
  34. package/packageDetect.d.ts +0 -1
  35. package/packageDetect.js +0 -3
  36. package/packageInfo.d.ts +0 -6
  37. package/packageInfo.js +0 -1
  38. package/types.d.ts +0 -93
  39. package/types.js +0 -1
  40. /package/{bundle.d.ts → build/bundle.d.ts} +0 -0
  41. /package/{chrome.d.ts → build/chrome.d.ts} +0 -0
  42. /package/{cjs → build}/crossenv.d.ts +0 -0
  43. /package/{cjs → build}/cyrb53.d.ts +0 -0
  44. /package/{cjs → build}/index.d.ts +0 -0
  45. /package/{cjs → build}/packageDetect.d.ts +0 -0
  46. /package/{cjs → build}/packageInfo.d.ts +0 -0
  47. /package/{cjs → build}/types.d.ts +0 -0
package/package.json CHANGED
@@ -15,144 +15,8 @@
15
15
  },
16
16
  "sideEffects": true,
17
17
  "type": "module",
18
- "version": "0.62.16",
19
- "main": "./cjs/index.js",
20
- "module": "./index.js",
21
- "types": "./index.d.ts",
22
- "exports": {
23
- "./cjs/package.json": "./cjs/package.json",
24
- "./cjs/*": "./cjs/*.js",
25
- ".": {
26
- "module": {
27
- "types": "./index.d.ts",
28
- "default": "./index.js"
29
- },
30
- "require": {
31
- "types": "./cjs/index.d.ts",
32
- "default": "./cjs/index.js"
33
- },
34
- "default": {
35
- "types": "./index.d.ts",
36
- "default": "./index.js"
37
- }
38
- },
39
- "./bundle": {
40
- "module": {
41
- "types": "./bundle.d.ts",
42
- "default": "./bundle.js"
43
- },
44
- "require": {
45
- "types": "./cjs/bundle.d.ts",
46
- "default": "./cjs/bundle.js"
47
- },
48
- "default": {
49
- "types": "./bundle.d.ts",
50
- "default": "./bundle.js"
51
- }
52
- },
53
- "./chrome": {
54
- "module": {
55
- "types": "./chrome.d.ts",
56
- "default": "./chrome.js"
57
- },
58
- "require": {
59
- "types": "./cjs/chrome.d.ts",
60
- "default": "./cjs/chrome.js"
61
- },
62
- "default": {
63
- "types": "./chrome.d.ts",
64
- "default": "./chrome.js"
65
- }
66
- },
67
- "./crossenv": {
68
- "module": {
69
- "types": "./crossenv.d.ts",
70
- "default": "./crossenv.js"
71
- },
72
- "require": {
73
- "types": "./cjs/crossenv.d.ts",
74
- "default": "./cjs/crossenv.js"
75
- },
76
- "default": {
77
- "types": "./crossenv.d.ts",
78
- "default": "./crossenv.js"
79
- }
80
- },
81
- "./cyrb53": {
82
- "module": {
83
- "types": "./cyrb53.d.ts",
84
- "default": "./cyrb53.js"
85
- },
86
- "require": {
87
- "types": "./cjs/cyrb53.d.ts",
88
- "default": "./cjs/cyrb53.js"
89
- },
90
- "default": {
91
- "types": "./cyrb53.d.ts",
92
- "default": "./cyrb53.js"
93
- }
94
- },
95
- "./package.json": {
96
- "require": "./cjs/package.json",
97
- "default": "./package.json"
98
- },
99
- "./packageDetect": {
100
- "module": {
101
- "types": "./packageDetect.d.ts",
102
- "default": "./packageDetect.js"
103
- },
104
- "require": {
105
- "types": "./cjs/packageDetect.d.ts",
106
- "default": "./cjs/packageDetect.js"
107
- },
108
- "default": {
109
- "types": "./packageDetect.d.ts",
110
- "default": "./packageDetect.js"
111
- }
112
- },
113
- "./packageInfo.js": {
114
- "module": {
115
- "types": "./packageInfo.d.ts",
116
- "default": "./packageInfo.js"
117
- },
118
- "require": {
119
- "types": "./cjs/packageInfo.d.ts",
120
- "default": "./cjs/packageInfo.js"
121
- },
122
- "default": {
123
- "types": "./packageInfo.d.ts",
124
- "default": "./packageInfo.js"
125
- }
126
- },
127
- "./packageInfo": {
128
- "module": {
129
- "types": "./packageInfo.d.ts",
130
- "default": "./packageInfo.js"
131
- },
132
- "require": {
133
- "types": "./cjs/packageInfo.d.ts",
134
- "default": "./cjs/packageInfo.js"
135
- },
136
- "default": {
137
- "types": "./packageInfo.d.ts",
138
- "default": "./packageInfo.js"
139
- }
140
- },
141
- "./types": {
142
- "module": {
143
- "types": "./types.d.ts",
144
- "default": "./types.js"
145
- },
146
- "require": {
147
- "types": "./cjs/types.d.ts",
148
- "default": "./cjs/types.js"
149
- },
150
- "default": {
151
- "types": "./types.d.ts",
152
- "default": "./types.js"
153
- }
154
- }
155
- },
18
+ "version": "0.62.18",
19
+ "main": "index.js",
156
20
  "dependencies": {
157
21
  "@pezkuwi/api": "^16.5.9",
158
22
  "@pezkuwi/rpc-provider": "^16.5.9",
@@ -162,6 +26,11 @@
162
26
  "@pezkuwi/x-global": "^14.0.11",
163
27
  "tslib": "^2.8.1"
164
28
  },
29
+ "devDependencies": {
30
+ "@pezkuwi/dev-test": "^0.84.3",
31
+ "@types/chrome": "^0.0.254",
32
+ "@types/firefox-webext-browser": "^111.0.5"
33
+ },
165
34
  "peerDependencies": {
166
35
  "@pezkuwi/api": "*",
167
36
  "@pezkuwi/util": "*"
package/src/bundle.ts ADDED
@@ -0,0 +1,47 @@
1
+ // Copyright 2019-2026 @pezkuwi/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Injected, InjectedExtension, InjectedWindow, InjectOptions } from './types.js';
5
+
6
+ import { cyrb53 } from './cyrb53.js';
7
+
8
+ export { packageInfo } from './packageInfo.js';
9
+
10
+ // setting for new-style connect (more-secure with no details exposed without
11
+ // user acknowledgement, however slightly less-compatible with all dapps, some
12
+ // may have not upgraded and don't have access to the latest interfaces)
13
+ //
14
+ // NOTE: In future versions this will be made the default
15
+ const IS_CONNECT_CAPABLE = false;
16
+
17
+ // It is recommended to always use the function below to shield the extension and dapp from
18
+ // any future changes. The exposed interface will manage access between the 2 environments,
19
+ // be it via window (current), postMessage (under consideration) or any other mechanism
20
+ export function injectExtension (enable: (origin: string) => Promise<Injected>, { name, version }: InjectOptions): void {
21
+ // small helper with the typescript types, just cast window
22
+ const windowInject = window as Window & InjectedWindow;
23
+
24
+ // don't clobber the existing object, we will add it (or create as needed)
25
+ windowInject.injectedWeb3 = windowInject.injectedWeb3 || {};
26
+
27
+ if (IS_CONNECT_CAPABLE) {
28
+ // expose our extension on the window object, new-style with connect(origin)
29
+ windowInject.injectedWeb3[cyrb53(`${name}/${version}`)] = {
30
+ connect: (origin: string): Promise<InjectedExtension> =>
31
+ enable(origin).then(({ accounts, metadata, provider, signer }) => ({
32
+ accounts, metadata, name, provider, signer, version
33
+ })),
34
+ enable: (): Promise<Injected> =>
35
+ Promise.reject(
36
+ 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)')
37
+ )
38
+ };
39
+ } else {
40
+ // expose our extension on the window object, old-style with enable(origin)
41
+ windowInject.injectedWeb3[name] = {
42
+ enable: (origin: string): Promise<Injected> =>
43
+ enable(origin),
44
+ version
45
+ };
46
+ }
47
+ }
@@ -1,2 +1,6 @@
1
+ // Copyright 2019-2026 @pezkuwi/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
1
4
  import { extractGlobal, xglobal } from '@pezkuwi/x-global';
5
+
2
6
  export const chrome = extractGlobal('chrome', xglobal.browser);
@@ -0,0 +1,6 @@
1
+ // Copyright 2019-2026 @pezkuwi/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { exposeGlobal, xglobal } from '@pezkuwi/x-global';
5
+
6
+ exposeGlobal('chrome', xglobal.browser);
@@ -0,0 +1,30 @@
1
+ // Copyright 2019-2026 @pezkuwi/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type * as _ from '@pezkuwi/dev-test/globals.d.ts';
5
+
6
+ import { cyrb53 } from './cyrb53.js';
7
+
8
+ const TESTS = [
9
+ { input: 'a', seed: 0, test: '501c2ba782c97901' },
10
+ { input: 'b', seed: 0, test: '459eda5bc254d2bf' },
11
+ { input: 'revenge', seed: 0, test: 'fbce64cc3b748385' },
12
+ { input: 'revenue', seed: 0, test: 'fb1d85148d13f93a' },
13
+ { input: 'revenue', seed: 1, test: '76fee5e6598ccd5c' },
14
+ { input: 'revenue', seed: 2, test: '1f672e2831253862' },
15
+ { input: 'revenue', seed: 3, test: '2b10de31708e6ab7' }
16
+ ] as const;
17
+
18
+ describe('cyrb53', (): void => {
19
+ for (let i = 0, count = TESTS.length; i < count; i++) {
20
+ const { input, seed, test } = TESTS[i];
21
+
22
+ it(`correctly encodes ${input}`, (): void => {
23
+ // expected values, known input & seed
24
+ expect(cyrb53(input, seed)).toEqual(test);
25
+
26
+ // seed set as Date.now(), should not match previous
27
+ expect(cyrb53(input)).not.toEqual(test);
28
+ });
29
+ }
30
+ });
package/src/cyrb53.ts ADDED
@@ -0,0 +1,33 @@
1
+ // Copyright 2019-2026 @pezkuwi/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: string, seed = Date.now()): string {
18
+ let h1 = 0xdeadbeef ^ seed;
19
+ let h2 = 0x41c6ce57 ^ seed;
20
+
21
+ for (let i = 0, count = input.length; i < count; i++) {
22
+ const ch = input.charCodeAt(i);
23
+
24
+ h1 = Math.imul(h1 ^ ch, 2654435761);
25
+ h2 = Math.imul(h2 ^ ch, 1597334677);
26
+ }
27
+
28
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
29
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
30
+
31
+ // https://stackoverflow.com/a/52171480
32
+ return (h2 >>> 0).toString(16).padStart(8, '0') + (h1 >>> 0).toString(16).padStart(8, '0');
33
+ }
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ // Copyright 2019-2026 @pezkuwi/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Since we inject into pages, we skip this
5
+ // import './packageDetect.js';
6
+
7
+ export * from './bundle.js';
@@ -0,0 +1,11 @@
1
+ // Copyright 2017-2026 @pezkuwi/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Do not edit, auto-generated by @pezkuwi/dev
5
+ // (packageInfo imports will be kept as-is, user-editable)
6
+
7
+ import { detectPackage } from '@pezkuwi/util';
8
+
9
+ import { packageInfo } from './packageInfo.js';
10
+
11
+ detectPackage(packageInfo, null, []);
@@ -0,0 +1,6 @@
1
+ // Copyright 2017-2026 @pezkuwi/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Do not edit, auto-generated by @pezkuwi/dev
5
+
6
+ export const packageInfo = { name: '@pezkuwi/extension-inject', path: 'auto', type: 'auto', version: '0.62.16' };
package/src/types.ts ADDED
@@ -0,0 +1,122 @@
1
+ // Copyright 2019-2026 @pezkuwi/extension-inject authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Signer as InjectedSigner } from '@pezkuwi/api/types';
5
+ import type { ProviderInterface } from '@pezkuwi/rpc-provider/types';
6
+ import type { ExtDef } from '@pezkuwi/types/extrinsic/signedExtensions/types';
7
+ import type { HexString } from '@pezkuwi/util/types';
8
+ import type { KeypairType } from '@pezkuwi/util-crypto/types';
9
+
10
+ // eslint-disable-next-line no-undef
11
+ type This = typeof globalThis;
12
+
13
+ export type Unsubcall = () => void;
14
+
15
+ export interface InjectedAccount {
16
+ address: string;
17
+ genesisHash?: string | null;
18
+ name?: string;
19
+ type?: KeypairType;
20
+ }
21
+
22
+ export interface InjectedAccountWithMeta {
23
+ address: string;
24
+ meta: {
25
+ genesisHash?: string | null;
26
+ name?: string;
27
+ source: string;
28
+ };
29
+ type?: KeypairType;
30
+ }
31
+
32
+ export interface InjectedAccounts {
33
+ get: (anyType?: boolean) => Promise<InjectedAccount[]>;
34
+ subscribe: (cb: (accounts: InjectedAccount[]) => void | Promise<void>) => Unsubcall;
35
+ }
36
+
37
+ export interface InjectedExtensionInfo {
38
+ name: string;
39
+ version: string;
40
+ }
41
+
42
+ // Metadata about a provider
43
+ export interface ProviderMeta {
44
+ // Network of the provider
45
+ network: string;
46
+ // Light or full node
47
+ node: 'full' | 'light';
48
+ // The extension source
49
+ source: string;
50
+ // Provider transport: 'WsProvider' etc.
51
+ transport: string;
52
+ }
53
+
54
+ export interface MetadataDefBase {
55
+ chain: string;
56
+ genesisHash: HexString;
57
+ icon: string;
58
+ ss58Format: number;
59
+ chainType?: 'bizinikiwi' | 'ethereum'
60
+ }
61
+
62
+ export interface MetadataDef extends MetadataDefBase {
63
+ color?: string;
64
+ specVersion: number;
65
+ tokenDecimals: number;
66
+ tokenSymbol: string;
67
+ types: Record<string, Record<string, string> | string>;
68
+ metaCalls?: string;
69
+ rawMetadata?: HexString;
70
+ userExtensions?: ExtDef;
71
+ }
72
+
73
+ export interface InjectedMetadataKnown {
74
+ genesisHash: string;
75
+ specVersion: number;
76
+ }
77
+
78
+ export interface InjectedMetadata {
79
+ get: () => Promise<InjectedMetadataKnown[]>;
80
+ provide: (definition: MetadataDef) => Promise<boolean>;
81
+ }
82
+
83
+ export type ProviderList = Record<string, ProviderMeta>
84
+
85
+ export interface InjectedProvider extends ProviderInterface {
86
+ listProviders: () => Promise<ProviderList>;
87
+ startProvider: (key: string) => Promise<ProviderMeta>;
88
+ }
89
+
90
+ export interface InjectedProviderWithMeta {
91
+ // provider will actually always be a PostMessageProvider, which implements InjectedProvider
92
+ provider: InjectedProvider;
93
+ meta: ProviderMeta;
94
+ }
95
+
96
+ export interface Injected {
97
+ accounts: InjectedAccounts;
98
+ metadata?: InjectedMetadata;
99
+ provider?: InjectedProvider;
100
+ signer: InjectedSigner;
101
+ }
102
+
103
+ export interface InjectedWindowProvider {
104
+ connect?: (origin: string) => Promise<InjectedExtension>;
105
+ enable?: (origin: string) => Promise<Injected>;
106
+ version?: string;
107
+ }
108
+
109
+ export interface InjectedWindow extends This {
110
+ injectedWeb3: Record<string, InjectedWindowProvider>;
111
+ }
112
+
113
+ export type InjectedExtension = InjectedExtensionInfo & Injected;
114
+
115
+ export type InjectOptions = InjectedExtensionInfo;
116
+
117
+ export interface Web3AccountsOptions {
118
+ accountType?: KeypairType[];
119
+ extensions?: string[];
120
+ genesisHash?: string | null;
121
+ ss58Format?: number;
122
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "baseUrl": "..",
5
+ "outDir": "./build",
6
+ "rootDir": "./src"
7
+ },
8
+ "exclude": [
9
+ "**/*.spec.ts"
10
+ ],
11
+ "references": []
12
+ }