Comparing version 0.1.2 to 0.1.3
@@ -0,1 +1,6 @@ | ||
# 0.1.3 -- config fixes | ||
1. webpack config updates | ||
2. build config updates | ||
# 0.1.2 -- removal of BigNumber for BN | ||
@@ -2,0 +7,0 @@ |
'use strict'; | ||
var BN = require('bn.js'); | ||
var numberToBN = require('number-to-bn'); | ||
var sha3 = require('ethjs-sha3'); | ||
var numberToBN = require('number-to-bn'); | ||
function getChecksumAddress(addressInput) { | ||
var address = addressInput; // eslint-disable-line | ||
if (typeof address !== 'string' || !address.match(/^0x[0-9A-Fa-f]{40}$/)) { | ||
throw new Error('[ethjs-abi] invalid address value ' + JSON.stringify(address) + ' not a valid hex string'); | ||
} | ||
address = address.substring(2).toLowerCase(); | ||
var hashed = sha3(address, true); | ||
address = address.split(''); | ||
for (var i = 0; i < 40; i += 2) { | ||
// eslint-disable-line | ||
if (hashed[i >> 1] >> 4 >= 8) { | ||
address[i] = address[i].toUpperCase(); | ||
} | ||
if ((hashed[i >> 1] & 0x0f) >= 8) { | ||
address[i + 1] = address[i + 1].toUpperCase(); | ||
} | ||
} | ||
return '0x' + address.join(''); | ||
} | ||
function getAddress(addressInput) { | ||
var address = addressInput; // eslint-disable-line | ||
var result = null; // eslint-disable-line | ||
if (typeof address !== 'string') { | ||
throw new Error('[ethjs-abi] invalid address value ' + JSON.stringify(address) + ' not a valid hex string'); | ||
} | ||
// Missing the 0x prefix | ||
if (address.substring(0, 2) !== '0x' && address.substring(0, 2) !== 'XE') { | ||
address = '0x' + address; | ||
} | ||
if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) { | ||
result = getChecksumAddress(address); | ||
// It is a checksummed address with a bad checksum | ||
if (address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) && result !== address) { | ||
throw new Error('invalid address checksum'); | ||
} | ||
// Maybe ICAP? (we only support direct mode) | ||
} else if (address.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)) { | ||
throw new Error('[ethjs-abi] ICAP and IBAN addresses, not supported yet..'); | ||
/* | ||
// It is an ICAP address with a bad checksum | ||
if (address.substring(2, 4) !== ibanChecksum(address)) { | ||
throw new Error('invalid address icap checksum'); | ||
} | ||
result = (new BN(address.substring(4), 36)).toString(16); | ||
while (result.length < 40) { result = '0' + result; } | ||
result = getChecksumAddress('0x' + result); | ||
*/ | ||
} else { | ||
throw new Error('[ethjs-abi] invalid address value ' + JSON.stringify(address) + ' not a valid hex string'); | ||
} | ||
return result; | ||
} | ||
// from ethereumjs-util | ||
@@ -456,4 +391,2 @@ function stripZeros(aInput) { | ||
BN: BN, | ||
getAddress: getAddress, | ||
getChecksumAddress: getChecksumAddress, | ||
bnToBuffer: bnToBuffer, | ||
@@ -460,0 +393,0 @@ isHexString: isHexString, |
{ | ||
"name": "ethjs-abi", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Just the Ethereum encoding and decoding methods from the ethers-io-wallet.", | ||
"main": "lib/index.js", | ||
"browser": "dist/ethjs-abi.js", | ||
"files": [ | ||
@@ -132,2 +131,9 @@ "dist", | ||
"author": "Nick Dodson <thenickdodson@gmail.com>", | ||
"contributors": [ | ||
{ | ||
"name": "Richard Moore", | ||
"email": "me@ricmoo.com", | ||
"url": "https://ethers.io" | ||
} | ||
], | ||
"repository": { | ||
@@ -134,0 +140,0 @@ "type": "git", |
const BN = require('bn.js'); | ||
const numberToBN = require('number-to-bn'); | ||
const sha3 = require('ethjs-sha3'); | ||
const numberToBN = require('number-to-bn'); | ||
function getChecksumAddress(addressInput) { | ||
var address = addressInput; // eslint-disable-line | ||
if (typeof(address) !== 'string' || !address.match(/^0x[0-9A-Fa-f]{40}$/)) { | ||
throw new Error(`[ethjs-abi] invalid address value ${JSON.stringify(address)} not a valid hex string`); | ||
} | ||
address = address.substring(2).toLowerCase(); | ||
const hashed = sha3(address, true); | ||
address = address.split(''); | ||
for (var i = 0; i < 40; i += 2) { // eslint-disable-line | ||
if ((hashed[i >> 1] >> 4) >= 8) { | ||
address[i] = address[i].toUpperCase(); | ||
} | ||
if ((hashed[i >> 1] & 0x0f) >= 8) { | ||
address[i + 1] = address[i + 1].toUpperCase(); | ||
} | ||
} | ||
return `0x${address.join('')}`; | ||
} | ||
function getAddress(addressInput) { | ||
var address = addressInput; // eslint-disable-line | ||
var result = null; // eslint-disable-line | ||
if (typeof(address) !== 'string') { throw new Error(`[ethjs-abi] invalid address value ${JSON.stringify(address)} not a valid hex string`); } | ||
// Missing the 0x prefix | ||
if (address.substring(0, 2) !== '0x' && | ||
address.substring(0, 2) !== 'XE') { address = `0x${address}`; } | ||
if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) { | ||
result = getChecksumAddress(address); | ||
// It is a checksummed address with a bad checksum | ||
if (address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) && result !== address) { | ||
throw new Error('invalid address checksum'); | ||
} | ||
// Maybe ICAP? (we only support direct mode) | ||
} else if (address.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)) { | ||
throw new Error('[ethjs-abi] ICAP and IBAN addresses, not supported yet..'); | ||
/* | ||
// It is an ICAP address with a bad checksum | ||
if (address.substring(2, 4) !== ibanChecksum(address)) { | ||
throw new Error('invalid address icap checksum'); | ||
} | ||
result = (new BN(address.substring(4), 36)).toString(16); | ||
while (result.length < 40) { result = '0' + result; } | ||
result = getChecksumAddress('0x' + result); | ||
*/ | ||
} else { | ||
throw new Error(`[ethjs-abi] invalid address value ${JSON.stringify(address)} not a valid hex string`); | ||
} | ||
return result; | ||
} | ||
// from ethereumjs-util | ||
@@ -415,4 +353,2 @@ function stripZeros(aInput) { | ||
BN, | ||
getAddress, | ||
getChecksumAddress, | ||
bnToBuffer, | ||
@@ -419,0 +355,0 @@ isHexString, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2110305
24
11947