Add cryptoIsReady (#557)

* Add cryptoIsReady

* Bump yarn
This commit is contained in:
Jaco Greeff
2020-02-29 11:51:17 +01:00
committed by GitHub
parent 42f318fcb5
commit af56c10278
4 changed files with 36 additions and 23 deletions
+2 -1
View File
@@ -1,7 +1,8 @@
# 2.6.0-beta.x
- **Breaking change** Following on the 2.0 release, `@polkadot/wasm` was updated to 1.1+. sr25510 now only verifies 0.8+ signatures, closing the loop on no Substrate-era 1.x support
- **Breaking change** Following on the 2.0 release, `@polkadot/wasm` was updated to 1.1+. sr25510 now only verifies 0.8+ signatures, closing the loop on dropping Substrate 1.x-era support
- Add `signatureVerify (message: Uint8Array | string, signature: Uint8Array | string, addressOrPublicKey: Uint8Array | string): VerifyResult` to verify any signature, regardless of type. Returns validity & detected crypto type.
- Add `cryptoIsReady (): boolean` function to check status of initialization
- Add `addressCheckChecksum (decoded: Uint8Array)` as an helper to extract and verify the ss58 checksum
- Swap to yarn 2
+4 -17
View File
@@ -2,10 +2,13 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// polyfills
import './polyfill';
import wasmCrypto from '@polkadot/wasm-crypto';
// out of order and early in the chain, this also kicks off initialization on require
export * from './init';
// all internal exports
export * from './address';
export * from './blake2';
export * from './keccak';
@@ -18,19 +21,3 @@ export * from './secp256k1';
export * from './sha512';
export * from './signature';
export * from './xxhash';
export function cryptoWaitReady (): Promise<boolean> {
return wasmCrypto
.waitReady()
.then((): boolean => true)
.catch((error): boolean => {
console.error('Unable to initialize @polkadot/util-crypto', error);
return false;
});
}
// start init process immediately
cryptoWaitReady().catch((): void => {
// shouldn't happen, logged above
});
+25
View File
@@ -0,0 +1,25 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import wasmCrypto from '@polkadot/wasm-crypto';
export function cryptoIsReady (): boolean {
return wasmCrypto.isReady();
}
export function cryptoWaitReady (): Promise<boolean> {
return wasmCrypto
.waitReady()
.then((): boolean => true)
.catch((error): boolean => {
console.error('Unable to initialize @polkadot/util-crypto', error);
return false;
});
}
// start init process immediately
cryptoWaitReady().catch((): void => {
// shouldn't happen, logged above
});
+5 -5
View File
@@ -2829,8 +2829,8 @@ __metadata:
resolution: "@polkadot/keyring@workspace:packages/keyring"
dependencies:
"@babel/runtime": ^7.8.4
"@polkadot/util": 2.6.0-beta.4
"@polkadot/util-crypto": 2.6.0-beta.4
"@polkadot/util": 2.6.0-beta.5
"@polkadot/util-crypto": 2.6.0-beta.5
languageName: unknown
linkType: soft
@@ -2843,12 +2843,12 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/util-crypto@2.6.0-beta.4, @polkadot/util-crypto@workspace:packages/util-crypto":
"@polkadot/util-crypto@2.6.0-beta.5, @polkadot/util-crypto@workspace:packages/util-crypto":
version: 0.0.0-use.local
resolution: "@polkadot/util-crypto@workspace:packages/util-crypto"
dependencies:
"@babel/runtime": ^7.8.4
"@polkadot/util": 2.6.0-beta.4
"@polkadot/util": 2.6.0-beta.5
"@polkadot/wasm-crypto": ^1.1.1
"@types/bn.js": ^4.11.6
"@types/bs58": ^4.0.0
@@ -2868,7 +2868,7 @@ __metadata:
languageName: unknown
linkType: soft
"@polkadot/util@2.6.0-beta.4, @polkadot/util@workspace:packages/util":
"@polkadot/util@2.6.0-beta.5, @polkadot/util@workspace:packages/util":
version: 0.0.0-use.local
resolution: "@polkadot/util@workspace:packages/util"
dependencies: