forked from cryptocoinjs/coinstring
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 79bf8a1
Showing
8 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.gitignore | ||
test/ | ||
.DS_Store | ||
component.json | ||
bower.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
0.0.1 / 2014-03-07 | ||
------------------ | ||
* initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
coinstring | ||
========== | ||
|
||
|
||
|
||
|
||
License | ||
------- | ||
|
||
(MIT License) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--ui bdd | ||
--reporter spec | ||
--timeout 2000 |