Import cleanups (#1246)

This commit is contained in:
Jaco
2023-04-03 09:31:55 +03:00
committed by GitHub
parent 934d4f3a9d
commit 9fe7868f2c
27 changed files with 62 additions and 65 deletions
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { KeyringPair } from '@polkadot/keyring/types';
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { KeyringPair } from '@polkadot/keyring/types';
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
/// <reference types="@polkadot/dev-test/globals" />
@@ -11,7 +11,7 @@ import type { KeyringPair } from '@polkadot/keyring/types';
import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
import type { SignerPayloadJSON } from '@polkadot/types/types';
import type { KeypairType } from '@polkadot/util-crypto/types';
import type { AuthUrls } from './State.js';
import type { AuthUrls } from '../types.js';
import { TypeRegistry } from '@polkadot/types';
import keyring from '@polkadot/ui-keyring';
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { MetadataDef } from '@polkadot/extension-inject/types';
@@ -3,17 +3,17 @@
import type { MetadataDef, ProviderMeta } from '@polkadot/extension-inject/types';
import type { JsonRpcResponse, ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types';
import type { AccountJson, AuthorizeRequest, MetadataRequest, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning, SigningRequest } from '../types.js';
import type { AccountJson, AuthorizeRequest, AuthUrlInfo, AuthUrls, MetadataRequest, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning, SigningRequest } from '../types.js';
import { BehaviorSubject } from 'rxjs';
import { getId } from '@polkadot/extension-base/utils/getId';
import { addMetadata, knownMetadata } from '@polkadot/extension-chains';
import { knownGenesis } from '@polkadot/networks/defaults';
import settings from '@polkadot/ui-settings';
import { assert } from '@polkadot/util';
import { MetadataStore } from '../../stores/index.js';
import { getId } from '../../utils/getId.js';
import { withErrorLog } from './helpers.js';
interface Resolver<T> {
@@ -28,20 +28,8 @@ interface AuthRequest extends Resolver<AuthResponse> {
url: string;
}
export type AuthUrls = Record<string, AuthUrlInfo>;
export type AuthorizedAccountsDiff = [url: string, authorizedAccounts: AuthUrlInfo['authorizedAccounts']][]
export interface AuthUrlInfo {
count: number;
id: string;
// this is from pre-0.44.1
isAllowed?: boolean;
origin: string;
url: string;
authorizedAccounts: string[];
}
interface MetaRequest extends Resolver<boolean> {
id: string;
request: MetadataDef;
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Subscription } from 'rxjs';
@@ -10,13 +10,13 @@ import type { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
import type { MessageTypes, RequestAccountList, RequestAccountUnsubscribe, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestTypes, ResponseRpcListProviders, ResponseSigning, ResponseTypes, SubscriptionMessageTypes } from '../types.js';
import type { AuthResponse } from './State.js';
import { PHISHING_PAGE_REDIRECT } from '@polkadot/extension-base/defaults';
import { canDerive } from '@polkadot/extension-base/utils';
import { checkIfDenied } from '@polkadot/phishing';
import keyring from '@polkadot/ui-keyring';
import { accounts as accountsObservable } from '@polkadot/ui-keyring/observable/accounts';
import { assert, isNumber } from '@polkadot/util';
import { PHISHING_PAGE_REDIRECT } from '../../defaults.js';
import { canDerive } from '../../utils/index.js';
import RequestBytesSign from '../RequestBytesSign.js';
import RequestExtrinsicSign from '../RequestExtrinsicSign.js';
import { withErrorLog } from './helpers.js';
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
export function withErrorLog (fn: () => unknown): void {
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { MessageTypes, TransportRequestMessage } from '../types.js';
@@ -10,6 +10,8 @@ import Extension from './Extension.js';
import State from './State.js';
import Tabs from './Tabs.js';
export { withErrorLog } from './helpers.js';
const state = new State();
const extension = new Extension(state);
const tabs = new Tabs(state);
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { MessageTypesWithSubscriptions, SubscriptionMessageTypes } from '../types.js';
@@ -0,0 +1,4 @@
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { default as handlers, withErrorLog } from './handlers/index.js';
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable no-use-before-define */
@@ -10,7 +10,7 @@ import type { Registry, SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/ty
import type { KeyringPairs$Json } from '@polkadot/ui-keyring/types';
import type { HexString } from '@polkadot/util/types';
import type { KeypairType } from '@polkadot/util-crypto/types';
import type { AuthResponse, AuthUrls } from './handlers/State.js';
import type { AuthResponse } from './handlers/State.js';
import { ALLOWED_PATH } from '../defaults.js';
@@ -26,6 +26,18 @@ type IsNull<T, K extends keyof T> = { [K1 in Exclude<keyof T, K>]: T[K1] } & T[K
type NullKeys<T> = { [K in keyof T]: IsNull<T, K> }[keyof T];
export type AuthUrls = Record<string, AuthUrlInfo>;
export interface AuthUrlInfo {
count: number;
id: string;
// this is from pre-0.44.1
isAllowed?: boolean;
origin: string;
url: string;
authorizedAccounts: string[];
}
export type SeedLengths = 12 | 24;
export interface AccountJson extends KeyringPair$Meta {
+13 -21
View File
@@ -2,33 +2,25 @@
// SPDX-License-Identifier: Apache-2.0
// this _must_ be changed for each extension
const EXTENSION_PREFIX = process.env.EXTENSION_PREFIX || '';
export const EXTENSION_PREFIX = process.env.EXTENSION_PREFIX || '';
if (!EXTENSION_PREFIX && !process.env.PORT_PREFIX) {
throw new Error('CRITICAL: The extension does not define an own EXTENSION_PREFIX environment variable as part of the build, this is required to ensure that messages are not shared between extensions. Failure to do so will yield messages sent to multiple extensions.');
}
const PORT_PREFIX = `${EXTENSION_PREFIX || 'unknown'}-${process.env.PORT_PREFIX || 'unknown'}`;
const PORT_CONTENT = `${PORT_PREFIX}-content`;
const PORT_EXTENSION = `${PORT_PREFIX}-extension`;
const MESSAGE_ORIGIN_PAGE = `${PORT_PREFIX}-page`;
const MESSAGE_ORIGIN_CONTENT = `${PORT_PREFIX}-content`;
const ALLOWED_PATH = ['/', '/account/import-ledger', '/account/restore-json'] as const;
const PHISHING_PAGE_REDIRECT = '/phishing-page-detected';
const PASSWORD_EXPIRY_MIN = 15;
const PASSWORD_EXPIRY_MS = PASSWORD_EXPIRY_MIN * 60 * 1000;
export const PORT_CONTENT = `${PORT_PREFIX}-content`;
export const PORT_EXTENSION = `${PORT_PREFIX}-extension`;
export const MESSAGE_ORIGIN_PAGE = `${PORT_PREFIX}-page`;
export const MESSAGE_ORIGIN_CONTENT = `${PORT_PREFIX}-content`;
export const ALLOWED_PATH = ['/', '/account/import-ledger', '/account/restore-json'] as const;
export const PASSWORD_EXPIRY_MIN = 15;
export const PASSWORD_EXPIRY_MS = PASSWORD_EXPIRY_MIN * 60 * 1000;
export const PHISHING_PAGE_REDIRECT = '/phishing-page-detected';
// console.log(`Extension is sending and receiving messages on ${PORT_PREFIX}-*`);
export {
ALLOWED_PATH,
PASSWORD_EXPIRY_MIN,
PASSWORD_EXPIRY_MS,
PHISHING_PAGE_REDIRECT,
EXTENSION_PREFIX,
PORT_CONTENT,
PORT_EXTENSION,
MESSAGE_ORIGIN_PAGE,
MESSAGE_ORIGIN_CONTENT
};
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { InjectedAccount, InjectedAccounts, Unsubcall } from '@polkadot/extension-inject/types';
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Injected } from '@polkadot/extension-inject/types';
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { InjectedMetadata, InjectedMetadataKnown, MetadataDef } from '@polkadot/extension-inject/types';
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { MessageTypes, MessageTypesWithNoSubscriptions, MessageTypesWithNullRequest, MessageTypesWithSubscriptions, RequestTypes, ResponseTypes, SubscriptionMessageTypes, TransportRequestMessage, TransportResponseMessage } from '../background/types.js';
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
export interface Message extends MessageEvent {
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { KeypairType } from '@polkadot/util-crypto/types';
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { EXTENSION_PREFIX } from '../defaults.js';
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// Copyright 2019-2023 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { canDerive } from './canDerive.js';
@@ -1,13 +1,13 @@
// Copyright 2019-2023 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AuthUrlInfo } from '@polkadot/extension-base/background/handlers/State';
import type { AuthUrlInfo } from '@polkadot/extension-base/background/types';
import type { ThemeProps } from '../../types.js';
import React, { useCallback } from 'react';
import { Link } from 'react-router-dom';
import { useTranslation } from '@polkadot/extension-ui/components/translate';
import { useTranslation } from '@polkadot/extension-ui/translate';
import RemoveAuth from '../../components/RemoveAuth.js';
import { styled } from '../../styled.js';
@@ -1,7 +1,7 @@
// Copyright 2019-2023 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AuthUrlInfo, AuthUrls } from '@polkadot/extension-base/background/handlers/State';
import type { AuthUrlInfo, AuthUrls } from '@polkadot/extension-base/background/types';
import type { ThemeProps } from '../../types.js';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
@@ -11,8 +11,8 @@ import React, { useCallback, useContext, useEffect, useState } from 'react';
import { TypeRegistry } from '@polkadot/types';
import { ActionContext, Address, VerticalSpace, Warning } from '../../../components/index.js';
import { useTranslation } from '../../../components/translate.js';
import { approveSignSignature } from '../../../messaging.js';
import { useTranslation } from '../../../translate.js';
import Bytes from '../Bytes.js';
import Extrinsic from '../Extrinsic.js';
import LedgerSign from '../LedgerSign.js';
@@ -6,9 +6,9 @@ import type { WithTranslation } from 'react-i18next';
import React from 'react';
import Header from '../partials/Header.js';
import translate from '../translate.js';
import Button from './Button.js';
import ButtonArea from './ButtonArea.js';
import translate from './translate.js';
import VerticalSpace from './VerticalSpace.js';
interface Props extends WithTranslation {
+1 -2
View File
@@ -7,8 +7,7 @@ import '@polkadot/extension-inject/crossenv';
import type { RequestSignatures, TransportRequestMessage } from '@polkadot/extension-base/background/types';
import handlers from '@polkadot/extension-base/background/handlers';
import { withErrorLog } from '@polkadot/extension-base/background/handlers/helpers';
import { handlers, withErrorLog } from '@polkadot/extension-base/background';
import { PORT_CONTENT, PORT_EXTENSION } from '@polkadot/extension-base/defaults';
import { AccountsStore } from '@polkadot/extension-base/stores';
import keyring from '@polkadot/ui-keyring';
+2 -2
View File
@@ -8,8 +8,8 @@
"@polkadot/extension": ["extension/src/index.ts"],
"@polkadot/extension/*": ["extension/src/*.ts"],
"@polkadot/extension-base": ["extension-base/src/index.ts"],
"@polkadot/extension-base/background/handlers": ["extension-base/src/background/handlers/index.ts"],
"@polkadot/extension-base/packageInfo": ["extension-base/src/packageInfo.ts"],
"@polkadot/extension-base/background": ["extension-base/src/background/index.ts"],
"@polkadot/extension-base/background/types": ["extension-base/src/background/types.ts"],
"@polkadot/extension-base/page": ["extension-base/src/page/index.ts"],
"@polkadot/extension-base/stores": ["extension-base/src/stores/index.ts"],
"@polkadot/extension-base/utils": ["extension-base/src/utils/index.ts"],