release candidate rc3 supporting mandel 3.1 endpoints

* Made sure server_version_string was avalible. It would be undefined when chainId was provided to the constructor. Made server_version a private late-init member, and added a check to populate when needed
* Added node's semver parsing for version string support checks
* Security updated moved developement package JsSigniture to use Buffer.from
* Updated npm dependancies to include node-fetch and semver
* Documentation: Added simple example in readme
* Documenation: Added clarity on providers of private key vaults
* Documentation: switch to npm build/install no more references to yarn

Squashed commit of the following:

commit 5c321adb22493298fc0d2b3624ccffddbe66af97
Author: Eric Passmore <eric.passmore@gmail.com>
Date:   Mon Aug 15 09:51:25 2022 -0700

    minor updates for node package

    updated dependancies in package.json
    switch all yarn instructures to use npm (its 2022 npm is the way to go)
    added a very simple example to get info into readme

    Updated documentation for send_transaction2
    Removed EOSIO github references
    Updated .travel.yml with node_js 16.0.0 and npm@8.0.0

Date:   Fri Aug 12 22:22:25 2022 -0700

    minor fixes for release of node pkg

commit 57bb0003a808e58de9154271cf12d3e9cfb68346
Author: Eric Passmore <eric.passmore@gmail.com>
Date:   Fri Aug 12 19:22:57 2022 -0700

    init commit updated for integration tests

commit 5855e69c1ed2a35c20300189272419ab95031fc6
Author: Eric Passmore <eric.passmore@gmail.com>
Date:   Tue Aug 9 13:36:53 2022 -0700

    housekeeping updated .gitignore for webstorm, and added package-lock.json

commit ff87097ae66c06808000f046362c0c15b6ed1fa2
Merge: f65d2cb 4266b71
Author: Eric Passmore <eric.passmore@gmail.com>
Date:   Tue Aug 9 13:31:57 2022 -0700

    Merge remote-tracking branch 'origin' into ericpassmore-working

commit f65d2cbfc916081676bf7d4cf61c65ea54c90f14
Author: Eric Passmore <eric.passmore@gmail.com>
Date:   Mon Aug 8 20:27:55 2022 -0700

    first pass instructions for integration tests

commit 32a4bd40260a8d8d3debade9d24421e4fdc1e555
Merge: 9d6aa60 251beab
Author: Eric Passmore <eric.passmore@gmail.com>
Date:   Mon Aug 8 12:39:49 2022 -0700

    Merge Updated release 3.0 Endpoints for get info and transaction

commit 9d6aa60846d30f66f5e64eb6d29bb7c6f0cd35ae
Author: Eric Passmore <eric.passmore@gmail.com>
Date:   Thu Aug 4 12:48:15 2022 -0700

    fixed path for reference

commit a22bdfa6f9b539f9736ac2809a33afb0c1148a28
Author: Eric Passmore <eric.passmore@gmail.com>
Date:   Wed Aug 3 13:09:29 2022 -0700

    removed eos.io

commit 704be7c65ae3bc00236e5dcac71883c8bf8ada7d
Author: Eric Passmore <eric.passmore@gmail.com>
Date:   Wed Aug 3 13:06:57 2022 -0700

    removed eos.io references
