Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
update tooling + web3 1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
clbrge committed Dec 20, 2020
1 parent 1bb8a49 commit 4afd8fc
Show file tree
Hide file tree
Showing 17 changed files with 4,568 additions and 2,167 deletions.
11 changes: 7 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module.exports = {
parser: "babel-eslint",
extends: "standard",
env: {
node: true
"env": {
"es2020": true,
"node": true,
"jest": true
},
"parserOptions": {
"sourceType": "module"
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
Expand Down
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
'@babel/preset-env',
{
targets: {
node: 'current',
node: 10,
},
},
],
Expand Down
5,773 changes: 3,993 additions & 1,780 deletions package-lock.json

Large diffs are not rendered by default.

75 changes: 36 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
{
"name": "rouge.js",
"version": "0.5.0",
"license": "AGPL-3.0-only",
"description": "Javascript library for interacting with the Rouge protocol",
"main": "dist/rouge.cjs.js",
"module": "dist/rouge.esm.js",
"jsdelivr": "dist/rouge.umd.min.js",
"files": [
"dist",
"src",
"examples"
],
"engines": {
"node": ">=10.0.0"
},
"repository": "TheRougeProject/rouge.js",
"keywords": [
"rouge.js",
"rge",
Expand All @@ -21,26 +12,33 @@
"voucher",
"ticket"
],
"engines": {
"node": ">=10.0.0"
},
"main": "dist/rouge.cjs.js",
"module": "dist/rouge.esm.js",
"jsdelivr": "dist/rouge.umd.min.js",
"files": [
"dist",
"src",
"examples"
],
"authors": [
"Christophe Le Bars <[email protected]>",
"Valentin D. Guillois <[email protected]>"
],
"license": "AGPL-3.0-only",
"repository": "TheRougeProject/rouge.js",
"scripts": {
"prepublish": "npm run build",
"release": "release-it",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls",
"example-node": "babel-node examples/node.js",
"lint": "npm run lint:eslint",
"lint:eslint": "eslint src/*.js test/*.js",
"format": "prettier-standard --format src/**/*.js test/**/*.js",
"lint": "prettier-standard --lint src/**/*.js test/**/*.js",
"test": "jest --verbose",
"test:coverage": "jest --coverage",
"test:watch": "clear && jest --watch",
"test:create": "jest --testPathIgnorePatterns='[]' -- __tests__/create.js",
"lint:test": "npm run lint && npm run test:coverage",
"build": "npm run lint:test && npm run build:rollup",
"build:rollup": "rimraf dist/ && cross-env VERSION=$npm_package_version rollup -c"
"build": "rimraf dist/ && cross-env VERSION=$npm_package_version rollup -c"
},
"release-it": {
"github": {
Expand All @@ -60,36 +58,30 @@
]
},
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/node": "^7.12.6",
"@babel/preset-env": "^7.12.1",
"@rollup/plugin-commonjs": "^16.0.0",
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/node": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^10.0.0",
"@rollup/plugin-replace": "^2.3.4",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.6.3",
"babel-plugin-relative-path-import": "^2.0.1",
"coveralls": "^3.1.0",
"cross-env": "^7.0.2",
"eslint": "^7.13.0",
"eslint-config-standard": "^16.0.1",
"eslint-plugin-babel": "^5.3.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.2",
"cross-env": "^7.0.3",
"dayjs": "^1.9.7",
"ganache-core": "^2.13.1",
"husky": "^4.3.0",
"husky": "^4.3.6",
"jest": "^26.6.3",
"lint-staged": "^10.5.3",
"nodemon": "^2.0.6",
"release-it": "^14.2.1",
"prettier-standard": "^16.4.1",
"release-it": "^14.2.2",
"rimraf": "^3.0.2",
"dayjs": "^1.9.5",
"rollup": "^2.33.1",
"rollup": "^2.35.1",
"rollup-plugin-terser": "^7.0.2",
"web3": "^1.2.11"
"web3": "^1.3.1"
},
"peerDependencies": {
"web3-eth": "1.2.x",
Expand All @@ -100,10 +92,15 @@
"hex64": "^0.4.0",
"rouge-protocol-solidity": "0.21.2"
},
"lint-staged": {
"src/**/*.js": [
"npm run format",
"npm run lint"
]
},
"husky": {
"hooks": {
"pre-commit": "npm run lint:test",
"pre-push": "npm run lint:test"
"pre-commit": "lint-staged"
}
}
}
8 changes: 4 additions & 4 deletions src/RGEMockup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { transact } from '../src/internalUtils'

import RGEToken from 'rouge-protocol-solidity/build/contracts/TestRGEToken.json'
Expand All @@ -9,7 +8,8 @@ const globalOptions = {
gasPrice: '100000'
}

const estimateAndDeploy = async contract => contract.deploy().send({ gas: await contract.deploy().estimateGas() })
const estimateAndDeploy = async contract =>
contract.deploy().send({ gas: await contract.deploy().estimateGas() })

export const sendTestRGE = (web3, rge, account, amount) =>
transact(
Expand Down Expand Up @@ -38,15 +38,15 @@ export const generateRgeMockup = async (web3, owner) => {

const tx1 = await transact(
web3,
{ as: {address: owner}, options: globalOptions },
{ as: { address: owner }, options: globalOptions },
factory.methods.setParams(rge.options.address, defaultTare),
factory.options.address
)
if (!tx1.status) throw new Error('cannot setParams in factory')

const tx2 = await transact(
web3,
{ as: {address: owner}, options: globalOptions },
{ as: { address: owner }, options: globalOptions },
rge.methods.setFactory(factory.options.address),
rge.options.address
)
Expand Down
42 changes: 24 additions & 18 deletions src/bytes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-var */

export function isHexable (value) {
return !!(value.toHexString)
return !!value.toHexString
}

export function addSlice (array) {
Expand All @@ -16,8 +16,11 @@ export function addSlice (array) {
}

export function isArrayish (value) {
// eslint-disable-next-line eqeqeq
if (!value || parseInt(String(value.length)) != value.length || typeof (value) === 'string') {
if (
!value || // eslint-disable-next-line eqeqeq
parseInt(String(value.length)) != value.length ||
typeof value === 'string'
) {
return false
}
for (var i = 0; i < value.length; i++) {
Expand All @@ -37,7 +40,7 @@ export function arrayify (value) {
if (isHexable(value)) {
value = value.toHexString()
}
if (typeof (value) === 'string') {
if (typeof value === 'string') {
var match = value.match(/^(0x)?[0-9a-fA-F]*$/)
if (!match) {
throw new Error('invalid hexidecimal string')
Expand Down Expand Up @@ -106,7 +109,7 @@ export function padZeros (value, length) {
}

export function isHexString (value, length) {
if (typeof (value) !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/)) {
if (typeof value !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/)) {
return false
}
if (length && value.length !== 2 + 2 * length) {
Expand All @@ -120,7 +123,7 @@ export function hexlify (value) {
if (isHexable(value)) {
return value.toHexString()
}
if (typeof (value) === 'number') {
if (typeof value === 'number') {
if (value < 0) {
throw new Error('cannot hexlify negative value')
}
Expand All @@ -142,7 +145,7 @@ export function hexlify (value) {
}
return '0x00'
}
if (typeof (value) === 'string') {
if (typeof value === 'string') {
var match = value.match(/^(0x)?[0-9a-fA-F]*$/)
if (!match) {
throw new Error('invalid hexidecimal string')
Expand All @@ -167,7 +170,7 @@ export function hexlify (value) {
}

export function hexDataLength (data) {
if (!isHexString(data) || (data.length % 2) !== 0) {
if (!isHexString(data) || data.length % 2 !== 0) {
return null
}
return (data.length - 2) / 2
Expand All @@ -177,7 +180,7 @@ export function hexDataSlice (data, offset, endOffset) {
if (!isHexString(data)) {
throw new Error('invalid hex data')
}
if ((data.length % 2) !== 0) {
if (data.length % 2 !== 0) {
throw new Error('hex data length must be even')
}
offset = 2 + 2 * offset
Expand Down Expand Up @@ -208,20 +211,21 @@ export function hexZeroPad (value, length) {
}

export function isSignature (value) {
return (value && value.r != null && value.s != null)
return value && value.r != null && value.s != null
}

export function splitSignature (signature) {
var v = 0
var r = '0x'; var s = '0x'
var r = '0x'
var s = '0x'
if (isSignature(signature)) {
if (signature.v == null && signature.recoveryParam == null) {
throw new Error('at least on of recoveryParam or v must be specified')
}
r = hexZeroPad(signature.r, 32)
s = hexZeroPad(signature.s, 32)
v = signature.v
if (typeof (v) === 'string') {
if (typeof v === 'string') {
v = parseInt(v, 16)
}
var recoveryParam = signature.recoveryParam
Expand All @@ -244,16 +248,18 @@ export function splitSignature (signature) {
return {
r: r,
s: s,
recoveryParam: (v - 27),
recoveryParam: v - 27,
v: v
}
}

export function joinSignature (signature) {
signature = splitSignature(signature)
return hexlify(concat([
signature.r,
signature.s,
(signature.recoveryParam ? '0x1c' : '0x1b')
]))
return hexlify(
concat([
signature.r,
signature.s,
signature.recoveryParam ? '0x1c' : '0x1b'
])
)
}
Loading

0 comments on commit 4afd8fc

Please sign in to comment.