Merge pull request #42 from maraoz/feature/browserify-base58
browserify base58
This commit is contained in:
commit
06d7969e87
|
@ -1,4 +1,5 @@
|
|||
build/
|
||||
browser/bundle.js
|
||||
node_modules/
|
||||
*.swp
|
||||
*~
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"node": true, // Enable globals available when code is running inside of the NodeJS runtime environment.
|
||||
"browser": true, // Standard browser globals e.g. `window`, `document`.
|
||||
"esnext": true, // Allow ES.next specific features such as `const` and `let`.
|
||||
"bitwise": false, // Prohibit bitwise operators (&, |, ^, etc.).
|
||||
"camelcase": false, // Permit only camelcase for `var` and `object indexes`.
|
||||
"curly": false, // Require {} for every new block or scope.
|
||||
"eqeqeq": true, // Require triple equals i.e. `===`.
|
||||
"immed": true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
|
||||
"latedef": true, // Prohibit variable use before definition.
|
||||
"newcap": true, // Require capitalization of all constructor functions e.g. `new F()`.
|
||||
"noarg": true, // Prohibit use of `arguments.caller` and `arguments.callee`.
|
||||
"quotmark": "single", // Define quotes to string values.
|
||||
"regexp": true, // Prohibit `.` and `[^...]` in regular expressions.
|
||||
"undef": true, // Require all non-global variables be declared before they are used.
|
||||
"unused": true, // Warn unused variables.
|
||||
"strict": true, // Require `use strict` pragma in every file.
|
||||
"trailing": true, // Prohibit trailing whitespaces.
|
||||
"smarttabs": false, // Suppresses warnings about mixed tabs and spaces
|
||||
"globals": { // Globals variables.
|
||||
"angular": true
|
||||
},
|
||||
"predef": [ // Extra globals.
|
||||
"define",
|
||||
"require",
|
||||
"exports",
|
||||
"module",
|
||||
"describe",
|
||||
"before",
|
||||
"beforeEach",
|
||||
"after",
|
||||
"afterEach",
|
||||
"requirejs",
|
||||
"it"
|
||||
],
|
||||
"indent": false, // Specify indentation spacing
|
||||
"devel": true, // Allow development statements e.g. `console.log();`.
|
||||
"noempty": true // Prohibit use of empty blocks.
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = function(grunt) {
|
||||
|
||||
//Load NPM tasks
|
||||
grunt.loadNpmTasks('grunt-browserify');
|
||||
grunt.loadNpmTasks('grunt-contrib-watch');
|
||||
grunt.loadNpmTasks('grunt-mocha-test');
|
||||
|
||||
// Project Configuration
|
||||
grunt.initConfig({
|
||||
browserify: {
|
||||
client: {
|
||||
src: ['bitcore.js'],
|
||||
dest: 'browser/bundle.js',
|
||||
options: {
|
||||
alias: ['browserify-bignum/bignumber.js:bignum'],
|
||||
standalone: 'bitcore'
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
scripts: {
|
||||
files: ['**/*.js', '**/*.html', '!**/node_modules/**', '!**/bundle.js'],
|
||||
tasks: ['browserify'/*, 'mochaTest'*/],
|
||||
},
|
||||
},
|
||||
mochaTest: {
|
||||
options: {
|
||||
reporter: 'spec',
|
||||
},
|
||||
src: ['test/*.js'],
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
grunt.registerTask('default', ['watch']);
|
||||
|
||||
};
|
||||
|
|
@ -46,6 +46,13 @@ Bitcore is still under heavy development and not quite ready for "drop-in" produ
|
|||
#Contributing
|
||||
Bitcore needs some developer love. Please send pull requests for bug fixes, code optimization, and ideas for improvement.
|
||||
|
||||
# install bitcore
|
||||
cd bitcore/
|
||||
npm install
|
||||
|
||||
# build browser version
|
||||
npm install -g grunt-cli
|
||||
grunt browserify
|
||||
|
||||
|
||||
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/bitpay/bitcore/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
require('classtool');
|
||||
|
||||
function spec(b) {
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* Bitcore bindings for the browser
|
||||
*/
|
||||
|
||||
|
||||
module.exports.bignum = require('bignum');
|
||||
module.exports.base58 = require('base58-native');
|
||||
//module.exports.Address = require('./Address');
|
||||
|
||||
|
||||
|
||||
if (typeof process.versions === 'undefined') {
|
||||
module.exports.bignum.config({EXPONENTIAL_AT: 9999999, DECIMAL_PLACES: 0, ROUNDING_MODE: 1});
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<script src="bundle.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
26
package.json
26
package.json
|
@ -7,9 +7,15 @@
|
|||
"email": "stephen@bitpay.com"
|
||||
},
|
||||
"contributors": [
|
||||
{"name": "Stefan Thomas", "email": "moon@justmoon.net"},
|
||||
{"name": "Jeff Garzik", "email": "jgarzik@bitpay.com"}
|
||||
],
|
||||
{
|
||||
"name": "Stefan Thomas",
|
||||
"email": "moon@justmoon.net"
|
||||
},
|
||||
{
|
||||
"name": "Jeff Garzik",
|
||||
"email": "jgarzik@bitpay.com"
|
||||
}
|
||||
],
|
||||
"keywords": [
|
||||
"bitcoin",
|
||||
"btc",
|
||||
|
@ -25,16 +31,22 @@
|
|||
"scripts": {},
|
||||
"dependencies": {
|
||||
"classtool": "=1.0.0",
|
||||
"base58-native": "=0.1.1",
|
||||
"bindings": "=1.1.0",
|
||||
"base58-native": "=0.1.3",
|
||||
"bindings": "=1.1.1",
|
||||
"bufferput": "=0.1.1",
|
||||
"bignum": "=0.6.1",
|
||||
"binary": "=0.3.0",
|
||||
"step": "=0.0.4",
|
||||
"buffers": "=0.1.1",
|
||||
"buffertools": "=1.1.1",
|
||||
"mocha": ">=1.15.1"
|
||||
"mocha": ">=1.15.1",
|
||||
"browserify-bignum": "git://github.com/maraoz/browserify-bignum.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"grunt-contrib-watch": "~0.5.3",
|
||||
"grunt-mocha-test": "~0.8.2",
|
||||
"grunt-browserify": "~1.3.0",
|
||||
"chai": "~1.9.0"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"license": "MIT"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
if (typeof require === 'undefined') {
|
||||
var that = this;
|
||||
that.require = function(name) {
|
||||
var split = name.split('/');
|
||||
if (split.length > 0) {
|
||||
name = split.pop();
|
||||
}
|
||||
var module = that[name];
|
||||
if (!module) {
|
||||
throw new Error('Cannot find module "'+name+'"');
|
||||
}
|
||||
return module;
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Mocha</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
<script src="adapter.js"></script>
|
||||
<script src="../node_modules/mocha/mocha.js"></script>
|
||||
<script src="../node_modules/chai/chai.js"></script>
|
||||
<script>mocha.setup('bdd')</script>
|
||||
<script src="../browser/bundle.js"></script>
|
||||
|
||||
<script src="test.main.js"></script>
|
||||
<script src="test.base58.js"></script>
|
||||
<script>
|
||||
mocha.run();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,45 @@
|
|||
'use strict';
|
||||
|
||||
var chai = require('chai');
|
||||
var bitcore = require('../bitcore');
|
||||
|
||||
var expect = chai.expect;
|
||||
var should = chai.should();
|
||||
|
||||
var bignum = bitcore.bignum;
|
||||
var base58 = bitcore.base58;
|
||||
var base58Check = base58.base58Check;
|
||||
|
||||
describe('bignum module basics', function() {
|
||||
it('should initialze the main object', function() {
|
||||
should.exist(bitcore.bignum);
|
||||
});
|
||||
it('should create a bignum from string', function() {
|
||||
var n = bignum('9832087987979879879879879879879879879879879879');
|
||||
should.exist(n);
|
||||
});
|
||||
it('should perform basic math operations', function() {
|
||||
var b = bignum('782910138827292261791972728324982')
|
||||
.sub('182373273283402171237474774728373')
|
||||
.div(13);
|
||||
b.toNumber().should.equal(46195143503376160811884457968969);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('base58 module', function() {
|
||||
it('should initialze the main object', function() {
|
||||
should.exist(bitcore.base58);
|
||||
});
|
||||
it('should obtain the same string in base58 roundtrip', function() {
|
||||
var m = 'mqqa8xSMVDyf9QxihGnPtap6Mh6qemUkcu';
|
||||
base58.encode(base58.decode(m)).should.equal(m);
|
||||
});
|
||||
it('should obtain the same string in base58Check roundtrip', function() {
|
||||
var m = '1QCJj1gPZKx2EwzGo9Ri8mMBs39STvDYcv';
|
||||
base58Check.encode(base58Check.decode(m)).should.equal(m);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
var chai = require('chai');
|
||||
var bitcore = require('../bitcore');
|
||||
|
||||
var expect = chai.expect;
|
||||
var should = chai.should();
|
||||
|
||||
describe('Initialization of bitcore', function() {
|
||||
it('should initialze the main object', function() {
|
||||
should.exist(bitcore);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue