diff --git a/examples/basic-usage-boilerplate/README.md b/examples/basic-usage-boilerplate/README.md index 55f98e5..21be56d 100644 --- a/examples/basic-usage-boilerplate/README.md +++ b/examples/basic-usage-boilerplate/README.md @@ -1,2 +1,10 @@ # Usage -`npm install` \ No newline at end of file +`npm install` -> Installs all required dependencies to run these examples. + +## Different Examples +**Basic Usage**: Create asset and transfer it to new owner. +-> `npm start` + +**Querying for Assets**: Query for assetdata or metadata. +-> `npm run query-assets` + diff --git a/examples/basic-usage-boilerplate/package.json b/examples/basic-usage-boilerplate/package.json index a309435..a3576c8 100644 --- a/examples/basic-usage-boilerplate/package.json +++ b/examples/basic-usage-boilerplate/package.json @@ -7,7 +7,9 @@ "serve": "node dist/basic-usage.js", "clean": "rimraf ./dist", "start": "nodemon src/basic-usage.js --exec babel-node", - "query-assets": "nodemon src/query-assets.js --exec babel-node" + "query-assets": "nodemon src/query-assets.js --exec babel-node", + "seed-func": "nodemon src/seed-func.js --exec babel-node", + "websocket": "nodemon src/websocket.js --exec babel-node" }, "author": "BigchainDB", "license": "MIT", @@ -27,6 +29,7 @@ "repository": "/", "private": true, "dependencies": { - "bigchaindb-driver": "^3.2.0" + "bigchaindb-driver": "^3.2.0", + "bip39": "^2.5.0" } } diff --git a/examples/basic-usage-boilerplate/src/seed-func.js b/examples/basic-usage-boilerplate/src/seed-func.js new file mode 100644 index 0000000..a8b89fb --- /dev/null +++ b/examples/basic-usage-boilerplate/src/seed-func.js @@ -0,0 +1,34 @@ +import bip39 from 'bip39' + +const driver = require('bigchaindb-driver') + +// ======== Create Keypair ======== // +/** + * Use a passphrase to derive a keypair + * If you use the same seed -> you will derive the same keypair + * + * mnemnoicToSeed() transforms the passphrase you gave as an input + * to a byteArray + * + * BigchainDB however only accepts an input length of 32 characters + * so we have to slice this to give it as input for driver.Ed25519Keypair() + * + * Is it safe to slice? Yes, a seed of length 32 is very safe according + * to related papers discussing this. + */ +const passphrase = 'This is a random passphrase' +const seed = bip39.mnemonicToSeed(passphrase).slice(0, 32) + +const keypair = new driver.Ed25519Keypair(seed) + +console.log(`Public Key: ${keypair.publicKey} - Private Key: ${keypair.privateKey}`) // eslint-disable-line no-console + +// ======== Other Bip39 Functionality not related to BigchainDB ======== // + +/* Create Random passphrase */ +const mnemonic = bip39.generateMnemonic() +console.log('Random passphrase: ', mnemonic) // eslint-disable-line no-console + +/* Validate mnemnoic */ +console.log(bip39.validateMnemonic(mnemonic)) // eslint-disable-line no-console +console.log(bip39.validateMnemonic('some random strings together but to short')) // eslint-disable-line no-console