Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CENNZnet Extension with unique origin #30

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"@polkadot/keyring": "^6.0.5",
"@polkadot/networks": "^6.0.5",
"@polkadot/types": "^4.4.2-1",
"@polkadot/util": "^6.0.5",
"@polkadot/util-crypto": "^6.0.5",
"@polkadot/x-fetch": "^6.0.5",
"@polkadot/util": "6.0.5",
"@polkadot/util-crypto": "6.0.5",
"@polkadot/x-fetch": "6.0.5",
"babel-core": "^7.0.0-bridge.0",
"safe-buffer": "^5.2.1",
"typescript": "^4.2.4"
Expand Down Expand Up @@ -44,6 +44,7 @@
"sinon-chrome": "^3.0.1",
"stylelint": "^13.12.0",
"stylelint-config-recommended": "^4.0.0",
"stylelint-config-styled-components": "^0.1.1"
"stylelint-config-styled-components": "^0.1.1",
"yarn-audit-fix": "^9.3.10"
}
}
2 changes: 1 addition & 1 deletion packages/extension-base/src/background/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export type MessageTypesWithNullRequest = NullKeys<RequestTypes>
export interface TransportRequestMessage<TMessageType extends MessageTypes> {
id: string;
message: TMessageType;
origin: 'page' | 'extension';
origin: string;
request: RequestTypes[TMessageType];
}

Expand Down
10 changes: 7 additions & 3 deletions packages/extension-base/src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
// SPDX-License-Identifier: Apache-2.0

const ALLOWED_PATH = ['/', '/account/import-ledger', '/account/restore-json'] as const;
const PORT_CONTENT = 'content';
const PORT_CONTENT = 'cennznet-content';
const PHISHING_PAGE_REDIRECT = '/phishing-page-detected';
const PORT_EXTENSION = 'extension';
const PORT_EXTENSION = 'cennznet-extension';
const PASSWORD_EXPIRY_MIN = 15;
const PASSWORD_EXPIRY_MS = PASSWORD_EXPIRY_MIN * 60 * 1000;
const MESSAGE_ORIGIN_PAGE = 'cennznet-page';
const MESSAGE_ORIGIN_CONTENT = 'cennznet-content';

export {
ALLOWED_PATH,
PASSWORD_EXPIRY_MIN,
PASSWORD_EXPIRY_MS,
PHISHING_PAGE_REDIRECT,
PORT_CONTENT,
PORT_EXTENSION
PORT_EXTENSION,
MESSAGE_ORIGIN_PAGE,
MESSAGE_ORIGIN_CONTENT
};
3 changes: 1 addition & 2 deletions packages/extension-base/src/packageInfo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2017-2021 @cennznet/extension-base authors & contributors
// Copyright 2017-2021 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0

// Auto-generated by @polkadot/dev, do not edit

// eslint-disable-next-line header/header
export const packageInfo = { name: '@cennznet/extension-base', version: '0.38.3' };
4 changes: 3 additions & 1 deletion packages/extension-base/src/page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import type { MessageTypes, MessageTypesWithNoSubscriptions, MessageTypesWithNullRequest, MessageTypesWithSubscriptions, RequestTypes, ResponseTypes, SubscriptionMessageTypes, TransportRequestMessage, TransportResponseMessage } from '../background/types';

import { MESSAGE_ORIGIN_PAGE } from '@cennznet/extension-base/defaults';

import Injected from './Injected';

// when sending a message from the injector to the extension, we
Expand Down Expand Up @@ -40,7 +42,7 @@ export function sendMessage<TMessageType extends MessageTypes> (message: TMessag
const transportRequestMessage: TransportRequestMessage<TMessageType> = {
id,
message,
origin: 'page',
origin: MESSAGE_ORIGIN_PAGE,
request: request || null as RequestTypes[TMessageType]
};

Expand Down
3 changes: 1 addition & 2 deletions packages/extension-chains/src/packageInfo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2017-2021 @cennznet/extension-chains authors & contributors
// Copyright 2017-2021 @polkadot/extension-chains authors & contributors
// SPDX-License-Identifier: Apache-2.0

// Auto-generated by @polkadot/dev, do not edit

// eslint-disable-next-line header/header
export const packageInfo = { name: '@cennznet/extension-chains', version: '0.38.3' };
3 changes: 1 addition & 2 deletions packages/extension-dapp/src/packageInfo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2017-2021 @cennznet/extension-dapp authors & contributors
// Copyright 2017-2021 @polkadot/extension-dapp authors & contributors
// SPDX-License-Identifier: Apache-2.0

// Auto-generated by @polkadot/dev, do not edit

// eslint-disable-next-line header/header
export const packageInfo = { name: '@cennznet/extension-dapp', version: '0.38.3' };
3 changes: 1 addition & 2 deletions packages/extension-inject/src/packageInfo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2017-2021 @cennznet/extension-inject authors & contributors
// Copyright 2017-2021 @polkadot/extension-inject authors & contributors
// SPDX-License-Identifier: Apache-2.0

// Auto-generated by @polkadot/dev, do not edit

// eslint-disable-next-line header/header
export const packageInfo = { name: '@cennznet/extension-inject', version: '0.38.3' };
6 changes: 3 additions & 3 deletions packages/extension/src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@

import type { Message } from '@cennznet/extension-base/types';

import { PORT_CONTENT } from '@cennznet/extension-base/defaults';
import { MESSAGE_ORIGIN_CONTENT, MESSAGE_ORIGIN_PAGE, PORT_CONTENT } from '@cennznet/extension-base/defaults';
import chrome from '@cennznet/extension-inject/chrome';

// connect to the extension
const port = chrome.runtime.connect({ name: PORT_CONTENT });

// send any messages from the extension back to the page
port.onMessage.addListener((data): void => {
window.postMessage({ ...data, origin: 'content' }, '*');
window.postMessage({ ...data, origin: MESSAGE_ORIGIN_CONTENT }, '*');
});

// all messages from the page, pass them to the extension
window.addEventListener('message', ({ data, source }: Message): void => {
// only allow messages from our window, by the inject
if (source !== window || data.origin !== 'page') {
if (source !== window || data.origin !== MESSAGE_ORIGIN_PAGE) {
return;
}

Expand Down
3 changes: 1 addition & 2 deletions packages/extension/src/packageInfo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2017-2021 @cennznet/extension authors & contributors
// Copyright 2017-2021 @polkadot/extension authors & contributors
// SPDX-License-Identifier: Apache-2.0

// Auto-generated by @polkadot/dev, do not edit

// eslint-disable-next-line header/header
export const packageInfo = { name: '@cennznet/extension', version: '0.38.3' };
3 changes: 2 additions & 1 deletion packages/extension/src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

import type { Message } from '@cennznet/extension-base/types';

import { MESSAGE_ORIGIN_CONTENT } from '@cennznet/extension-base/defaults';
import { enable, handleResponse, redirectIfPhishing } from '@cennznet/extension-base/page';
import { injectExtension } from '@cennznet/extension-inject';

// setup a response listener (events created by the loader for extension responses)
window.addEventListener('message', ({ data, source }: Message): void => {
// only allow messages from our window, by the loader
if (source !== window || data.origin !== 'content') {
if (source !== window || data.origin !== MESSAGE_ORIGIN_CONTENT) {
return;
}

Expand Down
Loading