sodium-wasm support (#170)

* sodium-wasm support

* Update deps
This commit is contained in:
Jaco Greeff 2018-08-02 07:34:39 +02:00 committed by GitHub
parent fb9d0153c2
commit 1ea1e193c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 150 additions and 112 deletions

View File

@ -28,7 +28,7 @@
},
"devDependencies": {
"@polkadot/dev-react": "^0.20.12",
"@polkadot/ts": "^0.1.9",
"@polkadot/ts": "^0.1.10",
"autoprefixer": "^8.6.2",
"gh-pages": "^1.1.0",
"postcss-import": "^11.1.0",

View File

@ -11,9 +11,9 @@
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/storage": "^0.26.33",
"@polkadot/storage": "^0.26.35",
"@polkadot/ui-react": "^0.19.9",
"@polkadot/ui-react-rx": "^0.19.9",
"@polkadot/util-keyring": "^0.26.33"
"@polkadot/util-keyring": "^0.26.35"
}
}

View File

@ -16,8 +16,8 @@
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/primitives": "^0.26.33",
"@polkadot/primitives": "^0.26.35",
"@polkadot/ui-app": "^0.19.9",
"@polkadot/util-crypto": "^0.26.33"
"@polkadot/util-crypto": "^0.26.35"
}
}

View File

@ -16,7 +16,7 @@
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/extrinsics": "^0.26.33",
"@polkadot/extrinsics": "^0.26.35",
"@polkadot/ui-app": "^0.19.9",
"@polkadot/ui-signer": "^0.19.9",
"react-dropzone": "^4.2.9"

View File

