Skip to content

Commit

Permalink
remove babel
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Oct 21, 2015
1 parent 9b52c35 commit 3f13d5b
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 193 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

4 changes: 1 addition & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"extends": "standard",
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true,
"mocha": true,
"es6": true
"mocha": true
}
}
6 changes: 1 addition & 5 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module.exports = function (config) {
config.set({
frameworks: ['browserify', 'detectBrowsers', 'mocha'],
files: [
'node_modules/babel-core/browser-polyfill.js',
'test/*.js'
],
preprocessors: {
Expand All @@ -17,10 +16,7 @@ module.exports = function (config) {
'karma-mocha'
],
browserify: {
debug: true,
transform: [
['babelify']
]
debug: true
},
detectBrowsers: {
enabled: true,
Expand Down
24 changes: 9 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "script2addresses",
"version": "1.0.1",
"version": "1.1.0",
"description": "Transform bitcoin script to bitcoin addresses",
"keywords": [
"bitcoin",
Expand All @@ -20,52 +20,46 @@
"email": "fanatid@ya.ru"
},
"files": [
"lib",
"src",
"LICENSE",
"README.md"
],
"main": "./lib/index.js",
"main": "./src/index.js",
"repository": {
"type": "git",
"url": "https://github.com/fanatid/script2addresses.git"
},
"scripts": {
"prepublish": "npm run clean && npm run compile",
"clean": "rm -rf lib/*",
"compile": "babel --optional runtime -d lib src -D",
"coverage": "istanbul cover _mocha -- --compilers js:babel/register test/*.js",
"coverage": "istanbul cover _mocha -- test/*.js",
"coveralls": "npm run coverage && coveralls <coverage/lcov.info",
"lint": "eslint src test",
"test": "npm run test:node && npm run test:browser",
"test:browser": "karma start karma.conf.js",
"test:node": "istanbul test mocha -- --compilers js:babel/register --reporter spec test/*.js"
"test:node": "istanbul test mocha -- --reporter spec test/*.js"
},
"dependencies": {
"babel-runtime": "^5.8.20",
"bn.js": "^3.2.0",
"bs58check": "^1.0.6",
"create-hash": "^1.1.2",
"elliptic": "^5.1.0"
},
"devDependencies": {
"babel": "^5.8.21",
"babel-core": "^5.8.22",
"babel-eslint": "^4.0.5",
"babelify": "^6.1.3",
"bitcoinjs-lib": "^2.1.1",
"chai": "^3.2.0",
"coveralls": "^2.11.3",
"eslint": "^1.0.0",
"eslint-config-standard": "^4.0.0",
"eslint-config-standard": "^4.4.0",
"eslint-plugin-standard": "^1.2.0",
"istanbul": "^0.3.17",
"istanbul": "^0.4.0",
"karma": "^0.13.8",
"karma-browserify": "^4.3.0",
"karma-chrome-launcher": "^0.2.0",
"karma-detect-browsers": "^2.0.1",
"karma-firefox-launcher": "^0.1.6",
"karma-mocha": "^0.2.0",
"mocha": "^2.2.5"
},
"engines": {
"node": ">=0.12"
}
}
32 changes: 16 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import createHash from 'create-hash'
import bs58check from 'bs58check'
var createHash = require('create-hash')
var bs58check = require('bs58check')

import networks from './networks.json'
import opcodes from './opcodes.json'
import isPublicKey from './publickey'
var networks = require('./networks.json')
var opcodes = require('./opcodes.json')
var isPublicKey = require('./publickey')

/**
* @param {Buffer} buf
Expand All @@ -20,8 +20,8 @@ function sha256ripemd160 (buf) {
* @return {string}
*/
function createAddress (version, hashBuffer) {
let versionBuffer = new Buffer([version])
let buffer = Buffer.concat([versionBuffer, hashBuffer])
var versionBuffer = new Buffer([version])
var buffer = Buffer.concat([versionBuffer, hashBuffer])
return bs58check.encode(buffer)
}

Expand All @@ -32,7 +32,7 @@ function createAddress (version, hashBuffer) {
* @return {?{bytes: number, size: number}}
*/
function readDataSize (buf, offset, strict) {
let opcode = buf[offset]
var opcode = buf[offset]

if ((strict && opcode >= opcodes.OP_PUSHDATA1) ||
opcode > opcodes.OP_PUSHDATA4 ||
Expand All @@ -58,7 +58,7 @@ function readDataSize (buf, offset, strict) {
* @param {boolean} [strict=false]
* @return {{type: string, addresses: Array.<string>}}
*/
export default function (buf, network, strict) {
module.exports = function (buf, network, strict) {
if (!Buffer.isBuffer(buf)) {
try {
buf = new Buffer(buf, 'hex')
Expand All @@ -75,7 +75,7 @@ export default function (buf, network, strict) {
network = networks.mainnet
}

let dataSize
var dataSize
switch (buf[0]) {
// pubkeyhash
case opcodes.OP_DUP:
Expand Down Expand Up @@ -142,15 +142,15 @@ export default function (buf, network, strict) {
}

// multisig
let mOp = buf[0]
let nOp = buf[buf.length - 2]
let isMultisig = (buf[buf.length - 1] === opcodes.OP_CHECKMULTISIG &&
var mOp = buf[0]
var nOp = buf[buf.length - 2]
var isMultisig = (buf[buf.length - 1] === opcodes.OP_CHECKMULTISIG &&
mOp >= opcodes.OP_1 &&
nOp <= opcodes.OP_16 &&
nOp >= mOp)

let pubKeys = []
for (let offset = 1, stop = buf.length - 2; isMultisig && offset < stop;) {
var pubKeys = []
for (var offset = 1, stop = buf.length - 2; isMultisig && offset < stop;) {
dataSize = readDataSize(buf, offset, strict)
if (dataSize === null) {
isMultisig = false
Expand All @@ -162,7 +162,7 @@ export default function (buf, network, strict) {
}

if (isMultisig && pubKeys.length === nOp - opcodes.OP_1 + 1) {
let addresses = pubKeys.map((pubKey) => {
var addresses = pubKeys.map((pubKey) => {
return createAddress(network.pubkeyhash, sha256ripemd160(pubKey))
})
return {
Expand Down
17 changes: 8 additions & 9 deletions src/publickey.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import elliptic from 'elliptic'
import BN from 'bn.js'
var BN = require('bn.js')
var ec = require('elliptic').curves.secp256k1

let ec = elliptic.curves.secp256k1
let zero = new BN(0)
var zero = new BN(0)

/**
* @param {Buffer} buf
* @param {boolean} [strict=false]
* @return {boolean}
*/
export default function (buf, strict) {
module.exports = function (buf, strict) {
if (!strict) {
switch (buf[0]) {
case 0x02:
Expand All @@ -24,7 +23,7 @@ export default function (buf, strict) {
}
}

let point
var point
if (buf.length === 65 &&
(buf[0] === 0x04 || buf[0] === 0x06 || buf[0] === 0x07)) {
point = ec.curve.point(buf.slice(1, 33), buf.slice(33, 65))
Expand All @@ -42,10 +41,10 @@ export default function (buf, strict) {
}

// Only for uncompressed,
// make sure that y equals value calculated through x
// make sure that given y values match with value calculated through x
// point.y.cmp(ec.curve.pointFromX(point.x, point.y.isOdd()).y) !== 0
// but point.validate() just is faster
// y is odd if version equals 0x07
// but point.validate() is faster
// y should be odd if version 0x07 or not if version is 0x06
if (buf.length === 65 &&
(!point.validate() ||
(buf[0] !== 0x04 && point.y.isOdd() !== (buf[0] === 0x07)))) {
Expand Down

0 comments on commit 3f13d5b

Please sign in to comment.