diff --git a/packages/iov-keycontrol/README.md b/packages/iov-cli/README.md similarity index 71% rename from packages/iov-keycontrol/README.md rename to packages/iov-cli/README.md index ac477e200..4457f54a7 100644 --- a/packages/iov-keycontrol/README.md +++ b/packages/iov-cli/README.md @@ -1,15 +1,13 @@ -@iov/keycontrol -=============== +How to use the web4 cli +======================= ## Example usage -1. Navigate into a directory where @iov/keycontrol is installed - (e.g `cd web4 && yarn install && yarn build`) -2. Run `node` in interactive mode +1. Build all dependencies: `cd web4 && yarn install && yarn build` +2. Go to `packages/iov-cli`, run `yarn web4` and follow on-screen instructions 3. Play around like in the following example code: ``` -> const { Ed25519SimpleAddressKeyringEntry, Keyring, UserProfile } = require("@iov/keycontrol") > const profile = new UserProfile(); > profile.addEntry(Ed25519SimpleAddressKeyringEntry.fromMnemonic("melt wisdom mesh wash item catalog talk enjoy gaze hat brush wash")) @@ -37,11 +35,22 @@ [ { pubkey: { algo: 'ed25519', data: [Object] }, label: 'the first one' } ] -> const Long = require("long") -> const fakeTransaction = { } -> const fakeCodec = { bytesToSign: () => { return new Uint8Array([0x00, 0x11, 0x22]); }, } -> const nonce = new Long(0x11223344, 0x55667788) -> profile.signTransaction(0, mainIdentity, fakeTransaction, fakeCodec, nonce).then(signed => console.log(signed)) +> .editor +const sendTx: SendTx = { + kind: TransactionKind.SEND, + chainId: "aabb" as ChainId, + signer: mainIdentity.pubkey, + recipient: new Uint8Array([0x11]) as AddressBytes, + memo: "Web4 write style", + amount: { + whole: 11000, + fractional: 777, + tokenTicker: "CASH" as TokenTicker, + }, +}; +^D +> const nonce = new Long(0x11223344, 0x55667788) as Nonce; +> profile.signTransaction(0, mainIdentity, sendTx, bnsCodec, nonce).then(signed => console.log(signed)) ``` 4. Congratulations, you created the first signed transaction! @@ -76,8 +85,6 @@ 6. Now store to disk ``` -> const leveldown = require('leveldown') -> const levelup = require('levelup') > const db = levelup(leveldown('./my_userprofile_db')) > profile.storeIn(db, "secret passwd") ``` diff --git a/packages/iov-cli/init b/packages/iov-cli/init new file mode 100644 index 000000000..3d32e5510 --- /dev/null +++ b/packages/iov-cli/init @@ -0,0 +1,28 @@ +import colors = require('colors/safe'); +const leveldown = require('leveldown') +const levelup = require('levelup') +import Long from "long"; +import { bnsCodec } from "@iov/bns"; +import { Encoding } from '@iov/encoding'; +import { Ed25519SimpleAddressKeyringEntry, UserProfile } from '@iov/keycontrol'; +import { AddressBytes, ChainId, Nonce, SendTx, TokenTicker, TransactionKind } from "@iov/types"; +console.log(colors.green('Done initializing session for you. Have fun!')); +console.log(colors.yellow('Available imports:')); +console.log(colors.yellow(' * leveldown')); +console.log(colors.yellow(' * levelup')); +console.log(colors.yellow(' * from long')); +console.log(colors.yellow(' - Long')); +console.log(colors.yellow(' * from @iov/bns')); +console.log(colors.yellow(' - bnsCodec')); +console.log(colors.yellow(' * from @iov/encoding')); +console.log(colors.yellow(' - Encoding')); +console.log(colors.yellow(' * from @iov/keycontrol')); +console.log(colors.yellow(' - Ed25519SimpleAddressKeyringEntry')); +console.log(colors.yellow(' - UserProfile')); +console.log(colors.yellow(' * from @iov/types')); +console.log(colors.yellow(' - AddressBytes')); +console.log(colors.yellow(' - ChainId')); +console.log(colors.yellow(' - Nonce')); +console.log(colors.yellow(' - SendTx')); +console.log(colors.yellow(' - TokenTicker')); +console.log(colors.yellow(' - TransactionKind')); diff --git a/packages/iov-cli/package.json b/packages/iov-cli/package.json new file mode 100644 index 000000000..e6a053412 --- /dev/null +++ b/packages/iov-cli/package.json @@ -0,0 +1,18 @@ +{ + "name": "@iov/cli", + "version": "0.0.0", + "description": "Command line interface for web4", + "author": "simon ", + "license": "AGPL-3.0", + "repository": { + "type": "git", + "url": "https://github.com/iov-one/web4/tree/master/packages/iov-cli" + }, + "scripts": { + "web4": "echo '\\nTo get started type: .load init\\n' && ts-node" + }, + "dependencies": { + "colors": "^1.3.0", + "ts-node": "^7.0.0" + } +} diff --git a/packages/iov-cli/tsconfig.json b/packages/iov-cli/tsconfig.json new file mode 100644 index 000000000..a4457b071 --- /dev/null +++ b/packages/iov-cli/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "noUnusedLocals": false, + } +} diff --git a/yarn.lock b/yarn.lock index 1dc11f36c..a76516f48 100644 --- a/yarn.lock +++ b/yarn.lock @@ -494,7 +494,7 @@ arraybuffer.slice@~0.0.7: version "0.0.7" resolved "https://registry.yarnpkg.com/arraybuffer.slice/-/arraybuffer.slice-0.0.7.tgz#3bbc4275dd584cc1b10809b89d4e8b63a69e7675" -arrify@^1.0.1: +arrify@^1.0.0, arrify@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d" @@ -833,7 +833,7 @@ buffer-fill@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/buffer-fill/-/buffer-fill-1.0.0.tgz#f8f78b76789888ef39f205cd637f68e702122b2c" -buffer-from@^1.0.0: +buffer-from@^1.0.0, buffer-from@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.0.tgz#87fcaa3a298358e0ade6e442cfce840740d1ad04" @@ -1119,7 +1119,7 @@ color-name@1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.1.tgz#4b1415304cf50028ea81643643bd82ea05803689" -colors@^1.1.0: +colors@^1.1.0, colors@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/colors/-/colors-1.3.0.tgz#5f20c9fef6945cb1134260aab33bfbdc8295e04e" @@ -1690,7 +1690,7 @@ di@^0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/di/-/di-0.0.1.tgz#806649326ceaa7caa3306d75d985ea2748ba913c" -diff@^3.2.0: +diff@^3.1.0, diff@^3.2.0: version "3.5.0" resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12" @@ -3658,6 +3658,10 @@ make-dir@^1.0.0: dependencies: pify "^3.0.0" +make-error@^1.1.1: + version "1.3.4" + resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.4.tgz#19978ed575f9e9545d2ff8c13e33b5d18a67d535" + mamacro@^0.0.3: version "0.0.3" resolved "https://registry.yarnpkg.com/mamacro/-/mamacro-0.0.3.tgz#ad2c9576197c9f1abf308d0787865bd975a3f3e4" @@ -5297,11 +5301,18 @@ source-map-resolve@^0.5.0: source-map-url "^0.4.0" urix "^0.1.0" +source-map-support@^0.5.6: + version "0.5.6" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.6.tgz#4435cee46b1aab62b8e8610ce60f788091c51c13" + dependencies: + buffer-from "^1.0.0" + source-map "^0.6.0" + source-map-url@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3" -source-map@0.6.1, source-map@^0.6.1, source-map@~0.6.1: +source-map@0.6.1, source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" @@ -5727,6 +5738,19 @@ trim-off-newlines@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3" +ts-node@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-7.0.0.tgz#a94a13c75e5e1aa6b82814b84c68deb339ba7bff" + dependencies: + arrify "^1.0.0" + buffer-from "^1.1.0" + diff "^3.1.0" + make-error "^1.1.1" + minimist "^1.2.0" + mkdirp "^0.5.1" + source-map-support "^0.5.6" + yn "^2.0.0" + tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0: version "1.9.3" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286" @@ -6311,3 +6335,7 @@ yargs@~3.10.0: yeast@0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419" + +yn@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/yn/-/yn-2.0.0.tgz#e5adabc8acf408f6385fc76495684c88e6af689a"