From 50159233ed11ba3f07f887c04cbcd44d3e1fc815 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 15 Feb 2019 10:01:09 +0100 Subject: [PATCH] Add async crypto init (#697) * Add async crypto init * Used ed25519 for mock --- packages/api/package.json | 1 + packages/api/src/Base.ts | 8 +++++-- packages/rpc-core/package.json | 2 +- packages/rpc-provider/package.json | 6 ++--- packages/rpc-provider/src/mock/index.ts | 2 +- packages/type-extrinsics/package.json | 2 +- packages/type-storage/package.json | 6 ++--- packages/types/package.json | 4 ++-- yarn.lock | 30 ++++++++++++------------- 9 files changed, 33 insertions(+), 28 deletions(-) diff --git a/packages/api/package.json b/packages/api/package.json index 9d6c583280..dcfbc37715 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -36,6 +36,7 @@ "@polkadot/rpc-rx": "^0.43.2", "@polkadot/storage": "^0.43.2", "@polkadot/types": "^0.43.2", + "@polkadot/util-crypto": "^0.34.9", "@types/rx": "^4.1.1", "rxjs": "^6.3.3" } diff --git a/packages/api/src/Base.ts b/packages/api/src/Base.ts index 08947463f4..f517b858ca 100644 --- a/packages/api/src/Base.ts +++ b/packages/api/src/Base.ts @@ -27,6 +27,7 @@ import { Event, Hash, Metadata, Method, RuntimeVersion, typeRegistry } from '@po import { MethodFunction, ModulesWithMethods } from '@polkadot/types/Method'; import { StorageFunction } from '@polkadot/types/StorageKey'; import { assert, compactStripLength, isFunction, isObject, isUndefined, logger, u8aToHex } from '@polkadot/util'; +import { cryptoWaitReady } from '@polkadot/util-crypto'; import SubmittableExtrinsic from './SubmittableExtrinsic'; @@ -324,9 +325,12 @@ export default abstract class ApiBase implement this._rpcBase._provider.on('connected', async () => { this.emit('connected'); - const hasMeta = await this.loadMeta(); + const [hasMeta, cryptoReady] = await Promise.all([ + this.loadMeta(), + cryptoWaitReady() + ]); - if (hasMeta && !this._isReady) { + if (hasMeta && !this._isReady && cryptoReady) { this._isReady = true; this.emit('ready', this); diff --git a/packages/rpc-core/package.json b/packages/rpc-core/package.json index 28750f8187..a00444bcfc 100644 --- a/packages/rpc-core/package.json +++ b/packages/rpc-core/package.json @@ -33,6 +33,6 @@ "@polkadot/jsonrpc": "^0.43.2", "@polkadot/rpc-provider": "^0.43.2", "@polkadot/types": "^0.43.2", - "@polkadot/util": "^0.34.7" + "@polkadot/util": "^0.34.9" } } diff --git a/packages/rpc-provider/package.json b/packages/rpc-provider/package.json index 68cf05f72a..252508c1ac 100644 --- a/packages/rpc-provider/package.json +++ b/packages/rpc-provider/package.json @@ -30,10 +30,10 @@ "homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme", "dependencies": { "@babel/runtime": "^7.2.0", - "@polkadot/keyring": "^0.34.7", + "@polkadot/keyring": "^0.34.9", "@polkadot/storage": "^0.43.2", - "@polkadot/util": "^0.34.7", - "@polkadot/util-crypto": "^0.34.7", + "@polkadot/util": "^0.34.9", + "@polkadot/util-crypto": "^0.34.9", "@types/nock": "^9.3.0", "eventemitter3": "^3.1.0", "isomorphic-fetch": "^2.2.1", diff --git a/packages/rpc-provider/src/mock/index.ts b/packages/rpc-provider/src/mock/index.ts index 02ef3fe7c9..a4e9951b00 100644 --- a/packages/rpc-provider/src/mock/index.ts +++ b/packages/rpc-provider/src/mock/index.ts @@ -30,7 +30,7 @@ const SUBSCRIPTIONS: string[] = Array.prototype.concat.apply( ) ); -const keyring = testKeyring({ type: 'sr25519' }); +const keyring = testKeyring({ type: 'ed25519' }); const l = logger('api-mock'); /** diff --git a/packages/type-extrinsics/package.json b/packages/type-extrinsics/package.json index e2008debc1..e4ee6d3aa4 100644 --- a/packages/type-extrinsics/package.json +++ b/packages/type-extrinsics/package.json @@ -12,6 +12,6 @@ "dependencies": { "@babel/runtime": "^7.2.0", "@polkadot/types": "^0.43.2", - "@polkadot/util": "^0.34.7" + "@polkadot/util": "^0.34.9" } } diff --git a/packages/type-storage/package.json b/packages/type-storage/package.json index 3eb3aec465..0d1b016bcb 100644 --- a/packages/type-storage/package.json +++ b/packages/type-storage/package.json @@ -30,9 +30,9 @@ "homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-storage#readme", "dependencies": { "@babel/runtime": "^7.2.0", - "@polkadot/keyring": "^0.34.7", + "@polkadot/keyring": "^0.34.9", "@polkadot/types": "^0.43.2", - "@polkadot/util": "^0.34.7", - "@polkadot/util-crypto": "^0.34.7" + "@polkadot/util": "^0.34.9", + "@polkadot/util-crypto": "^0.34.9" } } diff --git a/packages/types/package.json b/packages/types/package.json index 3d6eb790e1..3a7dc43770 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -30,8 +30,8 @@ "homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme", "dependencies": { "@babel/runtime": "^7.2.0", - "@polkadot/keyring": "^0.34.7", - "@polkadot/util": "^0.34.7", + "@polkadot/keyring": "^0.34.9", + "@polkadot/util": "^0.34.9", "core-js": "^2.6.2" } } diff --git a/yarn.lock b/yarn.lock index cc1d01fa52..0e7d6b02cc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1338,14 +1338,14 @@ typedoc-plugin-no-inherit "^1.1.2" typescript "^3.2.2" -"@polkadot/keyring@^0.34.7": - version "0.34.7" - resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.34.7.tgz#1878aa9a04290f179ca81be0777847995addff16" - integrity sha512-h/F3iFpQ9BXVjmHFKAWd4E2CzAidrBPRIeYZy7G20G71AhK1Tz3GipwL0WT6SnBXR5oCPna9pPAM+j5QUkkOqw== +"@polkadot/keyring@^0.34.9": + version "0.34.9" + resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.34.9.tgz#54c5e9c503d7ea2d3176ebc744bd50e37f4ed99f" + integrity sha512-kQP+Ciawttz1egWPcCb7RXjZKW3IsGcPao8iau/beJFKAz32oOxem1BVA0ToiynYj9y7ivbJCs/E0lf+5iY0Ng== dependencies: "@babel/runtime" "^7.2.0" - "@polkadot/util" "^0.34.7" - "@polkadot/util-crypto" "^0.34.7" + "@polkadot/util" "^0.34.9" + "@polkadot/util-crypto" "^0.34.9" "@types/bs58" "^4.0.0" bs58 "^4.0.1" @@ -1354,14 +1354,14 @@ resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.52.tgz#6fb09e494d244dad4b3a9ca581bfe13beec66565" integrity sha512-sij1O0x4CY51A394RYD4/aQwDPwIxIeTOpYI4AZgdF/vq5nvF14b4XFq9vAcSnblaIosf0sYKoz1f3dkN3QqLw== -"@polkadot/util-crypto@^0.34.7": - version "0.34.7" - resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.34.7.tgz#e0af91c2b83f4df87b7d510b63486741086b091b" - integrity sha512-5V7ZwHmhAkJDfTuURqQZ83KPwFWWK4qJS1eFb3Jba9Kb2mc15oGcIbBsxkv0dnb0x2XHgT4tWvhXR8luYuRUbw== +"@polkadot/util-crypto@^0.34.9": + version "0.34.9" + resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.34.9.tgz#bcdf53d062c79c277b79cd167b6a14d42432a7ba" + integrity sha512-XXLJCSks5/14Hc6nZnVyKLLVElDJ+c454kOFt7xjeYpBSohBSSeGx1G9uFoPsAILDC4vuDD+ZtO2fQtzNGa9aQ== dependencies: "@babel/runtime" "^7.2.0" "@parity/schnorrkel-js" "^0.1.2" - "@polkadot/util" "^0.34.7" + "@polkadot/util" "^0.34.9" "@types/bip39" "^2.4.1" "@types/webassembly-js-api" "^0.0.2" bip39 "^2.5.0" @@ -1370,10 +1370,10 @@ tweetnacl "^1.0.0" xxhashjs "^0.2.2" -"@polkadot/util@^0.34.7": - version "0.34.7" - resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.34.7.tgz#0cc1c7b44eaed24a783c23317761dac153ac2e72" - integrity sha512-V+ubvA6DwjxJaWj0aHPlprPtF/5chqxqdXOLe5qQQeRXNifyr2d8uihIYGBvt1e5EypaVJd26sLNdJN98wk48g== +"@polkadot/util@^0.34.9": + version "0.34.9" + resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.34.9.tgz#919dc57de5441358a45f1c4f2fcf2cf0773285ab" + integrity sha512-kyGwG9apL8QBseIMVkP4BanyJboekF9hGLvyNhpka0f9aynEUs/TxRpExo5KRL4r9DTEKrDA8TDDBs3uQ1veHg== dependencies: "@babel/runtime" "^7.2.0" "@types/bn.js" "^4.11.3"