From 5fe96f60fa8433e5b333a904890123840751c37e Mon Sep 17 00:00:00 2001 From: Cody Douglass Date: Thu, 29 Nov 2018 16:31:44 -0500 Subject: [PATCH 1/7] README reorganization first draft --- README.md | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 5eacece04..9060953d4 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,17 @@ Documentation can be found [here](https://eosio.github.io/eosjs) ## Installation -### NodeJS +### NodeJS Dependency -`npm install eosjs@beta` +`npm install eosjs@beta` or `yarn add eosjs@beta` -## Basic Usage +### Browser Distribution + +Clone this repository locally then run `npm run build-web` or `yarn build-web`. The browser distribution will be located in `dist` and can be directly copied into your project repository. For full browser usage examples, [see the documentation](https://eosio.github.io/eosjs/static/3.-Browsers.html). -### Browser +## Import + +### ES Modules Importing using ES6 module syntax in the browser is supported if you have a transpiler, such as Babel. ```js @@ -26,20 +30,22 @@ import { Api, JsonRpc, RpcError } from 'eosjs'; import JsSignatureProvider from 'eosjs/dist/eosjs-jssig' ``` -### NodeJS +### CommonJS -Importing using commonJS syntax is supported by node out of the box. +Importing using commonJS syntax is supported by NodeJS out of the box. ```js const { Api, JsonRpc, RpcError } = require('eosjs'); const JsSignatureProvider = require('eosjs/dist/eosjs-jssig'); const fetch = require('node-fetch'); // node only; not needed in browsers +const { TextEncoder, TextDecoder } = require('util') // node only; native TextEncoder/Decoder const { TextDecoder, TextEncoder } = require('text-encoding'); // IE11 and IE Edge Browsers only -const {TextEncoder,TextDecoder} = require('util') // node only; native TextEncoder/Decoder ``` +## Basic Usage + ### SignatureProvider -SignatureProvider holds private keys and is responsible for signing transactions. +The SignatureProvider holds private keys and is responsible for signing transactions. ***Using the default JsSignatureProvider in the browser is not secure and should only be used for development purposes. Use a secure vault outside of the context of the webpage to ensure security when signing transactions in production*** @@ -55,7 +61,7 @@ Open a connection to JSON-RPC, include `fetch` when on NodeJS. const rpc = new JsonRpc('http://127.0.0.1:8000', { fetch }); ``` -### API Constructor +### API Include textDecoder and textEncoder when using in browser. ```js @@ -64,6 +70,8 @@ const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), te ### Sending a transaction +`transact()` is used to sign and push transactions onto the blockchain with an optional configuration object parameter. This parameter can override the default value of `broadcast: true`, and can be used to fill TAPOS fields given `blocksBehind` and `expireSeconds`. Given no configuration options, transactions are expected to be unpacked with TAPOS fields (`expiration`, `ref_block_num`, `ref_block_prefix`) and will automatically be broadcast onto the chain. + ```js (async () => { const result = await api.transact({ @@ -105,15 +113,6 @@ try { ... ``` -## Browsers - -After running `npm run build-web` or `yarn build-web`, the browser distribution will be located in `dist`. For full browser usage examples, [see the documentation](https://eosio.github.io/eosjs/static/3.-Browsers.html). - -## How it works - -`transact()` is used to sign and push transactions onto the blockchain with an optional configuration object parameter. This parameter can override the default value of `broadcast: true`, and can be used to fill TAPOS fields given `blocksBehind` and `expireSeconds`. Given no configuration options, transactions are expected to be unpacked with TAPOS fields (`expiration`, `ref_block_num`, `ref_block_prefix`) and will automatically be broadcast onto the chain. - - ## Running Tests ### Automated Test Suite From 068b7099f99dd4cf6a51521d6971356e57178323 Mon Sep 17 00:00:00 2001 From: Cody Douglass Date: Fri, 30 Nov 2018 11:39:21 -0500 Subject: [PATCH 2/7] add back integration tests and update readme --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9060953d4..1abc0f0ae 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Importing using ES6 module syntax in the browser is supported if you have a tran import { Api, JsonRpc, RpcError } from 'eosjs'; // If using default signature provider -import JsSignatureProvider from 'eosjs/dist/eosjs-jssig' +import JsSignatureProvider from 'eosjs/dist/eosjs-jssig'; ``` ### CommonJS @@ -37,8 +37,8 @@ Importing using commonJS syntax is supported by NodeJS out of the box. const { Api, JsonRpc, RpcError } = require('eosjs'); const JsSignatureProvider = require('eosjs/dist/eosjs-jssig'); const fetch = require('node-fetch'); // node only; not needed in browsers -const { TextEncoder, TextDecoder } = require('util') // node only; native TextEncoder/Decoder -const { TextDecoder, TextEncoder } = require('text-encoding'); // IE11 and IE Edge Browsers only +const { TextEncoder, TextDecoder } = require('util'); // node only; native TextEncoder/Decoder +const { TextEncoder, TextDecoder } = require('text-encoding'); // React Native, IE11, and Edge Browsers only ``` ## Basic Usage @@ -117,3 +117,6 @@ try { ### Automated Test Suite `npm run test` or `yarn test` + +### Integration Test Suite +Run `npm run build-web` to build the browser distrubution then open `test.html` in the browser of your choice. The file should run through 5 tests, relaying the results onto the webpage with a 2 second delay after each test. The final test should throw an exception as it is missing the TAPOS fields and the config parameter. From 9ab7cf88759c5e71fc953558135eb372cf14575d Mon Sep 17 00:00:00 2001 From: Cody Douglass Date: Mon, 3 Dec 2018 17:33:30 -0500 Subject: [PATCH 3/7] adding back web integration tests --- README.md | 10 +-- src/rpc-web.ts | 4 ++ src/tests/web.html | 151 +++++++++++++++++++++++++++++++++++++++++++++ webpack.config.js | 3 +- 4 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 src/rpc-web.ts create mode 100644 src/tests/web.html diff --git a/README.md b/README.md index 1abc0f0ae..b438bdff2 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Documentation can be found [here](https://eosio.github.io/eosjs) ### Browser Distribution -Clone this repository locally then run `npm run build-web` or `yarn build-web`. The browser distribution will be located in `dist` and can be directly copied into your project repository. For full browser usage examples, [see the documentation](https://eosio.github.io/eosjs/static/3.-Browsers.html). +Clone this repository locally then run `npm run build-web` or `yarn build-web`. The browser distribution will be located in `dist-web` and can be directly copied into your project repository. For full browser usage examples, [see the documentation](https://eosio.github.io/eosjs/static/3.-Browsers.html). ## Import @@ -58,7 +58,7 @@ const signatureProvider = new JsSignatureProvider([defaultPrivateKey]); Open a connection to JSON-RPC, include `fetch` when on NodeJS. ```js -const rpc = new JsonRpc('http://127.0.0.1:8000', { fetch }); +const rpc = new JsonRpc('http://127.0.0.1:8888', { fetch }); ``` ### API @@ -115,8 +115,8 @@ try { ## Running Tests -### Automated Test Suite +### Automated Unit Test Suite `npm run test` or `yarn test` -### Integration Test Suite -Run `npm run build-web` to build the browser distrubution then open `test.html` in the browser of your choice. The file should run through 5 tests, relaying the results onto the webpage with a 2 second delay after each test. The final test should throw an exception as it is missing the TAPOS fields and the config parameter. +### Web Integration Test Suite +Run `npm run build-web` to build the browser distrubution then open `src/tests/web.html` in the browser of your choice. The file should run through 6 tests, relaying the results onto the webpage with a 2 second delay after each test. The final 2 tests should relay the exceptions being thrown onto the webpage for an invalid transaction and invalid rpc call. diff --git a/src/rpc-web.ts b/src/rpc-web.ts new file mode 100644 index 000000000..63122257b --- /dev/null +++ b/src/rpc-web.ts @@ -0,0 +1,4 @@ +import JsonRpc from "./eosjs-jsonrpc"; +import RpcError from "./eosjs-rpcerror"; + +export { JsonRpc as default, RpcError }; diff --git a/src/tests/web.html b/src/tests/web.html new file mode 100644 index 000000000..95dde106c --- /dev/null +++ b/src/tests/web.html @@ -0,0 +1,151 @@ +

+
+
+
+
+
diff --git a/webpack.config.js b/webpack.config.js
index ba682afb8..e597f02f1 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -3,8 +3,7 @@ const path = require('path');
 module.exports = {
     entry: {
         eosjs_api: './src/eosjs-api.ts',
-        eosjs_jsonrpc: './src/eosjs-jsonrpc.ts',
-        eosjs_rpcerror: './src/eosjs-rpcerror.ts',
+        eosjs_jsonrpc: './src/rpc-web.ts',
         eosjs_jssig: './src/eosjs-jssig.ts',
     },
     devtool: 'inline-source-map',

From 1f6d951f5235d545f4d9181403e81e86a319d7bd Mon Sep 17 00:00:00 2001
From: Cody Douglass 
Date: Tue, 4 Dec 2018 10:50:43 -0500
Subject: [PATCH 4/7] making debug and production files for web build process

---
 package.json                          |    2 +-
 src/tests/web.html                    |    6 +-
 webpack.config.js => webpack.debug.js |    4 -
 webpack.prod.js                       |   31 +
 yarn.lock                             | 2207 ++++++++-----------------
 5 files changed, 735 insertions(+), 1515 deletions(-)
 rename webpack.config.js => webpack.debug.js (92%)
 create mode 100644 webpack.prod.js

diff --git a/package.json b/package.json
index c2ae55dd8..866c15836 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,7 @@
     "lint": "tslint -c tslint.json src/**/*.ts",
     "lint-fix": "tslint -c tslint.json src/**/*.ts --fix",
     "build": "tsc -p ./tsconfig.json && cp src/ripemd.es5.js dist/ripemd.js",
-    "build-web": "webpack",
+    "build-web": "webpack --config webpack.prod.js && webpack --config webpack.debug.js",
     "clean": "rm -rf dist",
     "docs-init": "sh .docs/scripts/init.sh",
     "docs-build": "sh .docs/scripts/build.sh",
diff --git a/src/tests/web.html b/src/tests/web.html
index 95dde106c..1abca2516 100644
--- a/src/tests/web.html
+++ b/src/tests/web.html
@@ -1,8 +1,8 @@
 

 
-
-
-
+
+
+
 
-
-
+
+
+
 
-
-
-
+
+
+
 
 ```
 
+## Debugging
+
+If you would like readable source files for debugging, change the file reference to the `-debug.js` files inside `dist-web/debug`.  These files should only be used for development as they are over 10 times as large as the minified versions, and importing the debug versions will increase loading times for the end user.
+
 ## IE11 and Edge Support
 If you need to support IE11 or Edge you will also need to install a text-encoding polyfill as eosjs Signing is dependent on the TextEncoder which IE11 and Edge do not provide.  Pass the TextEncoder and TextDecoder to the API constructor as demonstrated in the [ES 2015 example](#node-es-2015).  Refer to the documentation here https://github.com/inexorabletash/text-encoding to determine the best way to include it in your project.
diff --git a/docs/4.-Reading blockchain-Examples.md b/docs/4.-Reading blockchain-Examples.md
index fd957a51f..4460e6481 100644
--- a/docs/4.-Reading blockchain-Examples.md	
+++ b/docs/4.-Reading blockchain-Examples.md	
@@ -3,9 +3,9 @@
 Reading blockchain state only requires an instance of `JsonRpc` connected to a node.
 
 ```javascript
-const {JsonRpc } = require('eosjs');
+const { JsonRpc } = require('eosjs');
 const fetch = require('node-fetch');           // node only; not needed in browsers
-const rpc = new JsonRpc('http://127.0.0.1:8000', { fetch });
+const rpc = new JsonRpc('http://127.0.0.1:8888', { fetch });
 ```
 
 ## Examples
diff --git a/src/tests/web.html b/src/tests/web.html
index 7fea306bd..95dde106c 100644
--- a/src/tests/web.html
+++ b/src/tests/web.html
@@ -5,7 +5,7 @@