This commit is contained in:
Eric Passmore
2022-08-15 09:59:19 -07:00
parent 4266b71b01
commit 1271b842e5
15 changed files with 27809 additions and 4829 deletions
+2
View File
@@ -1,4 +1,6 @@
.DS_Store
# ignore webstorm IDE
.idea
dist/
dist-web/
node_modules/
+2 -2
View File
@@ -4,9 +4,9 @@ env:
sudo: false
language: node_js
node_js:
- '10.0.0'
- '16.0.0'
before_install:
- npm i -g npm@6.4.1
- npm i -g npm@8.0.0
- yarn global add typescript
- yarn global add webpack
before_script:
+7 -9
View File
@@ -35,12 +35,12 @@ Guidelines for bug reports:
reported.
1. **Check if the issue has been fixed** &mdash; look for [closed issues in the
current milestone](https://github.com/EOSIO/eosjs/issues?q=is%3Aissue+is%3Aclosed) or try to reproduce it
current milestone](https://github.com/eosnetworkfoundation/mandel-eosjs/issues?q=is%3Aissue+is%3Aclosed) or try to reproduce it
using the latest `develop` branch.
A good bug report shouldn't leave others needing to chase you up for more information. Be sure to include the details of your environment and relevant tests that demonstrate the failure.
[Report a bug](https://github.com/EOSIO/eosjs/issues/new?template=bug_report.md)
[Report a bug](https://github.com/eosnetworkfoundation/mandel-eosjs/issues/new?template=bug_report.md)
### Feature Requests
@@ -60,16 +60,14 @@ Change requests cover both architectural and functional changes to how EOSJS wor
## Working on EOSJS
Code contributions are welcome and encouraged! If you are looking for a good place to start, check out the [good first issue](https://github.com/EOSIO/eosjs/labels/good%20first%20issue) label in GitHub issues.
Code contributions are welcome and encouraged! If you are looking for a good place to start, check out the [good first issue](https://github.com/eosnetworkfoundation/mandel-eosjs/labels/good%20first%20issue) label in GitHub issues.
Also, please follow these guidelines when submitting code:
### Feature Branches
To get it out of the way:
- **[develop](https://github.com/EOSIO/eosjs/tree/develop)** is the development branch. All work on the next release happens here so you should generally branch off `develop`. Do **NOT** use this branch for a production site.
- **[master](https://github.com/EOSIO/eosjs/tree/master)** contains the latest release of EOSJS. This branch may be used in production. Do **NOT** use this branch to work on EOSJS's source.
- **[main](https://github.com/eosnetworkfoundation/mandel-eosjs/tree/main)** contains the latest release of EOSJS. Make your own branch off main for development, and create a pull request to merge into **main**
- **[releases](https://github.com/eosnetworkfoundation/mandel-eosjs/tags)** Tags starting with *v** are the release branches. You don't want to develop off these.
### Submitting Pull Requests
@@ -77,7 +75,7 @@ Pull requests are awesome. If you're looking to raise a PR for something which d
### Testing
EOSJS is used by many libraries across the EOSIO ecosystem, so proper testing is absolutely essential prior to opening a pull request. This can be done in EOSJS by running `yarn build-production`. This command will build the distrubution bundles (`yarn build-all`) and test each environment accordingly (`yarn test-all`).
EOSJS is used by many libraries across the EOS ecosystem, so proper testing is absolutely essential prior to opening a pull request. This can be done in EOSJS by running `yarn build-production`. This command will build the distrubution bundles (`yarn build-all`) and test each environment accordingly (`yarn test-all`).
#### Automated Unit Test Suite
@@ -85,7 +83,7 @@ EOSJS is used by many libraries across the EOSIO ecosystem, so proper testing is
#### Integration Test Suite
Integration tests will only work with a local node running on port 8888 and with test accounts "bob" and "alice".
Integration tests will only work with a local node running on port 8888 and with test accounts "bobtestlion1" and "alicetestlio".
##### Web Environment
+45 -8
View File
@@ -1,21 +1,21 @@
# eosjs ![npm](https://img.shields.io/npm/dw/eosjs.svg)
# enf-eosjs ![npm](https://img.shields.io/npm/dw/enf-eosjs.svg)
Javascript API for integration with EOSIO-based blockchains using [EOSIO RPC API](/developer-tools/01_nodeos/index.md).
Javascript API for integration with EOS-based blockchains.
## Installation
### NPM
The officially distributed npm packed will be posted soon.
[enf-eosjs](https://www.npmjs.com/package/enf-eosjs) has been updated to support latest features in EOS blockchain. This is an updated version of the popular eosjs package.
### NodeJS Dependency
`yarn add eosjs`
`npm install enf-eosjs`
### Using with Typescript
In order to get access to the `TextEncoding` and `TextDecoding` types, you need to add `@types/text-encoding` as a dev dependency:
`yarn add --dev @types/text-encoding`
`npm install --save @types/text-encoding`
If you're using Node (not a browser) then you'll also need to make sure the `dom` lib is referenced in your `tsconfig.json`:
@@ -29,15 +29,53 @@ If you're using Node (not a browser) then you'll also need to make sure the `dom
### Browser Distribution
Clone this repository locally then run `yarn build-web`. The browser distribution will be located in `dist-web` and can be directly copied into your project repository. The `dist-web` folder contains minified bundles ready for production, along with source mapped versions of the library for debugging.
Clone this repository locally then run `npm run build-web`. The browser distribution will be located in `dist-web` and can be directly copied into your project repository. The `dist-web` folder contains minified bundles ready for production, along with source mapped versions of the library for debugging.
## Getting Started
Very simple example of using **enf-eosjs**. Included unused imports as examples.
```shell
npm init es6
npm install enf-eosjs
node node_test
```
```js
/*
* @module test_enf_eosjs
* PUT THIS INTO A FILE NAMED node_test.js
*/
import { Api, JsonRpc, RpcError } from 'enf-eosjs';
import fetch from 'node-fetch'
import { TextEncoder, TextDecoder } from 'util';
const rpc = new JsonRpc('https://localhost:443', { fetch });
const api = new Api({ rpc, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
var info = await rpc.get_info();
console.log(info);
```
## Import
### Signature Providers
It best to use a secure well supported secret store. Some examples of providers include:
* Azure Key Vault
* Hashicorp Vault
* Google Cloud Secret Manager
* AWS Secrets Management
*JsSignatureProvider* is included as an example, and it is not provided by enf-eosjs.
### ES Modules
Importing using ES6 module syntax in the browser is supported if you have a transpiler, such as Babel.
```js
import { Api, JsonRpc, RpcError } from 'eosjs';
import { Api, JsonRpc, RpcError } from 'enf-eosjs';
import { JsSignatureProvider } from 'eosjs/dist/eosjs-jssig'; // development only
```
@@ -46,7 +84,6 @@ import { JsSignatureProvider } from 'eosjs/dist/eosjs-jssig'; // devel
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'); // development only
const fetch = require('node-fetch'); // node only; not needed in browsers
const { TextEncoder, TextDecoder } = require('util'); // node only; native TextEncoder/Decoder
const { TextEncoder, TextDecoder } = require('text-encoding'); // React Native, IE11, and Edge Browsers only
+28
View File
@@ -176,3 +176,31 @@ const result = await api.transact({
expireSeconds: 30,
});
```
## Old RPC Behavior
By default, transactions use the send_transaction2 endpoint and the updated transaction behavior. If you would like to revert to the previous behavior pass in the boolean **useOldSendRPC** with value True.
[See Readme *Sending A Transaction*](../README.md#Sending%20a%20transaction) for additional paramaters.
```javascript
const result = await api.transact({
actions: [{
account: 'eosio',
name: 'delegatebw',
authorization: [{
actor: 'useraaaaaaaa',
permission: 'active',
}],
data: {
from: 'useraaaaaaaa',
receiver: 'useraaaaaaaa',
stake_net_quantity: '1.0000 SYS',
stake_cpu_quantity: '1.0000 SYS',
transfer: false,
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
useOldSendRPC: true,
});
```
+1 -1
View File
@@ -1,7 +1,7 @@
# Browsers
## Usage
`npm run build-web` or `yarn build-web`
`npm run build-web`
Reuse the `api` object for all transactions; it caches ABIs to reduce network usage. Only call `new eosjs_api.Api(...)` once.
+31 -25
View File
@@ -22,10 +22,6 @@ Once you follow the directions you need to grap the keys for the existing eosio
egrep 'priv_key|pub_key' src/dune/*.py
```
## Private Keys in Tests
Look at `src/tests/node.js` and `src/tests/web.html` to make sure the private key matches DUNE's.
## Start a Node
Start a node if you haven't already
@@ -34,29 +30,14 @@ dune --start test_node
```
## Create Wallet
Bit of a workaround here as of Aug 2022 there is a permissions problem. Workaround
1 create an account that will fail
2 new account created wallet
3 change permissions on wallet
### Create An Account Will Fail
Start a Docker shell. Must be done locally due to permission problems with DUNE.
```
dune --create-account thiswillfail
Creating account [nodeone] with key pair [Private: 5K4GCQPREhc6HmJ2wWNqRHvVNSL1bZ79hu8grtmkUhGJcndUfMg, Public: EOS8DMcuK28sN7jw8Uj5gEKtH8JxdbhovhVkDaUoQAemo49RBse97]
Error 3120006: No available wallet
Ensure that you have created a wallet and have it open
Error Details:
You don't have any wallet!
Stack Trace:
wallet_manager.cpp:140 get_public_keys
docker exec -it dune_container /bin/bash
```
### Change Permissions on Docker Container
Commands to make wallet
```
docker exec -u root -it dune_container cp /root/eosio-wallet/default.wallet /home/www-data/eosio-wallet/
docker exec -u root -it dune_container chown www-data:www-data /home/www-data/eosio-wallet/default.wallet
cleos wallet create -n bob -f jungle4-wallet/bob.wallet
cleos wallet unlock -n bobtestlion1 --password $(cat jungle4-wallet/bob.wallet)
```
## Create Accounts
@@ -64,12 +45,37 @@ docker exec -u root -it dune_container chown www-data:www-data /home/www-data/eo
Now we can create our test accounts. In the examples below replace, **priv_key** and **pub_key** with the values from [DUNE Keys](#DUNE Keys)
```
dune --create-key
dune --create-account bob eosio pub_key priv_key
dune --create-key
dune --create-account alice eosio pub_key priv_key
```
## Add Private Key to Wallet
Use bob's priv_key
Note done locally
```
cleos wallet import -n bobtestlion1 --private-key priv_key
```
## Test Transfer
Note done locally
```
cleos transfer bob alice "0.001 EOS" "Hodl!" -p bob
```
## Private Keys in Tests
Look at `src/tests/node.js` and `src/tests/web.html` to make sure the private key matches DUNE's.
## Run Tests
```
yarn test node
npm run test node
```
If you want just the integration tests run.
```angular2html
npm run test-node
```
+23024
View File
File diff suppressed because it is too large Load Diff
+6 -4
View File
@@ -1,7 +1,7 @@
{
"name": "mandel-eosjs",
"version": "1.0.0",
"description": "Talk to mandel-eosio API",
"name": "enf-eosjs",
"version": "23.0.0-rc3",
"description": "JS API to talk to eosio blockchain",
"main": "dist/index.js",
"scripts": {
"cypress": "cypress run --spec 'cypress/integration/index.spec.js'",
@@ -31,7 +31,9 @@
"bn.js": "5.2.0",
"elliptic": "6.5.4",
"hash.js": "1.1.7",
"pako": "2.0.3"
"pako": "2.0.3",
"node-fetch": "2.6.7",
"semver": "^7.3.7"
},
"devDependencies": {
"@blockone/eslint-config-blockone": "^4.0.1",
+2 -2
View File
@@ -4,8 +4,8 @@ setup_git() {
# Set the user name and email to match the API token holder
# This will make sure the git commits will have the correct photo
# and the user gets the credit for a checkin
git config --global user.email "devops@block.one"
git config --global user.name "blockone-devops"
git config --global user.email "eric.passmore@gmail.com"
git config --global user.name "ericpassmore"
git config --global push.default matching
# Get the credentials from a file
+4
View File
@@ -0,0 +1,4 @@
npm login
npm publish
+21 -1
View File
@@ -11,6 +11,9 @@ import * as ser from './eosjs-serialize';
const abiAbi = require('../src/abi.abi.json');
const transactionAbi = require('../src/transaction.abi.json');
const semver = require('semver')
export class Api {
/** Issues RPC calls */
public rpc: JsonRpc;
@@ -42,6 +45,12 @@ export class Api {
/** Fetched abis */
public cachedAbis = new Map<string, CachedAbi>();
/** Matched get_info server version string
* Deferred call to get_info will populate
* Needed for new 3.1+ endpoints to check support
* */
private server_version_string?: string
/**
* @param args
* * `rpc`: Issues RPC calls
@@ -71,6 +80,9 @@ export class Api {
this.abiTypes = ser.getTypesFromAbi(ser.createInitialTypes(), abiAbi);
this.transactionTypes = ser.getTypesFromAbi(ser.createInitialTypes(), transactionAbi);
// deferred call to get_info will populate
this.server_version_string = undefined;
}
/** Decodes an abi as Uint8Array into json. */
@@ -261,12 +273,20 @@ export class Api {
if (!this.chainId) {
info = await this.rpc.get_info();
this.chainId = info.chain_id;
this.server_version_string = info.server_version_string;
}
const isRetry = retryIrreversible || retryTrxNumBlocks > 0;
if(isRetry) {
if(info.server_version_string < "v3.1.0") {
if (!this.server_version_string) {
info = await this.rpc.get_info();
this.server_version_string = info.server_version_string;
}
// check if current version bigger than 3.1 release or release candidate
if(semver.lt(this.server_version_string,'v3.1.0-rc1') ) {
throw new Error(`Retry transaction feature unavailable for nodeos :${info.server_version_string}`);
}
if (useOldRPC || useOldSendRPC) {
+3 -3
View File
@@ -50,9 +50,9 @@ export class JsSignatureProvider implements SignatureProvider {
) {
const e = new ec('secp256k1') as any;
const signBuf = Buffer.concat([
new Buffer(chainId, 'hex'),
new Buffer(serializedTransaction),
new Buffer(
Buffer.from(chainId, 'hex'),
Buffer.from(serializedTransaction),
Buffer.from(
serializedContextFreeData ?
new Uint8Array(e.hash(serializedContextFreeData).update(serializedContextFreeData).digest()) :
new Uint8Array(32)
+24 -24
View File
@@ -22,13 +22,13 @@ const transactWithConfig = async () => await api.transact({
account: 'eosio.token',
name: 'transfer',
authorization: [{
actor: 'bob',
actor: 'bobtestlion1',
permission: 'active',
}],
data: {
from: 'bob',
to: 'alice',
quantity: '0.0001 SYS',
from: 'bobtestlion1',
to: 'alicetestlio',
quantity: '0.0001 EOS',
memo: '',
},
}]
@@ -53,13 +53,13 @@ const transactWithoutConfig = async () => {
account: 'eosio.token',
name: 'transfer',
authorization: [{
actor: 'bob',
actor: 'bobtestlion1',
permission: 'active',
}],
data: {
from: 'bob',
to: 'alice',
quantity: '0.0001 SYS',
from: 'bobtestlion1',
to: 'alicetestlio',
quantity: '0.0001 EOS',
memo: '',
},
}]
@@ -72,13 +72,13 @@ const transactWithoutBroadcast = async () => await api.transact({
account: 'eosio.token',
name: 'transfer',
authorization: [{
actor: 'bob',
actor: 'bobtestlion1',
permission: 'active',
}],
data: {
from: 'bob',
to: 'alice',
quantity: '0.0001 SYS',
from: 'bobtestlion1',
to: 'alicetestlio',
quantity: '0.0001 EOS',
memo: '',
},
}]
@@ -94,13 +94,13 @@ const transactWithRetry = async () => await api.transact({
account: 'eosio.token',
name: 'transfer',
authorization: [{
actor: 'bob',
actor: 'bobtestlion1',
permission: 'active',
}],
data: {
from: 'bob',
to: 'alice',
quantity: '0.0001 SYS',
from: 'bobtestlion1',
to: 'alicetestlio',
quantity: '0.0001 EOS',
memo: '',
},
}]
@@ -116,13 +116,13 @@ const transactWithRetryIrreversible = async () => await api.transact({
account: 'eosio.token',
name: 'transfer',
authorization: [{
actor: 'bob',
actor: 'bobtestlion1',
permission: 'active',
}],
data: {
from: 'bob',
to: 'alice',
quantity: '0.0001 SYS',
from: 'bobtestlion1',
to: 'alicetestlio',
quantity: '0.0001 EOS',
memo: '',
},
}]
@@ -140,13 +140,13 @@ const transactShouldFail = async () => await api.transact({
account: 'eosio.token',
name: 'transfer',
authorization: [{
actor: 'bob',
actor: 'bobtestlion1',
permission: 'active',
}],
data: {
from: 'bob',
to: 'alice',
quantity: '0.0001 SYS',
from: 'bobtestlion1',
to: 'alicetestlio',
quantity: '0.0001 EOS',
memo: '',
},
}]
+4609 -4750
View File
File diff suppressed because it is too large Load Diff