Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jprichardson committed Mar 7, 2014
0 parents commit 79bf8a1
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
.DS_Store
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.gitignore
test/
.DS_Store
component.json
bower.json
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0.0.1 / 2014-03-07
------------------
* initial release
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
coinstring
==========




License
-------

(MIT License)


34 changes: 34 additions & 0 deletions lib/coinstring.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var sha256 = require('crypto-hashing').sha256;
var base58 = require('bs58');

module.exports = coinstring

function coinstring(version, bytes) {
var version = new Buffer([version]);
var buf = Buffer.concat([version, bytes]);
var checksum = sha256.x2(buf).slice(0, 4);
var result = Buffer.concat([version, bytes, checksum]);
return base58.encode(result);
}

function decode(version, str) {
var buf = base58.decode(result);

}

function coinstringImpl(version, bytes) {

}

function partial(fn) {
var args = Array.prototype.slice.call(arguments);
var fn = args.shift();
return function(){
var arg = 0;
for (var i = 0; i < args.length && arg < arguments.length; i++) {
if ( args[i] === undefined )
args[i] = arguments[arg++];
}
return fn.apply(this, args);
}
}
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "constring",
"version": "0.0.1",
"description": "Create and parse crypto currency addresses, wallet import formats, etc.",
"keywords": [
"cryptography",
"crypto",
"bitcoin",
"litecoin",
"dogecoin",
"currency",
"cryptocurrency",
"address",
"wif"
],
"devDependencies": {
"mocha": "1.*",
"terst": "0.0.2",
"binstring": "~0.2.0"
},
"repository": {
"url": "https://github.com/cryptocoinjs/coinstring",
"type": "git"
},
"main": "./lib/coinstring.js",
"dependencies": {
"bs58": "0.3.x",
"crypto-hashing": "~0.2.0"
}
}
45 changes: 45 additions & 0 deletions test/coinstring.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var coinstring = require('../')
var conv = require('binstring');

require('terst');


describe('coinstring', function() {
describe('> when all arguments are passed', function() {
describe('> when Bitcoin', function() {
describe('> when public', function() {
it('should generate the public address', function() {
var hash160 = "3c176e659bea0f29a3e9bf7880c112b1b31b4dc8"; //hash representing uncompressed
var hash160Buf = conv(hash160, {in: 'hex', out: 'buffer'});
var address = "16UjcYNBG9GTK4uq2f7yYEbuifqCzoLMGS"
var version = 0x0 //bitcoin public / pubkeyhash
EQ (coinstring(version, hash160Buf), address);

//EQ (coinstring.decode(version, address).toString('hex'), hash160Buf.toString('hex'));

hash160 = "a1c2f92a9dacbd2991c3897724a93f338e44bdc1"; //hash representing compressed
hash160Buf = conv(hash160, {in: 'hex', out: 'buffer'});
address = '1FkKMsKNJqWSDvTvETqcCeHcUQQ64kSC6s';
EQ (coinstring(version, hash160Buf), address)
})
})

describe('> when private', function() {
it('should generate the WIF', function() {
var privatekeyhex = "1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd";
var wif = "5Hx15HFGyep2CfPxsJKe2fXJsCVn5DEiyoeGGF6JZjGbTRnqfiD"
var version = 0x80 //bitcoin private key

EQ (coinstring(version, conv(privatekeyhex, {in: 'hex', out: 'buffer'})), wif);

//compressed
var wifCompressed = 'KwomKti1X3tYJUUMb1TGSM2mrZk1wb1aHisUNHCQXTZq5auC2qc3';
privatekeyhex += '01'; //<--- '01' at the end represents a compressed wif address
EQ (coinstring(version, conv(privatekeyhex, {in: 'hex', out: 'buffer'})), wifCompressed);
})
})
})
})
})


3 changes: 3 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--ui bdd
--reporter spec
--timeout 2000

0 comments on commit 79bf8a1

Please sign in to comment.