Removed direct references to Bitcoin

This commit is contained in:
vub 2013-10-08 06:45:13 -04:00
parent a753f069a5
commit 038f8d5d99
6 changed files with 28 additions and 22 deletions

6
bitcoinjs-min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -110,7 +110,7 @@ ECKey.prototype.getExportedPrivateKey = function () {
hash.unshift(0x80); hash.unshift(0x80);
var checksum = Crypto.SHA256(Crypto.SHA256(hash, {asBytes: true}), {asBytes: true}); var checksum = Crypto.SHA256(Crypto.SHA256(hash, {asBytes: true}), {asBytes: true});
var bytes = hash.concat(checksum.slice(0,4)); var bytes = hash.concat(checksum.slice(0,4));
return Bitcoin.Base58.encode(bytes); return base58.encode(bytes);
}; };
ECKey.prototype.setPub = function (pub) { ECKey.prototype.setPub = function (pub) {

View file

@ -155,9 +155,9 @@ Script.prototype.simpleOutHash = function ()
case 'Address': case 'Address':
return this.chunks[2]; return this.chunks[2];
case 'Pubkey': case 'Pubkey':
return Bitcoin.Util.sha256ripe160(this.chunks[0]); return util.sha256ripe160(this.chunks[0]);
case 'Multisig': case 'Multisig':
return Bitcoin.Util.sha256ripe160(this.buffer); return util.sha256ripe160(this.buffer);
default: default:
throw new Error("Encountered non-standard scriptPubKey: " + this.getOutType()); throw new Error("Encountered non-standard scriptPubKey: " + this.getOutType());
} }
@ -198,7 +198,7 @@ Script.prototype.simpleOutPubKeyHash = Script.prototype.simpleOutHash;
Script.prototype.getInType = function () Script.prototype.getInType = function ()
{ {
if (this.chunks.length == 1 && if (this.chunks.length == 1 &&
Bitcoin.Util.isArray(this.chunks[0])) { util.isArray(this.chunks[0])) {
// Direct IP to IP transactions only have the signature in their scriptSig. // Direct IP to IP transactions only have the signature in their scriptSig.
// TODO: We could also check that the length of the data is correct. // TODO: We could also check that the length of the data is correct.
return 'Pubkey'; return 'Pubkey';
@ -261,7 +261,7 @@ Script.prototype.simpleInPubKey = function ()
*/ */
Script.prototype.simpleInHash = function () Script.prototype.simpleInHash = function ()
{ {
return Bitcoin.Util.sha256ripe160(this.simpleInPubKey()); return util.sha256ripe160(this.simpleInPubKey());
}; };
/** /**

View file

@ -3,6 +3,10 @@ var Script = require('./script');
var util = require('./util'); var util = require('./util');
var conv = require('./convert'); var conv = require('./convert');
var Crypto = require('./crypto-js/crypto'); var Crypto = require('./crypto-js/crypto');
var Wallet = require('./wallet');
var ECKey = require('./eckey');
var ECDSA = require('./ecdsa');
var Address = require('./address');
var Transaction = function (doc) { var Transaction = function (doc) {
this.version = 1; this.version = 1;
@ -265,7 +269,7 @@ Transaction.prototype.clone = function ()
* This method was unable to detect what the transaction does. Either it * This method was unable to detect what the transaction does. Either it
*/ */
Transaction.prototype.analyze = function (wallet) { Transaction.prototype.analyze = function (wallet) {
if (!(wallet instanceof Bitcoin.Wallet)) return null; if (!(wallet instanceof Wallet)) return null;
var allFromMe = true, var allFromMe = true,
allToMe = true, allToMe = true,
@ -300,7 +304,7 @@ Transaction.prototype.analyze = function (wallet) {
if (impact.sign > 0 && impact.value.compareTo(BigInteger.ZERO) > 0) { if (impact.sign > 0 && impact.value.compareTo(BigInteger.ZERO) > 0) {
analysis.type = 'recv'; analysis.type = 'recv';
analysis.addr = new Bitcoin.Address(firstMeRecvHash); analysis.addr = new Address(firstMeRecvHash);
} else if (allFromMe && allToMe) { } else if (allFromMe && allToMe) {
analysis.type = 'self'; analysis.type = 'self';
} else if (allFromMe) { } else if (allFromMe) {
@ -308,7 +312,7 @@ Transaction.prototype.analyze = function (wallet) {
// TODO: Right now, firstRecvHash is the first output, which - if the // TODO: Right now, firstRecvHash is the first output, which - if the
// transaction was not generated by this library could be the // transaction was not generated by this library could be the
// change address. // change address.
analysis.addr = new Bitcoin.Address(firstRecvHash); analysis.addr = new Address(firstRecvHash);
} else { } else {
analysis.type = "other"; analysis.type = "other";
} }
@ -378,7 +382,7 @@ Transaction.prototype.getTotalOutValue = function () {
* @returns Object Impact on wallet * @returns Object Impact on wallet
*/ */
Transaction.prototype.calcImpact = function (wallet) { Transaction.prototype.calcImpact = function (wallet) {
if (!(wallet instanceof Bitcoin.Wallet)) return BigInteger.ZERO; if (!(wallet instanceof Wallet)) return BigInteger.ZERO;
// Calculate credit to us from all outputs // Calculate credit to us from all outputs
var valueOut = BigInteger.ZERO; var valueOut = BigInteger.ZERO;
@ -474,13 +478,13 @@ Transaction.deserialize = function(buffer) {
Transaction.prototype.sign = function(index, key, type) { Transaction.prototype.sign = function(index, key, type) {
type = type || SIGHASH_ALL; type = type || SIGHASH_ALL;
key = new Bitcoin.ECKey(key); key = new ECKey(key);
var pub = key.getPub(), var pub = key.getPub(),
hash160 = Bitcoin.Util.sha256ripe160(pub), hash160 = util.sha256ripe160(pub),
script = Bitcoin.Script.createOutputScript(new Bitcoin.Address(hash160)), script = Script.createOutputScript(new Address(hash160)),
hash = this.hashTransactionForSignature( script, index, type), hash = this.hashTransactionForSignature( script, index, type),
sig = key.sign(hash).concat([type]); sig = key.sign(hash).concat([type]);
this.ins[i].script = Bitcoin.Script.createInputScript(sig,pub); this.ins[i].script = Script.createInputScript(sig,pub);
} }
/** /**
@ -488,8 +492,8 @@ Transaction.prototype.sign = function(index, key, type) {
*/ */
Transaction.prototype.p2shsign = function(index, script, key, type) { Transaction.prototype.p2shsign = function(index, script, key, type) {
script = new Bitcoin.Script(script); script = new Script(script);
key = new Bitcoin.ECKey(key); key = new ECKey(key);
type = type || SIGHASH_ALL; type = type || SIGHASH_ALL;
var hash = this.hashTransactionForSignature(script, index, type), var hash = this.hashTransactionForSignature(script, index, type),
sig = key.sign(hash).concat([type]); sig = key.sign(hash).concat([type]);
@ -499,9 +503,9 @@ Transaction.prototype.p2shsign = function(index, script, key, type) {
Transaction.prototype.multisign = Transaction.prototype.p2shsign; Transaction.prototype.multisign = Transaction.prototype.p2shsign;
Transaction.prototype.validateSig = function(index,script,sig,pub) { Transaction.prototype.validateSig = function(index,script,sig,pub) {
script = new Bitcoin.Script(script); script = new Script(script);
var hash = this.hashTransactionForSignature(script,i,1); var hash = this.hashTransactionForSignature(script,i,1);
return Bitcoin.ECDSA.verify(hash, conv.coerceToBytes(sig), return ECDSA.verify(hash, conv.coerceToBytes(sig),
conv.coerceToBytes(pub)); conv.coerceToBytes(pub));
} }

View file

@ -1,3 +1,5 @@
var Transaction = require('./transaction');
var TransactionDatabase = function () { var TransactionDatabase = function () {
this.txs = []; this.txs = [];
this.txIndex = {}; this.txIndex = {};
@ -16,7 +18,7 @@ TransactionDatabase.prototype.addTransactionNoUpdate = function (tx) {
return; return;
} }
this.txs.push(new Bitcoin.Transaction(tx)); this.txs.push(new Transaction(tx));
this.txIndex[tx.hash] = tx; this.txIndex[tx.hash] = tx;
}; };

View file

@ -329,7 +329,7 @@ Wallet.prototype.clearTransactions = function () {
* Check to see if a pubKeyHash belongs to this wallet. * Check to see if a pubKeyHash belongs to this wallet.
*/ */
Wallet.prototype.hasHash = function (hash) { Wallet.prototype.hasHash = function (hash) {
if (Bitcoin.Util.isArray(hash)) hash = conv.bytesToHex(hash); if (util.isArray(hash)) hash = conv.bytesToHex(hash);
// TODO: Just create an object with hashes as keys for faster lookup // TODO: Just create an object with hashes as keys for faster lookup
for (var k = 0; k < this.addressHashes.length; k++) { for (var k = 0; k < this.addressHashes.length; k++) {