Schnorrkel support (#72)

* Schnorrkel support

* Uuse KeyringOptions in loadAll

* Bump

* Bump version

* Integrate new updates
This commit is contained in:
Jaco Greeff
2019-02-14 23:38:49 +01:00
committed by GitHub
parent 6c851035b8
commit c48b6ff6f8
10 changed files with 97 additions and 84 deletions
+1 -1
View File
@@ -10,5 +10,5 @@
"packages": [
"packages/*"
],
"version": "0.25.12"
"version": "0.26.0"
}
+1 -1
View File
@@ -24,7 +24,7 @@
},
"devDependencies": {
"@babel/core": "^7.2.2",
"@polkadot/dev-react": "^0.23.14",
"@polkadot/dev-react": "^0.23.15",
"@polkadot/ts": "^0.1.52",
"empty": "^0.10.1"
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/ui-assets",
"version": "0.25.12",
"version": "0.26.0",
"description": "Static assets shared accross projects",
"main": "index.js",
"author": "Jaco Greeff <jacogr@gmail.com>",
+4 -4
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/ui-identicon",
"version": "0.25.12",
"version": "0.26.0",
"description": "Renders an SVG picture representing an address",
"main": "index.js",
"author": "Jaco Greeff <jacogr@gmail.com>",
@@ -10,7 +10,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.2.0",
"@polkadot/ui-settings": "^0.25.12",
"@polkadot/ui-settings": "^0.26.0",
"@types/color": "^3.0.0",
"@types/react-copy-to-clipboard": "^4.2.6",
"color": "^3.0.0",
@@ -22,8 +22,8 @@
"react": "*"
},
"devDependencies": {
"@polkadot/keyring": "^0.33.36",
"@polkadot/util-crypto": "^0.33.36",
"@polkadot/keyring": "^0.34.6",
"@polkadot/util-crypto": "^0.34.6",
"xmlserializer": "^0.6.1"
}
}
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/ui-keyring",
"version": "0.25.12",
"version": "0.26.0",
"main": "index.js",
"repository": "https://github.com/polkadot-js/apps.git",
"author": "Jaco Greeff <jacogr@gmail.com>",
@@ -16,13 +16,13 @@
"store": "^2.0.12"
},
"devDependencies": {
"@polkadot/keyring": "^0.33.36",
"@polkadot/types": "^0.42.11",
"@polkadot/util": "^0.33.36"
"@polkadot/keyring": "^0.34.6",
"@polkadot/types": "^0.43.1",
"@polkadot/util": "^0.34.6"
},
"peerDependencies": {
"@polkadot/keyring": "*",
"@polkadot/types": "*",
"@polkadot/keyring": ">=0.34.3",
"@polkadot/types": ">=0.43.1",
"@polkadot/util": "*"
}
}
+32 -31
View File
@@ -3,11 +3,11 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { Prefix } from '@polkadot/keyring/address/types';
import { KeyringInstance, KeyringPair } from '@polkadot/keyring/types';
import { KeyringInstance, KeyringPair, KeyringOptions } from '@polkadot/keyring/types';
import { AddressSubject } from './observable/types';
import testKeyring from '@polkadot/keyring/testing';
import { isString } from '@polkadot/util';
import { isBoolean, isString } from '@polkadot/util';
import accounts from './observable/accounts';
import addresses from './observable/addresses';
@@ -18,13 +18,12 @@ export default class Base {
private _accounts: AddressSubject;
private _addresses: AddressSubject;
private _keyring?: KeyringInstance;
private _prefix: Prefix;
private _prefix?: Prefix;
constructor () {
this._accounts = accounts;
this._addresses = addresses;
this._keyring = undefined;
this._prefix = 42;
}
get accounts () {
@@ -51,6 +50,30 @@ export default class Base {
return this.keyring.encodeAddress(key);
}
getPair (address: string | Uint8Array): KeyringPair {
return this.keyring.getPair(address);
}
getPairs (): Array<KeyringPair> {
return this.keyring.getPairs().filter((pair: KeyringPair) =>
env.isDevelopment() || pair.getMeta().isTesting !== true
);
}
isAvailable (_address: Uint8Array | string): boolean {
const accountsValue = this.accounts.subject.getValue();
const addressesValue = this.addresses.subject.getValue();
const address = isString(_address)
? _address
: this.encodeAddress(_address);
return !accountsValue[address] && !addressesValue[address];
}
isPassValid (password: string): boolean {
return password.length > 0 && password.length <= MAX_PASS_LEN;
}
setAddressPrefix (prefix: number): void {
this._prefix = prefix as Prefix;
}
@@ -59,10 +82,12 @@ export default class Base {
env.set(isDevelopment);
}
protected initKeyring (): void {
const keyring = testKeyring();
protected initKeyring (options: KeyringOptions & { isDevelopment?: boolean }): void {
const keyring = testKeyring({ addressPrefix: this._prefix, ...options });
keyring.setAddressPrefix(this._prefix);
if (isBoolean(options.isDevelopment)) {
this.setDevMode(options.isDevelopment);
}
this._keyring = keyring;
@@ -87,28 +112,4 @@ export default class Base {
pair.setMeta({ whenCreated: Date.now() });
}
}
isAvailable (_address: Uint8Array | string): boolean {
const accountsValue = this.accounts.subject.getValue();
const addressesValue = this.addresses.subject.getValue();
const address = isString(_address)
? _address
: this.encodeAddress(_address);
return !accountsValue[address] && !addressesValue[address];
}
isPassValid (password: string): boolean {
return password.length > 0 && password.length <= MAX_PASS_LEN;
}
getPair (address: string | Uint8Array): KeyringPair {
return this.keyring.getPair(address);
}
getPairs (): Array<KeyringPair> {
return this.keyring.getPairs().filter((pair: KeyringPair) =>
env.isDevelopment() || pair.getMeta().isTesting !== true
);
}
}
+7 -7
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeyringPair, KeyringPair$Meta, KeyringPair$Json } from '@polkadot/keyring/types';
import { KeyringPair, KeyringPair$Meta, KeyringPair$Json, KeyringOptions } from '@polkadot/keyring/types';
import { SingleAddress } from './observable/types';
import { KeyringAddress, KeyringJson, KeyringJson$Meta, KeyringStruct } from './types';
@@ -16,7 +16,7 @@ import { accountKey, addressKey, accountRegex, addressRegex } from './defaults';
import keyringOption from './options';
// No accounts (or test accounts) should be loaded until after the chain determination.
// Chain determination occurs outside of Keyring. Loading `keyring.loadAll()` is triggered
// Chain determination occurs outside of Keyring. Loading `keyring.loadAll({ type: 'ed25519' | 'sr25519' })` is triggered
// from the API after the chain is received
class Keyring extends Base implements KeyringStruct {
addAccountPair (pair: KeyringPair, password: string): KeyringPair {
@@ -45,7 +45,7 @@ class Keyring extends Base implements KeyringStruct {
}
createAccountExternal (publicKey: Uint8Array, meta: KeyringPair$Meta = {}): KeyringPair {
const pair = this.keyring.addFromAddress(publicKey, { ...meta, isExternal: true });
const pair = this.keyring.addFromAddress(publicKey, { ...meta, isExternal: true }, null);
this.saveAccount(pair);
@@ -153,8 +153,8 @@ class Keyring extends Base implements KeyringStruct {
this.rewriteKey(json, key, hexAddr, addressKey);
}
loadAll (): void {
super.initKeyring();
loadAll (options: KeyringOptions): void {
super.initKeyring(options);
store.each((json: KeyringJson, key: string) => {
if (accountRegex.test(key)) {
@@ -169,9 +169,9 @@ class Keyring extends Base implements KeyringStruct {
restoreAccount (json: KeyringPair$Json, password: string): KeyringPair {
const pair = createPair(
this.keyring.type,
{
publicKey: this.decodeAddress(json.address),
secretKey: new Uint8Array()
publicKey: this.decodeAddress(json.address)
},
json.meta,
hexToU8a(json.encoded)
+2 -2
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeyringInstance as BaseKeyringInstance, KeyringPair, KeyringPair$Meta, KeyringPair$Json } from '@polkadot/keyring/types';
import { KeyringInstance as BaseKeyringInstance, KeyringPair, KeyringPair$Meta, KeyringPair$Json, KeyringOptions } from '@polkadot/keyring/types';
import { AddressSubject, SingleAddress } from './observable/types';
export type KeyringJson$Meta = {
@@ -50,7 +50,7 @@ export interface KeyringStruct {
getPairs: () => Array<KeyringPair>;
isAvailable: (address: string | Uint8Array) => boolean;
isPassValid: (password: string) => boolean;
loadAll: () => void;
loadAll: (options: KeyringOptions) => void;
restoreAccount: (json: KeyringPair$Json, password: string) => KeyringPair;
saveAccount: (pair: KeyringPair, password?: string) => void;
saveAccountMeta: (pair: KeyringPair, meta: KeyringPair$Meta) => void;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/ui-settings",
"version": "0.25.12",
"version": "0.26.0",
"description": "Manages app settings",
"main": "index.js",
"author": "Jaco Greeff <jacogr@gmail.com>",
+42 -30
View File
@@ -1375,15 +1375,20 @@
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b"
integrity sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==
"@polkadot/dev-react@^0.23.14":
version "0.23.14"
resolved "https://registry.yarnpkg.com/@polkadot/dev-react/-/dev-react-0.23.14.tgz#f33f69dcdb4cb4dd132f558618879fc99d38844b"
integrity sha512-2Ms6iOnR2oWA7QnLuH+tAt8HCMRtOexhXaOHakEBKV4OHP9qCQHufEGvy+fKRYYox1LCO/kV5i17ro0BD1hh0g==
"@parity/schnorrkel-js@^0.1.2":
version "0.1.2"
resolved "https://registry.yarnpkg.com/@parity/schnorrkel-js/-/schnorrkel-js-0.1.2.tgz#08c9663299cbe43d292599a1312a761b2426900f"
integrity sha512-eQSCY6kb16Lhnlgdz1FbADo1PEI3Xgp0ApGpNydf0yBEQ6AMVo1YN/4zMA3lFjqnurv9NsAy11OJApailUNneQ==
"@polkadot/dev-react@^0.23.15":
version "0.23.15"
resolved "https://registry.yarnpkg.com/@polkadot/dev-react/-/dev-react-0.23.15.tgz#0e99299ad54360629c3d8a1220063d1a1603b9bf"
integrity sha512-o+ziUDjlXIs4Yvtldgxbs77VB3ci4vusbD61Qt0et9e3hTVOFuw0XSqtCN5xdC1DD/7fX/BGd2FsRjrdYChNtQ==
dependencies:
"@babel/core" "^7.2.2"
"@babel/plugin-syntax-dynamic-import" "^7.2.0"
"@babel/preset-react" "^7.0.0"
"@polkadot/dev" "^0.23.14"
"@polkadot/dev" "^0.23.15"
"@types/react" "^16.7.18"
"@types/react-dom" "^16.0.11"
"@types/styled-components" "^4.1.5"
@@ -1411,10 +1416,10 @@
webpack-serve "^2.0.3"
worker-loader "^2.0.0"
"@polkadot/dev@^0.23.14":
version "0.23.14"
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.23.14.tgz#e649dfaaab4fb1c8e8f2c1695a8b5367dd3ce2ce"
integrity sha512-vmgS7THEvEp1v7iKw/QxanedAozSIRzUJWVHLUkIRyDSRfH3/iOFxEwNso0CNMULO1OHfIfhgDP+3lHj/IMB1A==
"@polkadot/dev@^0.23.15":
version "0.23.15"
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.23.15.tgz#f1428a706e5ff2138eaf38900070579dee84b57d"
integrity sha512-SVkB3s1KsFQm9Pka8zKx4S06LX5S70r7xCV2lTmbj/5Wj/diamuZgbAHU313cH89q59qU9Bns2gJhynvGXkXfg==
dependencies:
"@babel/cli" "^7.2.3"
"@babel/core" "^7.2.2"
@@ -1451,14 +1456,14 @@
typedoc-plugin-no-inherit "^1.1.2"
typescript "^3.2.2"
"@polkadot/keyring@^0.33.36":
version "0.33.36"
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.33.36.tgz#def02631369b1a2288ae95d32cadd63299f877f7"
integrity sha512-UUyb0ua+b10FAt+dH5Vuua0mu+FH9WY+as+IoVNXyDY8PpHY+kg8MDXXrCGBueCF5CaiiAJP7gD5vp7U10nrEg==
"@polkadot/keyring@^0.34.6":
version "0.34.6"
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.34.6.tgz#fbe7a9a4cc4d96c8c692c5269aa953aee5d3e7ef"
integrity sha512-137VRVVYhLQseB8qHVqmMhcn0PjXjRxJxGLIwxqfPPquPd6z00xcprNwLKm35fi9bH8Akj6isKD7e/DRKbAfSA==
dependencies:
"@babel/runtime" "^7.2.0"
"@polkadot/util" "^0.33.36"
"@polkadot/util-crypto" "^0.33.36"
"@polkadot/util" "^0.34.6"
"@polkadot/util-crypto" "^0.34.6"
"@types/bs58" "^4.0.0"
bs58 "^4.0.1"
@@ -1467,34 +1472,36 @@
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.52.tgz#6fb09e494d244dad4b3a9ca581bfe13beec66565"
integrity sha512-sij1O0x4CY51A394RYD4/aQwDPwIxIeTOpYI4AZgdF/vq5nvF14b4XFq9vAcSnblaIosf0sYKoz1f3dkN3QqLw==
"@polkadot/types@^0.42.11":
version "0.42.11"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.42.11.tgz#2fa8d632adbb791e38c039b11bb514cf0978058c"
integrity sha512-kN3qnNWdCcn5DpLJRnY3hkhHhfatxjmfJAniVxPktGiTZQJz5rZy1NJXZa910ylGk6ahkjlYQ6wbLFqQzXE0GA==
"@polkadot/types@^0.43.1":
version "0.43.1"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.43.1.tgz#6bf38c980e999a357c1a1ed575160fd48b91fe30"
integrity sha512-I686x+P9TKRhN/hw1HFCUXcCJAo7OTX35Jven1wNT2iZ3JKOI2vH9FUkx89umR2qDeYrQE7uhWB3kPR9+t7YLg==
dependencies:
"@babel/runtime" "^7.2.0"
"@polkadot/keyring" "^0.33.36"
"@polkadot/util" "^0.33.36"
"@polkadot/keyring" "^0.34.6"
"@polkadot/util" "^0.34.6"
core-js "^2.6.2"
"@polkadot/util-crypto@^0.33.36":
version "0.33.36"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.33.36.tgz#3b1fc84be7126fd92ee4de960baafb901e50b1a4"
integrity sha512-kjzdOrBL8NKfZZdWIhQFim3yDWo6sHjWOuxJQt8k22pHa/ATF8zVZ6Xqi4r+wsfBa9S+G6AE5yyVOirVPQYeCQ==
"@polkadot/util-crypto@^0.34.6":
version "0.34.6"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.34.6.tgz#4cbe8afb1630fd6bf5e602612ea18026c300c4a5"
integrity sha512-F/fAAOFMgzQwxheE2RAIf5G/oPVlJhKUTJLClrgyac5dmpnueWd4wfaHJC+071yFzP5GMR/0cTGe1LOShb9jOw==
dependencies:
"@babel/runtime" "^7.2.0"
"@polkadot/util" "^0.33.36"
"@parity/schnorrkel-js" "^0.1.2"
"@polkadot/util" "^0.34.6"
"@types/bip39" "^2.4.1"
"@types/webassembly-js-api" "^0.0.2"
bip39 "^2.5.0"
blakejs "^1.1.0"
js-sha3 "^0.8.0"
tweetnacl "^1.0.0"
xxhashjs "^0.2.2"
"@polkadot/util@^0.33.36":
version "0.33.36"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.33.36.tgz#975590dd059f78209c9d398f72651ac393dd8245"
integrity sha512-N5b46NYTNJODILXNGRxvW/8yeKiHjQv4k3YmJhYnslMsEbaXPvkePFUA2N8Ji1LQrAD8sQbaoG8aYoNaqHSJMA==
"@polkadot/util@^0.34.6":
version "0.34.6"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.34.6.tgz#00f66a231c3764719081fdcf2694ad53fbd7dcf3"
integrity sha512-8Ag/ISA7t0onx7f+PbREIJX69hWZe+prUDhRjVMT64VkiSE2ErfM74Lu+A3N4Yy9a/APQUTUhDrI6cnBT8SGbg==
dependencies:
"@babel/runtime" "^7.2.0"
"@types/bn.js" "^4.11.3"
@@ -1700,6 +1707,11 @@
"@types/react" "*"
csstype "^2.2.0"
"@types/webassembly-js-api@^0.0.2":
version "0.0.2"
resolved "https://registry.yarnpkg.com/@types/webassembly-js-api/-/webassembly-js-api-0.0.2.tgz#43a04bd75fa20332133c6c3986156bfeb4a3ced7"
integrity sha512-htlxJRag6RUiMYUkS8Fjup+TMHO0VarpiF9MrqYaGJ0wXtIraQFz40rfA8VIeCiWy8sgpv3RLmigpgicG8fqGA==
"@types/xxhashjs@^0.1.1":
version "0.1.1"
resolved "https://registry.yarnpkg.com/@types/xxhashjs/-/xxhashjs-0.1.1.tgz#980709096c7138713b7777f49dccd4b8f93908e5"