1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-22 01:36:56 +01:00

example seed-func ready

This commit is contained in:
Michiel Mulders 2018-01-20 16:41:05 +01:00
parent 10fab5323a
commit 01deae78cd
3 changed files with 48 additions and 3 deletions

View File

@ -1,2 +1,10 @@
# Usage
`npm install`
`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`

View File

@ -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"
}
}

View File

@ -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