Skip to content

Commit

Permalink
Don't pollute the Bitcoin.Util namespace with overrides from Crypto.u…
Browse files Browse the repository at this point in the history
…til.
  • Loading branch information
mbelshe committed Mar 25, 2014
1 parent 84a4296 commit 744b0f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,17 @@ Bitcoin.Util = {
return bytes;
},

bytesToHex: function (bytes) {
for (var hex = [], i = 0; i < bytes.length; i++) {
if (bytes[i] > 0xff) {
throw 'illegal input';
}
hex.push((bytes[i] >>> 4).toString(16));
hex.push((bytes[i] & 0xF).toString(16));
}
return hex.join("");
},

/**
* Parse a Bitcoin value byte array, returning a BigInteger.
*/
Expand Down Expand Up @@ -267,9 +278,3 @@ Bitcoin.Util = {
return Crypto.SHA256(Crypto.SHA256(data, { asBytes: true }), { asBytes: true });
}
};

for (var i in Crypto.util) {
if (Crypto.util.hasOwnProperty(i)) {
Bitcoin.Util[i] = Crypto.util[i];
}
}
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,9 @@ test("bytesToBase64 - ok", function() {

for (var index = 0; index < testArrays.length; ++index) {
var a = testArrays[index];
var s = Bitcoin.Util.bytesToBase64(a);
var s = Crypto.util.bytesToBase64(a);
ok(s, 'encoded test array #' + index);
var a2 = Bitcoin.Util.base64ToBytes(s);
var a2 = Crypto.util.base64ToBytes(s);
ok(a2, 'decoded test array #' + index);
deepEqual(a, a2, 'decoded array #' + index + ' matched');
}
Expand Down

0 comments on commit 744b0f7

Please sign in to comment.