Skip to content

Commit

Permalink
Add additional ethereum utils
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjablack committed Jun 7, 2019
1 parent b0c4f72 commit f732328
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
24 changes: 24 additions & 0 deletions packages/ethereum-utils/lib/index.js
@@ -1,4 +1,6 @@
import { Block, Transaction } from '@liquality/schema'
import { padHexStart } from '@liquality/crypto'
import eip55 from 'eip55'

import { version } from '../package.json'

Expand All @@ -20,6 +22,26 @@ function remove0x (hash) {
return (typeof hash === 'string') ? hash.replace(/^0x/, '') : hash
}

/**
* Converts an ethereum address to the standard format
* @param {*} address
*/
function removeAddress0x (address) {
return remove0x(address).toLowerCase()
}

function checksumEncode (hash) {
return eip55.encode(ensure0x(hash))
}

function ensureBlockFormat (block) {
if (block === undefined) {
return 'latest'
} else {
return (typeof(block) === 'number') ? ensure0x(padHexStart(block.toString(16))) : block
}
}

function formatEthResponse (obj) {
if (typeof obj === 'string' || obj instanceof String) {
obj = remove0x(obj)
Expand Down Expand Up @@ -66,6 +88,8 @@ function normalizeTransactionObject (tx, currentHeight) {
export {
ensure0x,
remove0x,
removeAddress0x,
checksumEncode,
formatEthResponse,
normalizeTransactionObject,

Expand Down
47 changes: 47 additions & 0 deletions packages/ethereum-utils/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/ethereum-utils/package.json
Expand Up @@ -18,7 +18,9 @@
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.4.3",
"@liquality/schema": "^0.2.7"
"@liquality/crypto": "^0.2.7",
"@liquality/schema": "^0.2.7",
"eip55": "^1.0.3"
},
"engines": {
"node": "~8.12.0"
Expand Down

0 comments on commit f732328

Please sign in to comment.