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

enable on cennznet extension #25

Open
wants to merge 23 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
51 changes: 51 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: NPM Release Pipeline (develop/2.0)

on:
pull_request:
branches:
- master
types:
- labeled
check_suite:
types:
- completed

jobs:
release-to-github:
# release to github only when its a prerelease branch and auto merge label is triggered
if: ${{ startsWith(github.head_ref, 'useOnlyCENNZnetExtension') }} && ${{ github.event.label.name == 'automerge' }}
runs-on: ubuntu-latest
steps:
# checkout merged branch
- uses: actions/checkout@v2
with:
ref: useOnlyCENNZnetExtension
- uses: actions/setup-node@v1
with:
node-version: '15.3'
- name: find release version
id: find_version
run: |
echo ::set-output name=tag_name::$(cat packages/extension/package.json \
| grep version \
| head -1 \
| grep -E -o '[0-9|.]+\-*[a-z]*\.[0-9]+|]+')
- name: make release branch
uses: peterjgrainger/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
branch: "release/${{steps.find_version.outputs.tag_name}}"
- name: package
run: |
yarn && yarn build
npx lerna exec --ignore @cennznet/extension-ui -- 'cp package.json build/'
npx lerna exec --ignore @cennznet/extension-ui -- 'cp README.md build/'
npx lerna exec --ignore @cennznet/extension-ui -- 'cp ../../LICENSE build/'
- name: publish to npm
env:
NPM_KEY: ${{ secrets.NPM_KEY }}
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_KEY}" > ~/.npmrc
echo 'Publishing to npmjs.org.'
npx lerna exec --ignore @cennznet/extension-ui -- 'cd build && npm publish --access public'
12 changes: 12 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"packages": [
"packages/extension",
"packages/extension-base",
"packages/extension-chain",
"packages/extension-dapp",
"packages/extension-inject"
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "0.38.3"
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"repository": "https://github.com/polkadot-js/extension",
"author": "Jaco Greeff <[email protected]> & CENNZnet developers <[email protected]>",
"license": "Apache-2",
"version": "0.38.2",
"version": "0.38.3",
"private": true,
"workspaces": [
"packages/*"
Expand Down Expand Up @@ -41,6 +41,7 @@
"@polkadot/dev": "^0.62.7",
"@types/jest": "^26.0.22",
"i18next-scanner": "^3.0.0",
"lerna": "^3.13.1",
"sinon-chrome": "^3.0.1",
"stylelint": "^13.12.0",
"stylelint-config-recommended": "^4.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-base/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "@cennznet/extension-base",
"description": "Functions, classes and other utilities used in @polkadot/extension",
"version": "0.38.2",
"version": "0.38.3",
"type": "module",
"author": "Jaco Greeff <[email protected]>",
"license": "Apache-2",
"main": "index.js",
"sideEffects": false,
"dependencies": {
"@babel/runtime": "^7.13.10",
"@cennznet/extension-inject": "^0.38.2",
"@cennznet/extension-inject": "^0.38.3",
"@polkadot/api": "^4.4.1",
"@polkadot/keyring": "^6.0.5",
"@polkadot/phishing": "^0.6.72",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { SignerPayloadJSON } from '@polkadot/types/types';

import { ResponseSigning } from '@cennznet/extension-base/background/types';
import { MetadataDef } from '@cennznet/extension-inject/types';

import { KeyringPair } from '@polkadot/keyring/types';
import { TypeRegistry } from '@polkadot/types';
import keyring from '@polkadot/ui-keyring';
Expand Down
7 changes: 3 additions & 4 deletions packages/extension-base/src/background/handlers/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import type { MetadataDef } from '@cennznet/extension-inject/types';
import type { KeyringPair, KeyringPair$Json, KeyringPair$Meta } from '@polkadot/keyring/types';
import type { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
import type { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
import type {
AccountJson,
import type { AccountJson,
AllowedPath,
AuthorizeRequest,
MessageTypes,
Expand Down Expand Up @@ -45,11 +44,11 @@ import type {
ResponseSeedValidate,
ResponseSigningIsLocked,
ResponseType,
SigningRequest
} from '../types';
SigningRequest } from '../types';

import { ALLOWED_PATH, PASSWORD_EXPIRY_MS } from '@cennznet/extension-base/defaults';
import chrome from '@cennznet/extension-inject/chrome';

import { TypeRegistry } from '@polkadot/types';
import keyring from '@polkadot/ui-keyring';
import { accounts as accountsObservable } from '@polkadot/ui-keyring/observable/accounts';
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-base/src/background/handlers/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import type { MetadataDef, ProviderMeta } from '@cennznet/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';

import { BehaviorSubject } from 'rxjs';

import { addMetadata, knownMetadata } from '@cennznet/extension-chains';
import chrome from '@cennznet/extension-inject/chrome';
import { BehaviorSubject } from 'rxjs';

import { assert } from '@polkadot/util';

import { MetadataStore } from '../../stores';
Expand Down
1 change: 1 addition & 0 deletions packages/extension-base/src/background/handlers/Tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { MessageTypes, RequestAccountList, RequestAuthorizeTab, RequestRpcS

import { PHISHING_PAGE_REDIRECT } from '@cennznet/extension-base/defaults';
import { canDerive } from '@cennznet/extension-base/utils';

import { checkIfDenied } from '@polkadot/phishing';
import keyring from '@polkadot/ui-keyring';
import { accounts as accountsObservable } from '@polkadot/ui-keyring/observable/accounts';
Expand Down
5 changes: 3 additions & 2 deletions packages/extension-base/src/packageInfo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2017-2021 @polkadot/extension-base authors & contributors
// Copyright 2017-2021 @cennznet/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0

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

export const packageInfo = { name: '@cennznet/extension-base', version: '0.38.2' };
// eslint-disable-next-line header/header
export const packageInfo = { name: '@cennznet/extension-base', version: '0.38.3' };
3 changes: 2 additions & 1 deletion packages/extension-chains/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "@cennznet/extension-chains",
"description": "Definitions for all known chains as exposed by the extension.",
"version": "0.38.2",
"version": "0.38.3",
"type": "module",
"author": "Jaco Greeff <[email protected]>",
"license": "Apache-2",
"main": "index.js",
"sideEffects": false,
"dependencies": {
"@babel/runtime": "^7.13.10",
"@cennznet/extension-inject": "^0.38.3",
"@polkadot/networks": "^6.0.5"
},
"peerDependencies": {
Expand Down
454 changes: 229 additions & 225 deletions packages/extension-chains/src/config.ts

Large diffs are not rendered by default.

48 changes: 35 additions & 13 deletions packages/extension-chains/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// SPDX-License-Identifier: Apache-2.0

import type { MetadataDef } from '@cennznet/extension-inject/types';
import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
import type { Chain, MetadataFetched, RuntimeTypes } from './types';

import { Metadata } from '@polkadot/metadata';
import { TypeRegistry } from '@polkadot/types';
import { base64Decode } from '@polkadot/util-crypto';

import config from './config';
// imports chain details, generally metadata. For the generation of these,
// inside the api, run `yarn chain:info --ws <url>`
Expand All @@ -20,50 +22,70 @@ const definitions = new Map<string, MetadataDef>(
/** when metadata definition stored in extension is outdated
* get the definition for @cennznet/api/extension-releases
* for cennznet specific chains **/
export function getLatestMetaFromServer(genesisHashExpected: string): MetadataFetched | null {
export function getLatestMetaFromServer (genesisHashExpected: string): MetadataFetched | null {
try {
const xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "https://raw.githubusercontent.com/cennznet/api.js/master/extension-releases/metaCalls.json", false);

xmlHttp.open('GET', 'https://raw.githubusercontent.com/cennznet/api.js/master/extension-releases/metaCalls.json', false);
xmlHttp.send(null);
let response = xmlHttp.responseText;
const response: string = xmlHttp.responseText;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const metadataDetails = JSON.parse(response);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
const metaCallsList = metadataDetails?.metaCalls;

if (metaCallsList) {
// metaCalls is { genesisHash-specVersion: metaCalls }
const key = Object.keys(metaCallsList).filter(v => v.includes(genesisHashExpected));
const key = Object.keys(metaCallsList).filter((v) => v.includes(genesisHashExpected));

if (!key[0]) {
return null;
}

const [, specVersion] = key[0].split('-');
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
const metaCalls = metaCallsList[key[0]];
return {metaCalls, specVersion: parseInt(specVersion)};

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
return { metaCalls, specVersion: parseInt(specVersion) } as MetadataFetched;
}

return null;
} catch (e) {
console.log('Err:',e);
console.log('Err:', e);

return null;
}
}

/** when types stored in extension is outdated
* get the types for @cennznet/api/extension-releases
* for cennznet specific chains **/
export function getLatestTypesFromServer(genesisHashExpected: string): RuntimeTypes | null {
export function getLatestTypesFromServer (genesisHashExpected: string): RuntimeTypes | null {
try {
const xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "https://raw.githubusercontent.com/cennznet/api.js/master/extension-releases/runtimeModuleTypes.json", false);

xmlHttp.open('GET', 'https://raw.githubusercontent.com/cennznet/api.js/master/extension-releases/runtimeModuleTypes.json', false);
xmlHttp.send(null);
let response = xmlHttp.responseText;
const response = xmlHttp.responseText;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const additionalTypes = JSON.parse(response);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
const typesForCurrentChain = additionalTypes[genesisHashExpected];

if (typesForCurrentChain) {
const types = typesForCurrentChain.types;
const userExtensions = typesForCurrentChain.userExtensions;
return {types, userExtensions};
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
const types: Record<string, Record<string, string> | string> = typesForCurrentChain.types;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
const userExtensions: ExtDef = typesForCurrentChain.userExtensions;

return { types, userExtensions } as RuntimeTypes;
}

return null;
} catch (e) {
console.log('Err:',e);
console.log('Err:', e);

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

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

export const packageInfo = { name: '@cennznet/extension-chains', version: '0.38.2' };
// eslint-disable-next-line header/header
export const packageInfo = { name: '@cennznet/extension-chains', version: '0.38.3' };
3 changes: 2 additions & 1 deletion packages/extension-chains/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2019-2021 @polkadot/extension-chains authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';

import type { MetadataDef } from '@cennznet/extension-inject/types';
import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
import type { Registry } from '@polkadot/types/types';

export interface Chain {
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-dapp/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "@cennznet/extension-dapp",
"description": "Provides an interfaces around the injected globals for ease of access by dapp developers.",
"version": "0.38.2",
"version": "0.38.3",
"type": "module",
"author": "Jaco Greeff <[email protected]>",
"license": "Apache-2",
"main": "index.js",
"sideEffects": false,
"dependencies": {
"@babel/runtime": "^7.13.10",
"@cennznet/extension-inject": "^0.38.2",
"@cennznet/extension-inject": "^0.38.3",
"@polkadot/util": "^6.0.5",
"@polkadot/util-crypto": "^6.0.5"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-dapp/src/compat/singleSource.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2019-2021 @polkadot/extension-dapp authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { Signer } from '@polkadot/api/types';
import type { Injected, InjectedAccount, InjectedWindow } from '@cennznet/extension-inject/types';
import type { Signer } from '@polkadot/api/types';

// RxJs interface, only the bare-bones of what we need here
interface Subscriber<T> {
Expand Down
16 changes: 15 additions & 1 deletion packages/extension-dapp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import type { Injected, InjectedAccount, InjectedAccountWithMeta, InjectedExtension, InjectedExtensionInfo, InjectedProviderWithMeta, InjectedWindow, ProviderList, Unsubcall, Web3AccountsOptions } from '@cennznet/extension-inject/types';

import { InjectedWindowProvider } from '@cennznet/extension-inject/types';

import { u8aEq } from '@polkadot/util';
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';

Expand Down Expand Up @@ -44,9 +46,20 @@ let web3EnablePromise: Promise<InjectedExtension[]> | null = null;

export { isWeb3Injected, web3EnablePromise };

const CENNZNET_EXT = 'cennznet-extension';

function getWindowExtensions (originName: string): Promise<[InjectedExtensionInfo, Injected | void][]> {
let enableList: Record<string, InjectedWindowProvider>;

// Use only cennznet extension if its installed
if (win.injectedWeb3[CENNZNET_EXT]) {
enableList = { [CENNZNET_EXT]: win.injectedWeb3[CENNZNET_EXT] };
} else { // Use any other extension (fall back)
enableList = win.injectedWeb3;
}

return Promise.all(
Object.entries(win.injectedWeb3).map(([name, { enable, version }]): Promise<[InjectedExtensionInfo, Injected | void]> =>
Object.entries(enableList).map(([name, { enable, version }]): Promise<[InjectedExtensionInfo, Injected | void]> =>
Promise.all([
Promise.resolve({ name, version }),
enable(originName).catch((error: Error): void => {
Expand Down Expand Up @@ -113,6 +126,7 @@ export async function web3Accounts ({ ss58Format }: Web3AccountsOptions = {}): P
return mapAccounts(source, list, ss58Format);
} catch (error) {
console.error('web3accounts failed:', error);

// cannot handle this one
return [];
}
Expand Down
5 changes: 3 additions & 2 deletions packages/extension-dapp/src/packageInfo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2017-2021 @polkadot/extension-dapp authors & contributors
// Copyright 2017-2021 @cennznet/extension-dapp authors & contributors
// SPDX-License-Identifier: Apache-2.0

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

export const packageInfo = { name: '@cennznet/extension-dapp', version: '0.38.2' };
// eslint-disable-next-line header/header
export const packageInfo = { name: '@cennznet/extension-dapp', version: '0.38.3' };
2 changes: 1 addition & 1 deletion packages/extension-inject/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@cennznet/extension-inject",
"description": "A generic injector (usable to any extension), that populates the base exposed interfaces to be used by dapps.",
"version": "0.38.2",
"version": "0.38.3",
"type": "module",
"author": "Jaco Greeff <[email protected]>",
"license": "Apache-2",
Expand Down
5 changes: 3 additions & 2 deletions packages/extension-inject/src/packageInfo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2017-2021 @polkadot/extension-inject authors & contributors
// Copyright 2017-2021 @cennznet/extension-inject authors & contributors
// SPDX-License-Identifier: Apache-2.0

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

export const packageInfo = { name: '@cennznet/extension-inject', version: '0.38.2' };
// eslint-disable-next-line header/header
export const packageInfo = { name: '@cennznet/extension-inject', version: '0.38.3' };
Loading