Browse Source

Removed direct references to Bitcoin

hk-custom-address
vub 11 years ago
parent
commit
038f8d5d99
  1. 6
      bitcoinjs-min.js
  2. 2
      src/eckey.js
  3. 8
      src/script.js
  4. 28
      src/transaction.js
  5. 4
      src/txdb.js
  6. 2
      src/wallet.js

6
bitcoinjs-min.js

File diff suppressed because one or more lines are too long

2
src/eckey.js

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

8
src/script.js

@ -155,9 +155,9 @@ Script.prototype.simpleOutHash = function ()
case 'Address':
return this.chunks[2];
case 'Pubkey':
return Bitcoin.Util.sha256ripe160(this.chunks[0]);
return util.sha256ripe160(this.chunks[0]);
case 'Multisig':
return Bitcoin.Util.sha256ripe160(this.buffer);
return util.sha256ripe160(this.buffer);
default:
throw new Error("Encountered non-standard scriptPubKey: " + this.getOutType());
}
@ -198,7 +198,7 @@ Script.prototype.simpleOutPubKeyHash = Script.prototype.simpleOutHash;
Script.prototype.getInType = function ()
{
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.
// TODO: We could also check that the length of the data is correct.
return 'Pubkey';
@ -261,7 +261,7 @@ Script.prototype.simpleInPubKey = function ()
*/
Script.prototype.simpleInHash = function ()
{
return Bitcoin.Util.sha256ripe160(this.simpleInPubKey());
return util.sha256ripe160(this.simpleInPubKey());
};
/**

28
src/transaction.js

@ -3,6 +3,10 @@ var Script = require('./script');
var util = require('./util');
var conv = require('./convert');
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) {
this.version = 1;
@ -265,7 +269,7 @@ Transaction.prototype.clone = function ()
* This method was unable to detect what the transaction does. Either it
*/
Transaction.prototype.analyze = function (wallet) {
if (!(wallet instanceof Bitcoin.Wallet)) return null;
if (!(wallet instanceof Wallet)) return null;
var allFromMe = true,
allToMe = true,
@ -300,7 +304,7 @@ Transaction.prototype.analyze = function (wallet) {
if (impact.sign > 0 && impact.value.compareTo(BigInteger.ZERO) > 0) {
analysis.type = 'recv';
analysis.addr = new Bitcoin.Address(firstMeRecvHash);
analysis.addr = new Address(firstMeRecvHash);
} else if (allFromMe && allToMe) {
analysis.type = 'self';
} else if (allFromMe) {
@ -308,7 +312,7 @@ Transaction.prototype.analyze = function (wallet) {
// TODO: Right now, firstRecvHash is the first output, which - if the
// transaction was not generated by this library could be the
// change address.
analysis.addr = new Bitcoin.Address(firstRecvHash);
analysis.addr = new Address(firstRecvHash);
} else {
analysis.type = "other";
}
@ -378,7 +382,7 @@ Transaction.prototype.getTotalOutValue = function () {
* @returns Object Impact on 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
var valueOut = BigInteger.ZERO;
@ -474,13 +478,13 @@ Transaction.deserialize = function(buffer) {
Transaction.prototype.sign = function(index, key, type) {
type = type || SIGHASH_ALL;
key = new Bitcoin.ECKey(key);
key = new ECKey(key);
var pub = key.getPub(),
hash160 = Bitcoin.Util.sha256ripe160(pub),
script = Bitcoin.Script.createOutputScript(new Bitcoin.Address(hash160)),
hash160 = util.sha256ripe160(pub),
script = Script.createOutputScript(new Address(hash160)),
hash = this.hashTransactionForSignature( script, index, 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) {
script = new Bitcoin.Script(script);
key = new Bitcoin.ECKey(key);
script = new Script(script);
key = new ECKey(key);
type = type || SIGHASH_ALL;
var hash = this.hashTransactionForSignature(script, index, 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.validateSig = function(index,script,sig,pub) {
script = new Bitcoin.Script(script);
script = new Script(script);
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));
}

4
src/txdb.js

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

2
src/wallet.js

@ -329,7 +329,7 @@ Wallet.prototype.clearTransactions = function () {
* Check to see if a pubKeyHash belongs to this wallet.
*/
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
for (var k = 0; k < this.addressHashes.length; k++) {

Loading…
Cancel
Save