@ -20,6 +20,7 @@
"@types/yargs": "^11.0.0",
"babel-plugin-module-resolver": "^3.1.1",
"chalk": "^2.4.1",
"libsodium-wrappers": "^0.7.3",
"yargs": "10.1.2"
},
"optionalDependencies": {

View File

@ -4,16 +4,31 @@
import { Generator$PkFromSeed, Generator$Match, Generator$Options } from './types';
import sodiumWasm from 'libsodium-wrappers';
import randomBytes from '@polkadot/util-crypto/random/asU8a';
import addressEncode from '@polkadot/util-keyring/address/encode';
import pairFromSeed from '@polkadot/util-crypto/nacl/keypair/fromSeed';
import calculate from './calculate';
import sodiumKeygen from './sodiumKeygen';
const tweetPkFromSeed = (seed: Uint8Array): Uint8Array =>
pairFromSeed(seed).publicKey;
export default function generator (test: Array<string>, options: Generator$Options, pkFromSeed: Generator$PkFromSeed = tweetPkFromSeed): Generator$Match {
let defaultPkFromSeed: Generator$PkFromSeed = tweetPkFromSeed;
// tslint:disable-next-line
(async () => {
try {
await sodiumWasm.ready;
defaultPkFromSeed = sodiumKeygen(sodiumWasm);
} catch (error) {
console.log(`Using NaCl bindings from 'tweet-nacl' (faster 'libsodium-wrappers' dependency not available)`);
}
})();
export default function generator (test: Array<string>, options: Generator$Options, pkFromSeed: Generator$PkFromSeed = defaultPkFromSeed): Generator$Match {
const seed = randomBytes();
const address = addressEncode(pkFromSeed(seed));
const { count, offset } = calculate(test, address, options);

View File

@ -2,23 +2,16 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import bufferToU8a from '@polkadot/util/buffer/toU8a';
import u8aToBuffer from '@polkadot/util/u8a/toBuffer';
import { Generator$PkFromSeed } from './types';
type PkSeedFn = (seed: Uint8Array) => Uint8Array;
import sodiumKeygen from './sodiumKeygen';
let pkFromSeed: PkSeedFn | undefined;
let pkFromSeed: Generator$PkFromSeed | undefined;
try {
const sodium = require('sodium');
pkFromSeed = (seed: Uint8Array): Uint8Array =>
bufferToU8a(
sodium.Key.Sign
.fromSeed(u8aToBuffer(seed))
.getPublicKey()
.baseBuffer
);
pkFromSeed = sodiumKeygen(sodium.api);
} catch (error) {
console.log(`Using NaCl bindings from 'tweet-nacl' (faster 'sodium' dependency not installed)`);
}

View File

@ -0,0 +1,17 @@
// Copyright 2017-2018 @polkadot/app-vanitygen authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { Generator$PkFromSeed } from './types';
import bufferToU8a from '@polkadot/util/buffer/toU8a';
import u8aToBuffer from '@polkadot/util/u8a/toBuffer';
export default function setupFn (sodium: any): Generator$PkFromSeed {
return (seed: Uint8Array): Uint8Array =>
bufferToU8a(
sodium.crypto_sign_seed_keypair(
u8aToBuffer(seed)
).publicKey
);
}

View File

@ -154,14 +154,16 @@ class VanityApp extends React.PureComponent<Props, State> {
return null;
}
const secs = elapsed / 1000;
return (
<div className='vanity--App-stats'>
{t('vanity.stats', {
defaultValue: 'Evaluated {{count}} keys in {{elapsed}}s ({{avg}}ms/key)',
defaultValue: 'Evaluated {{count}} keys in {{elapsed}}s ({{avg}} keys/s)',
replace: {
avg: (elapsed / keyCount).toFixed(3),
avg: (keyCount / secs).toFixed(3),
count: keyCount,
elapsed: (elapsed / 1000).toFixed(2)
elapsed: secs.toFixed(2)
}
})}
</div>
@ -211,7 +213,7 @@ class VanityApp extends React.PureComponent<Props, State> {
}
setTimeout(() => {
if (this.results.length === 5) {
if (this.results.length === 25) {
this.checkMatches();
}

View File

@ -16,8 +16,8 @@
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/extrinsics": "^0.26.33",
"@polkadot/storage": "^0.26.33",
"@polkadot/extrinsics": "^0.26.35",
"@polkadot/storage": "^0.26.35",
"@polkadot/ui-keyring": "^0.19.9",
"@polkadot/ui-react": "^0.19.9",
"@polkadot/ui-react-rx": "^0.19.9",

View File

@ -22,7 +22,7 @@
"color": "^3.0.0"
},
"devDependencies": {
"@polkadot/util-crypto": "^0.26.33",
"@polkadot/util-crypto": "^0.26.35",
"xmlserializer": "^0.6.1"
}
}

View File

@ -17,7 +17,7 @@
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/ui-react": "^0.19.9",
"@polkadot/util-keyring": "^0.26.33",
"@polkadot/util-keyring": "^0.26.35",
"store": "^2.0.12"
},
"peerDependencies": {

View File

@ -36,9 +36,9 @@
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/api-rx": "^0.14.25",
"@polkadot/extrinsics": "^0.26.33",
"@polkadot/storage": "^0.26.33"
"@polkadot/api-rx": "^0.14.26",
"@polkadot/extrinsics": "^0.26.35",
"@polkadot/storage": "^0.26.35"
},
"devDependencies": {
"babel-loader": "^8.0.0-beta.2",

View File

@ -19,7 +19,7 @@
"@polkadot/ui-identicon": "^0.19.9"
},
"devDependencies": {
"@polkadot/util-keyring": "^0.26.33",
"@polkadot/util-keyring": "^0.26.35",
"babel-loader": "^8.0.0-beta.2",
"css-loader": "0.28.9",
"empty": "^0.10.1",

View File

@ -16,7 +16,7 @@
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/extrinsics": "^0.26.33",
"@polkadot/extrinsics": "^0.26.35",
"@polkadot/ui-app": "^0.19.9",
"@polkadot/ui-keyring": "^0.19.9"
},

172
yarn.lock
View File

@ -765,50 +765,50 @@
version "1.1.0"
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.0.tgz#50c1e2260ac0ed9439a181de3725a0168d59c48a"
"@polkadot/api-format@^0.14.25":
version "0.14.25"
resolved "https://registry.yarnpkg.com/@polkadot/api-format/-/api-format-0.14.25.tgz#65ff09389342be8975b0709bfe7bbb49547fd0f9"
"@polkadot/api-format@^0.14.26":
version "0.14.26"
resolved "https://registry.yarnpkg.com/@polkadot/api-format/-/api-format-0.14.26.tgz#f9f4f693aeba6257926e261e69b55fabc3077f8f"
dependencies:
"@babel/runtime" "^7.0.0-beta.51"
"@polkadot/jsonrpc" "^0.26.33"
"@polkadot/primitives" "^0.26.33"
"@polkadot/util" "^0.26.33"
"@polkadot/util-keyring" "^0.26.33"
"@polkadot/jsonrpc" "^0.26.35"
"@polkadot/primitives" "^0.26.35"
"@polkadot/util" "^0.26.35"
"@polkadot/util-keyring" "^0.26.35"
"@polkadot/api-provider@^0.14.25":
version "0.14.25"
resolved "https://registry.yarnpkg.com/@polkadot/api-provider/-/api-provider-0.14.25.tgz#6dc787cd0c067c3d509526716c84c285ee9b9a6a"
"@polkadot/api-provider@^0.14.26":
version "0.14.26"
resolved "https://registry.yarnpkg.com/@polkadot/api-provider/-/api-provider-0.14.26.tgz#d9869ba02df2b88b79e15c1c84ab60ac1fb4e417"
dependencies:
"@babel/runtime" "^7.0.0-beta.51"
"@polkadot/storage" "^0.26.33"
"@polkadot/util" "^0.26.33"
"@polkadot/util-crypto" "^0.26.33"
"@polkadot/util-keyring" "^0.26.33"
"@polkadot/storage" "^0.26.35"
"@polkadot/util" "^0.26.35"
"@polkadot/util-crypto" "^0.26.35"
"@polkadot/util-keyring" "^0.26.35"
"@types/nock" "^9.1.3"
eventemitter3 "^2.0.3"
isomorphic-fetch "^2.2.1"
websocket "^1.0.25"
"@polkadot/api-rx@^0.14.25":
version "0.14.25"
resolved "https://registry.yarnpkg.com/@polkadot/api-rx/-/api-rx-0.14.25.tgz#c464540851f9a981592739b3269cbc9012ef50c3"
"@polkadot/api-rx@^0.14.26":
version "0.14.26"
resolved "https://registry.yarnpkg.com/@polkadot/api-rx/-/api-rx-0.14.26.tgz#4ababa7e55f30dd72658cbfea0f343ab9cdf1229"
dependencies:
"@babel/runtime" "^7.0.0-beta.51"
"@polkadot/api" "^0.14.25"
"@polkadot/api-provider" "^0.14.25"
"@polkadot/api" "^0.14.26"
"@polkadot/api-provider" "^0.14.26"
"@types/rx" "^4.1.1"
rxjs "^5.5.10"
"@polkadot/api@^0.14.25":
version "0.14.25"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.14.25.tgz#cfb4791a2306d693cc48d76e19f1beab43f30156"
"@polkadot/api@^0.14.26":
version "0.14.26"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.14.26.tgz#e040e62eb4677868ab344597cc8fa55890a52b92"
dependencies:
"@babel/runtime" "^7.0.0-beta.51"
"@polkadot/api-format" "^0.14.25"
"@polkadot/api-provider" "^0.14.25"
"@polkadot/jsonrpc" "^0.26.33"
"@polkadot/params" "^0.26.33"
"@polkadot/util" "^0.26.33"
"@polkadot/api-format" "^0.14.26"
"@polkadot/api-provider" "^0.14.26"
"@polkadot/jsonrpc" "^0.26.35"
"@polkadot/params" "^0.26.35"
"@polkadot/util" "^0.26.35"
"@polkadot/dev-react@^0.20.12":
version "0.20.12"
@ -877,94 +877,94 @@
typedoc "^0.11.1"
typescript "^2.9.2"
"@polkadot/extrinsics@^0.26.33":
version "0.26.33"
resolved "https://registry.yarnpkg.com/@polkadot/extrinsics/-/extrinsics-0.26.33.tgz#afb5a3ed880d90d07a41d7ab1b770c4eee3771e4"
"@polkadot/extrinsics@^0.26.35":
version "0.26.35"
resolved "https://registry.yarnpkg.com/@polkadot/extrinsics/-/extrinsics-0.26.35.tgz#cc9b14f1f421f00ea4fde251ff023dd225e7dad7"
dependencies:
"@babel/runtime" "^7.0.0-beta.51"
"@polkadot/params" "^0.26.33"
"@polkadot/primitives" "^0.26.33"
"@polkadot/util" "^0.26.33"
"@polkadot/params" "^0.26.35"
"@polkadot/primitives" "^0.26.35"
"@polkadot/util" "^0.26.35"
"@polkadot/jsonrpc@^0.26.33":
version "0.26.33"
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.26.33.tgz#ad1c7802328ccf45ddda3df7c8262bb71d70ac6b"
"@polkadot/jsonrpc@^0.26.35":
version "0.26.35"
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.26.35.tgz#87db53388ea9ee6fc165c5730742cad06e692668"
dependencies:
"@polkadot/params" "^0.26.33"
"@polkadot/params" "^0.26.35"
babel-runtime "^6.26.0"
"@polkadot/params@^0.26.33":
version "0.26.33"
resolved "https://registry.yarnpkg.com/@polkadot/params/-/params-0.26.33.tgz#f04e030e6431dd18344c564c62fa7eb3120d2855"
"@polkadot/params@^0.26.35":
version "0.26.35"
resolved "https://registry.yarnpkg.com/@polkadot/params/-/params-0.26.35.tgz#92df414f862f8bfd18b551a21eff5e996c3c1eca"
dependencies:
"@babel/runtime" "^7.0.0-beta.51"
"@polkadot/extrinsics" "^0.26.33"
"@polkadot/primitives" "^0.26.33"
"@polkadot/util" "^0.26.33"
"@polkadot/extrinsics" "^0.26.35"
"@polkadot/primitives" "^0.26.35"
"@polkadot/util" "^0.26.35"
"@polkadot/primitives@^0.26.33":
version "0.26.33"
resolved "https://registry.yarnpkg.com/@polkadot/primitives/-/primitives-0.26.33.tgz#32caec98d3a711f24014bd9ff3e38e1117de2c32"
"@polkadot/primitives@^0.26.35":
version "0.26.35"
resolved "https://registry.yarnpkg.com/@polkadot/primitives/-/primitives-0.26.35.tgz#03cf35b8765081b3988153c45d27762db0900011"
dependencies:
"@babel/runtime" "^7.0.0-beta.51"
"@polkadot/trie-hash" "^0.26.33"
"@polkadot/util" "^0.26.33"
"@polkadot/trie-hash" "^0.26.35"
"@polkadot/util" "^0.26.35"
"@polkadot/storage@^0.26.33":
version "0.26.33"
resolved "https://registry.yarnpkg.com/@polkadot/storage/-/storage-0.26.33.tgz#adc05617d2c53a402ff8f5241de1b0c81cf1b5f7"
"@polkadot/storage@^0.26.35":
version "0.26.35"
resolved "https://registry.yarnpkg.com/@polkadot/storage/-/storage-0.26.35.tgz#2d4e3aac47612b0319c0c69f369974266d1c1d04"
dependencies:
"@babel/runtime" "^7.0.0-beta.51"
"@polkadot/params" "^0.26.33"
"@polkadot/primitives" "^0.26.33"
"@polkadot/util" "^0.26.33"
"@polkadot/util-crypto" "^0.26.33"
"@polkadot/util-keyring" "^0.26.33"
"@polkadot/params" "^0.26.35"
"@polkadot/primitives" "^0.26.35"
"@polkadot/util" "^0.26.35"
"@polkadot/util-crypto" "^0.26.35"
"@polkadot/util-keyring" "^0.26.35"
"@polkadot/trie-hash@^0.26.33":
version "0.26.33"
resolved "https://registry.yarnpkg.com/@polkadot/trie-hash/-/trie-hash-0.26.33.tgz#5bc89557ea26d775583cb30b8be6e827dd65ea5e"
"@polkadot/trie-hash@^0.26.35":
version "0.26.35"
resolved "https://registry.yarnpkg.com/@polkadot/trie-hash/-/trie-hash-0.26.35.tgz#632ba48fca8c82a0c4f4af8887b275d7b46045cc"
dependencies:
"@babel/runtime" "^7.0.0-beta.51"
"@polkadot/util" "^0.26.33"
"@polkadot/util-crypto" "^0.26.33"
"@polkadot/util-rlp" "^0.26.33"
"@polkadot/util" "^0.26.35"
"@polkadot/util-crypto" "^0.26.35"
"@polkadot/util-rlp" "^0.26.35"
"@polkadot/ts@^0.1.9":
version "0.1.9"
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.9.tgz#86010c5a4d63c0fb6b3e85d29db40dcf43c5d7c1"
"@polkadot/ts@^0.1.10":
version "0.1.10"
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.10.tgz#784d460cf4b2e9b38bb1c77f9366dd01425f220d"
"@polkadot/util-crypto@^0.26.33":
version "0.26.33"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.26.33.tgz#f447880d3793922d9ec8bf4a5d1b2a832a088093"
"@polkadot/util-crypto@^0.26.35":
version "0.26.35"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.26.35.tgz#74948946cc266d228b4636953c16c96e99626090"
dependencies:
"@babel/runtime" "^7.0.0-beta.51"
"@polkadot/util" "^0.26.33"
"@polkadot/util" "^0.26.35"
blakejs "^1.1.0"
js-sha3 "^0.7.0"
tweetnacl "^1.0.0"
xxhashjs "^0.2.2"
"@polkadot/util-keyring@^0.26.33":
version "0.26.33"
resolved "https://registry.yarnpkg.com/@polkadot/util-keyring/-/util-keyring-0.26.33.tgz#e6407e75a821a0e5616ad9c7895c471f83e75e3f"
"@polkadot/util-keyring@^0.26.35":
version "0.26.35"
resolved "https://registry.yarnpkg.com/@polkadot/util-keyring/-/util-keyring-0.26.35.tgz#266002c6591665cf8a7df6c5ad3ed840f8b400a5"
dependencies:
"@babel/runtime" "^7.0.0-beta.51"
"@polkadot/util" "^0.26.33"
"@polkadot/util-crypto" "^0.26.33"
"@polkadot/util" "^0.26.35"
"@polkadot/util-crypto" "^0.26.35"
"@types/bs58" "^3.0.30"
bs58 "^4.0.1"
"@polkadot/util-rlp@^0.26.33":
version "0.26.33"
resolved "https://registry.yarnpkg.com/@polkadot/util-rlp/-/util-rlp-0.26.33.tgz#9af719a3bbcc2d64b166850b8b2d0a361fcaba55"
"@polkadot/util-rlp@^0.26.35":
version "0.26.35"
resolved "https://registry.yarnpkg.com/@polkadot/util-rlp/-/util-rlp-0.26.35.tgz#f6e4d01a6f87a7882ba5b4d9bc819365d1d138b8"
dependencies:
"@babel/runtime" "^7.0.0-beta.51"
"@polkadot/util" "^0.26.33"
"@polkadot/util" "^0.26.35"
"@polkadot/util@^0.26.33":
version "0.26.33"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.26.33.tgz#41497f90e1c8b6335b88bb06a58dc8dee82b2cef"
"@polkadot/util@^0.26.35":
version "0.26.35"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.26.35.tgz#c63d8f14a5eadb668f00ca09ee40862c87b53e2e"
dependencies:
"@babel/runtime" "^7.0.0-beta.51"
"@types/bn.js" "^4.11.1"
@ -6936,6 +6936,16 @@ levn@^0.3.0, levn@~0.3.0:
prelude-ls "~1.1.2"
type-check "~0.3.2"
libsodium-wrappers@^0.7.3:
version "0.7.3"
resolved "https://registry.yarnpkg.com/libsodium-wrappers/-/libsodium-wrappers-0.7.3.tgz#b7e6326a5c42eb269540e360ce9c2600eb90c75c"
dependencies:
libsodium "0.7.3"
libsodium@0.7.3:
version "0.7.3"
resolved "https://registry.yarnpkg.com/libsodium/-/libsodium-0.7.3.tgz#35faf57293ba5485049d5072d0e96feda12f1f35"
linkify-it@^2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/linkify-it/-/linkify-it-2.0.3.tgz#d94a4648f9b1c179d64fa97291268bdb6ce9434f"