refactor: Extension of #231. Destructuring to combine imports (#237)

* refactor: Destructure imports together from same source in example util-crypto 01

* refactor: Destructure imports together example util-crypto 02. Avoid using default import. Show data to user

* refactor: Destructure imports together example util-crypto 03. Show data to user

* refactor: Split import over two lines looks cleaner

* fix: Address review comments. Update dependencies in examples
This commit is contained in:
Luke Schoen
2018-11-14 13:26:53 +01:00
committed by Jaco Greeff
parent 5c1df7214e
commit 48008e2cc8
14 changed files with 26 additions and 32 deletions
@@ -10,8 +10,8 @@
"start": "node index.js"
},
"dependencies": {
"@polkadot/util": "^0.32.2",
"@polkadot/keyring": "^0.32.1"
"@polkadot/util": "^0.32.10",
"@polkadot/keyring": "^0.32.10"
},
"devDependencies": {
"rimraf": "^2.6.2"
@@ -23,7 +23,7 @@ async function main () {
.forEach((pair, index) => {
const address = pair.address();
console.log(`${index} account has json: `,
console.log(`\nAccount with index #${index} has json: `,
JSON.stringify(keyring.toJson(address), null, 2));
});
}
@@ -10,8 +10,8 @@
"start": "node index.js"
},
"dependencies": {
"@polkadot/util": "^0.32.2",
"@polkadot/keyring": "^0.32.1"
"@polkadot/util": "^0.32.10",
"@polkadot/keyring": "^0.32.10"
},
"devDependencies": {
"rimraf": "^2.6.2"
@@ -10,8 +10,8 @@
"start": "node index.js"
},
"dependencies": {
"@polkadot/trie-db": "^0.32.1",
"@polkadot/db": "^0.32.2"
"@polkadot/trie-db": "^0.32.10",
"@polkadot/db": "^0.32.10"
},
"devDependencies": {
"rimraf": "^2.6.2"
@@ -10,8 +10,8 @@
"start": "node index.js"
},
"dependencies": {
"@polkadot/trie-db": "^0.32.1",
"@polkadot/db": "^0.32.2"
"@polkadot/trie-db": "^0.32.10",
"@polkadot/db": "^0.32.10"
},
"devDependencies": {
"rimraf": "^2.6.2"
@@ -10,8 +10,8 @@
"start": "node index.js"
},
"dependencies": {
"@polkadot/trie-db": "^0.32.1",
"@polkadot/db": "^0.32.2"
"@polkadot/trie-db": "^0.32.10",
"@polkadot/db": "^0.32.10"
},
"devDependencies": {
"rimraf": "^2.6.2"
@@ -10,8 +10,8 @@
"start": "node index.js"
},
"dependencies": {
"@polkadot/trie-db": "^0.32.1",
"@polkadot/db": "^0.32.2"
"@polkadot/trie-db": "^0.32.10",
"@polkadot/db": "^0.32.10"
},
"devDependencies": {
"rimraf": "^2.6.2"
@@ -10,8 +10,8 @@
"start": "node index.js"
},
"dependencies": {
"@polkadot/trie-db": "^0.32.1",
"@polkadot/db": "^0.32.2"
"@polkadot/trie-db": "^0.32.10",
"@polkadot/db": "^0.32.10"
},
"devDependencies": {
"rimraf": "^2.6.2"
@@ -1,5 +1,4 @@
const { naclEncrypt } = require('@polkadot/util-crypto');
const { naclDecrypt } = require('@polkadot/util-crypto');
const { naclEncrypt, naclDecrypt } = require('@polkadot/util-crypto');
async function main () {
const secret = new Uint8Array(32);
@@ -10,7 +10,7 @@
"start": "node index.js"
},
"dependencies": {
"@polkadot/util-crypto": "^0.32.2"
"@polkadot/util-crypto": "^0.32.10"
},
"devDependencies": {
"rimraf": "^2.6.2"
@@ -1,10 +1,5 @@
const stringToU8a = require('@polkadot/util/string/toU8a').default;
const { randomAsU8a } = require('@polkadot/util-crypto');
const { naclKeypairFromSeed } = require('@polkadot/util-crypto');
const { naclEncrypt } = require('@polkadot/util-crypto');
const { naclSign } = require('@polkadot/util-crypto');
const { naclVerify } = require('@polkadot/util-crypto');
const { stringToU8a, u8aToHex } = require('@polkadot/util');
const { naclEncrypt, naclKeypairFromSeed, naclSign, naclVerify, randomAsU8a } = require('@polkadot/util-crypto');
async function main () {
// Create account seed for Alice as fallback if generated mnemonic not valid
@@ -23,6 +18,8 @@ async function main () {
// Sign the message with a valid signature
const messageSignature = naclSign(encrypted, secretKey);
console.log(`Message signature: ${u8aToHex(messageSignature)}`);
// Validate that the message was correctly signed
const isValidSignature = naclVerify(encrypted, messageSignature, publicKey);
@@ -10,7 +10,7 @@
"start": "node index.js"
},
"dependencies": {
"@polkadot/util-crypto": "^0.32.2"
"@polkadot/util-crypto": "^0.32.10"
},
"devDependencies": {
"rimraf": "^2.6.2"
@@ -1,13 +1,11 @@
const { mnemonicGenerate } = require('@polkadot/util-crypto');
const { mnemonicToSeed } = require('@polkadot/util-crypto');
const { mnemonicValidate } = require('@polkadot/util-crypto');
const { toSecret } = require('@polkadot/util-crypto');
const { naclKeypairFromSeed } = require('@polkadot/util-crypto');
const { mnemonicGenerate, mnemonicToSeed, mnemonicValidate, naclKeypairFromSeed } = require('@polkadot/util-crypto');
async function main () {
// Create mnemonic string for Alice using BIP39
const mnemonicAlice = mnemonicGenerate();
console.log(`Generated mnemonic: ${mnemonicAlice}`);
// Validate the mnemic string that was generated
const isValidMnemonic = mnemonicValidate(mnemonicAlice);
@@ -10,7 +10,7 @@
"start": "node index.js"
},
"dependencies": {
"@polkadot/util-crypto": "^0.32.2"
"@polkadot/util-crypto": "^0.32.10"
},
"devDependencies": {
"rimraf": "^2.6.2"