diff --git a/build/bitcoinjs-min.js b/build/bitcoinjs-min.js index 291e4f7..45dc4a8 100644 --- a/build/bitcoinjs-min.js +++ b/build/bitcoinjs-min.js @@ -1,5 +1,5 @@ /** - * BitcoinJS-lib v0.1.0-default + * BitcoinJS-lib v0.1.2-default * Copyright (c) 2011 BitcoinJS Project * * This program is free software; you can redistribute it and/or modify @@ -20,7 +20,7 @@ BigInteger.valueOf=nbv,BigInteger.prototype.toByteArrayUnsigned=function(){var a (function(a){a.Base58={alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",validRegex:/^[1-9A-HJ-NP-Za-km-z]+$/,base:BigInteger.valueOf(58),encode:function(a){var c=BigInteger.fromByteArrayUnsigned(a),d=[];while(c.compareTo(b.base)>=0){var e=c.mod(b.base);d.unshift(b.alphabet[e.intValue()]),c=c.subtract(e).divide(b.base)}d.unshift(b.alphabet[c.intValue()]);for(var f=0;f=0;e--){var f=b.alphabet.indexOf(a[e]);if(f<0)throw"Invalid character";c=c.add(BigInteger.valueOf(f).multiply(b.base.pow(a.length-1-e))),a[e]=="1"?d++:d=0}var g=c.toByteArrayUnsigned();while(d-->0)g.unshift(0);return g}};var b=a.Base58})("undefined"!=typeof Bitcoin?Bitcoin:module.exports); Bitcoin.Address=function(a){"string"==typeof a&&(a=Bitcoin.Address.decodeString(a)),this.hash=a,this.version=0},Bitcoin.Address.prototype.toString=function(){var a=this.hash.slice(0);a.unshift(this.version);var b=Crypto.SHA256(Crypto.SHA256(a,{asBytes:!0}),{asBytes:!0}),c=a.concat(b.slice(0,4));return Bitcoin.Base58.encode(c)},Bitcoin.Address.prototype.getHashBase64=function(){return Crypto.util.bytesToBase64(this.hash)},Bitcoin.Address.decodeString=function(a){var b=Bitcoin.Base58.decode(a),c=b.slice(0,21),d=Crypto.SHA256(Crypto.SHA256(c,{asBytes:!0}),{asBytes:!0});if(d[0]!=b[21]||d[1]!=b[22]||d[2]!=b[23]||d[3]!=b[24])throw"Checksum validation failed!";var e=c.shift();if(e!=0)throw"Version "+e+" not supported!";return c}; function integerToBytes(a,b){var c=a.toByteArrayUnsigned();if(bc.length)c.unshift(0);return c}function dmp(a){return a instanceof BigInteger||(a=a.toBigInteger()),Crypto.util.bytesToHex(a.toByteArrayUnsigned())}ECFieldElementFp.prototype.getByteLength=function(){return Math.floor((this.toBigInteger().bitLength()+7)/8)},ECPointFp.prototype.getEncoded=function(a){var b=this.getX().toBigInteger(),c=this.getY().toBigInteger(),d=integerToBytes(b,32);return a?c.isEven()?d.unshift(2):d.unshift(3):(d.unshift(4),d=d.concat(integerToBytes(c,32))),d},ECPointFp.decodeFrom=function(a,b){var c=b[0],d=b.length-1,e=b.slice(1,1+d/2),f=b.slice(1+d/2,1+d);e.unshift(0),f.unshift(0);var g=new BigInteger(e),h=new BigInteger(f);return new ECPointFp(a,a.fromBigInteger(g),a.fromBigInteger(h))},ECPointFp.prototype.add2D=function(a){if(this.isInfinity())return a;if(a.isInfinity())return this;if(this.x.equals(a.x))return this.y.equals(a.y)?this.twice():this.curve.getInfinity();var b=a.x.subtract(this.x),c=a.y.subtract(this.y),d=c.divide(b),e=d.square().subtract(this.x).subtract(a.x),f=d.multiply(this.x.subtract(e)).subtract(this.y);return new ECPointFp(this.curve,e,f)},ECPointFp.prototype.twice2D=function(){if(this.isInfinity())return this;if(this.y.toBigInteger().signum()==0)return this.curve.getInfinity();var a=this.curve.fromBigInteger(BigInteger.valueOf(2)),b=this.curve.fromBigInteger(BigInteger.valueOf(3)),c=this.x.square().multiply(b).add(this.curve.a).divide(this.y.multiply(a)),d=c.square().subtract(this.x.multiply(a)),e=c.multiply(this.x.subtract(d)).subtract(this.y);return new ECPointFp(this.curve,d,e)},ECPointFp.prototype.multiply2D=function(a){if(this.isInfinity())return this;if(a.signum()==0)return this.curve.getInfinity();var b=a,c=b.multiply(new BigInteger("3")),d=this.negate(),e=this,f;for(f=c.bitLength()-2;f>0;--f){e=e.twice();var g=c.testBit(f),h=b.testBit(f);g!=h&&(e=e.add2D(g?this:d))}return e},ECPointFp.prototype.isOnCurve=function(){var a=this.getX().toBigInteger(),b=this.getY().toBigInteger(),c=this.curve.getA().toBigInteger(),d=this.curve.getB().toBigInteger(),e=this.curve.getQ(),f=b.multiply(b).mod(e),g=a.multiply(a).multiply(a).add(c.multiply(a)).add(d).mod(e);return f.equals(g)},ECPointFp.prototype.validate=function(){var a=this.curve.getQ();if(this.isInfinity())throw new Error("Point is at infinity.");var b=this.getX().toBigInteger(),c=this.getY().toBigInteger();if(b.compareTo(BigInteger.ONE)<0||b.compareTo(a.subtract(BigInteger.ONE))>0)throw new Error("x coordinate out of bounds");if(c.compareTo(BigInteger.ONE)<0||c.compareTo(a.subtract(BigInteger.ONE))>0)throw new Error("y coordinate out of bounds");if(!this.isOnCurve())throw new Error("Point is not on the curve.");if(this.multiply(a).isInfinity())throw new Error("Point is not a scalar multiple of G.");return!0},Bitcoin.ECDSA=function(){function c(a,b,c,d){var e=Math.max(b.bitLength(),d.bitLength()),f=a.add2D(c),g=a.curve.getInfinity();for(var h=e-1;h>=0;--h)g=g.twice2D(),g.z=BigInteger.ONE,b.testBit(h)?d.testBit(h)?g=g.add2D(f):g=g.add2D(a):d.testBit(h)&&(g=g.add2D(c));return g}var a=getSECCurveByName("secp256k1"),b=new SecureRandom,d={getBigRandom:function(a){return(new BigInteger(a.bitLength(),b)).mod(a.subtract(BigInteger.ONE)).add(BigInteger.ONE)},sign:function(b,c){var e=c,f=a.getN(),g=BigInteger.fromByteArrayUnsigned(b);do var h=d.getBigRandom(f),i=a.getG(),j=i.multiply(h),k=j.getX().toBigInteger().mod(f);while(k.compareTo(BigInteger.ZERO)<=0);var l=h.modInverse(f).multiply(g.add(e.multiply(k))).mod(f);return d.serializeSig(k,l)},verify:function(b,e,f){var g=d.parseSig(e),h=g.r,i=g.s,j=a.getN(),k=BigInteger.fromByteArrayUnsigned(b);if(h.compareTo(BigInteger.ONE)<0||h.compareTo(j)>=0)return!1;if(i.compareTo(BigInteger.ONE)<0||i.compareTo(j)>=0)return!1;var l=i.modInverse(j),m=k.multiply(l).mod(j),n=h.multiply(l).mod(j),o=a.getG(),p=ECPointFp.decodeFrom(a.getCurve(),f),q=c(o,m,p,n),r=q.x.toBigInteger().mod(j);return r.equals(h)},serializeSig:function(a,b){var c=a.toByteArrayUnsigned(),d=b.toByteArrayUnsigned(),e=[];return e.push(2),e.push(c.length),e=e.concat(c),e.push(2),e.push(d.length),e=e.concat(d),e.unshift(e.length),e.unshift(48),e},parseSig:function(a){var b;if(a[0]!=48)throw new Error("Signature not a valid DERSequence");b=2;if(a[b]!=2)throw new Error("First element in signature must be a DERInteger");var c=a.slice(b+2,b+2+a[b+1]);b+=2+a[b+1];if(a[b]!=2)throw new Error("Second element in signature must be a DERInteger");var d=a.slice(b+2,b+2+a[b+1]);b+=2+a[b+1];var e=BigInteger.fromByteArrayUnsigned(c),f=BigInteger.fromByteArrayUnsigned(d);return{r:e,s:f}}};return d}(); -Bitcoin.ECKey=function(){var a=Bitcoin.ECDSA,b=getSECCurveByName("secp256k1"),c=new SecureRandom,d=function(c){if(!c){var d=b.getN();this.priv=a.getBigRandom(d)}else c instanceof BigInteger?this.priv=c:Bitcoin.Util.isArray(c)?this.priv=BigInteger.fromByteArrayUnsigned(c):"string"==typeof c&&(this.priv=BigInteger.fromByteArrayUnsigned(Crypto.util.base64ToBytes(c)))};return d.prototype.getPub=function(){return this.pub?this.pub:this.pub=b.getG().multiply(this.priv).getEncoded()},d.prototype.getPubKeyHash=function(){return this.pubKeyHash?this.pubKeyHash:this.pubKeyHash=Bitcoin.Util.sha256ripe160(this.getPub())},d.prototype.getBitcoinAddress=function(){var a=this.getPubKeyHash(),b=new Bitcoin.Address(a);return b},d.prototype.setPub=function(a){this.pub=a},d.prototype.toString=function(a){return a==="base64"?Crypto.util.bytesToBase64(this.priv.toByteArrayUnsigned()):Crypto.util.bytesToHex(this.priv.toByteArrayUnsigned())},d.prototype.sign=function(b){return a.sign(b,this.priv)},d.prototype.verify=function(b,c){return a.verify(b,c,this.getPub())},d}(); +Bitcoin.ECKey=function(){var a=Bitcoin.ECDSA,b=getSECCurveByName("secp256k1"),c=new SecureRandom,d=function(c){if(!c){var e=b.getN();this.priv=a.getBigRandom(e)}else c instanceof BigInteger?this.priv=c:Bitcoin.Util.isArray(c)?this.priv=BigInteger.fromByteArrayUnsigned(c):"string"==typeof c&&(c.length==51&&c[0]=="5"?this.priv=BigInteger.fromByteArrayUnsigned(d.decodeString(c)):this.priv=BigInteger.fromByteArrayUnsigned(Crypto.util.base64ToBytes(c)))};return d.prototype.getPub=function(){return this.pub?this.pub:this.pub=b.getG().multiply(this.priv).getEncoded()},d.prototype.getPubKeyHash=function(){return this.pubKeyHash?this.pubKeyHash:this.pubKeyHash=Bitcoin.Util.sha256ripe160(this.getPub())},d.prototype.getBitcoinAddress=function(){var a=this.getPubKeyHash(),b=new Bitcoin.Address(a);return b},d.prototype.getExportedPrivateKey=function(){var a=this.priv.toByteArrayUnsigned();a.unshift(128);var b=Crypto.SHA256(Crypto.SHA256(a,{asBytes:!0}),{asBytes:!0}),c=a.concat(b.slice(0,4));return Bitcoin.Base58.encode(c)},d.prototype.setPub=function(a){this.pub=a},d.prototype.toString=function(a){return a==="base64"?Crypto.util.bytesToBase64(this.priv.toByteArrayUnsigned()):Crypto.util.bytesToHex(this.priv.toByteArrayUnsigned())},d.prototype.sign=function(b){return a.sign(b,this.priv)},d.prototype.verify=function(b,c){return a.verify(b,c,this.getPub())},d.decodeString=function(a){var b=Bitcoin.Base58.decode(a),c=b.slice(0,33),d=Crypto.SHA256(Crypto.SHA256(c,{asBytes:!0}),{asBytes:!0});if(d[0]!=b[33]||d[1]!=b[34]||d[2]!=b[35]||d[3]!=b[36])throw"Checksum validation failed!";var e=c.shift();if(e!=128)throw"Version "+e+" not supported!";return c},d}(); (function(){var a=Bitcoin.Opcode=function(a){this.code=a};a.prototype.toString=function(){return a.reverseMap[this.code]},a.map={OP_0:0,OP_FALSE:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_1:81,OP_TRUE:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_NOP2:177,OP_NOP3:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255},a.reverseMap=[];for(var b in a.map)a.reverseMap[a.map[b]]=b})(); (function(){var Opcode=Bitcoin.Opcode;for(var i in Opcode.map)eval("var "+i+" = "+Opcode.map[i]+";");var Script=Bitcoin.Script=function(a){if(!a)this.buffer=[];else if("string"==typeof a)this.buffer=Crypto.util.base64ToBytes(a);else if(Bitcoin.Util.isArray(a))this.buffer=a;else if(a instanceof Script)this.buffer=a.buffer;else throw new Error("Invalid script");this.parse()};Script.prototype.parse=function(){function c(c){a.chunks.push(a.buffer.slice(b,b+c)),b+=c}var a=this;this.chunks=[];var b=0;while(b=240&&(d=d<<8|this.buffer[b++]);var e;d>0&&d>>8&255)):(this.buffer.push(OP_PUSHDATA4),this.buffer.push(a.length&255),this.buffer.push(a.length>>>8&255),this.buffer.push(a.length>>>16&255),this.buffer.push(a.length>>>24&255)),this.buffer=this.buffer.concat(a),this.chunks.push(a)},Script.createOutputScript=function(a){var b=new Script;return b.writeOp(OP_DUP),b.writeOp(OP_HASH160),b.writeBytes(a.hash),b.writeOp(OP_EQUALVERIFY),b.writeOp(OP_CHECKSIG),b},Script.prototype.extractAddresses=function(a){switch(this.getOutType()){case"Address":return a.push(new Address(this.chunks[2])),1;case"Pubkey":return a.push(new Address(Util.sha256ripe160(this.chunks[0]))),1;case"Multisig":for(var b=1;b=0;g--){var h=this.outs[g],i=h.script.simpleOutPubKeyHash();a.hasHash(i)?e=i:c=!1,d=i}for(var g=this.ins.length-1;g>=0;g--){var j=this.ins[g];f=j.script.simpleInPubKeyHash();if(!a.hasHash(f)){b=!1;break}}var k=this.calcImpact(a),l={};return l.impact=k,k.sign>0&&k.value.compareTo(BigInteger.ZERO)>0?(l.type="recv",l.addr=new Bitcoin.Address(e)):b&&c?l.type="self":b?(l.type="sent",l.addr=new Bitcoin.Address(d)):l.type="other",l}return null},b.prototype.getDescription=function(a){var b=this.analyze(a);if(!b)return"";switch(b.type){case"recv":return"Received with "+b.addr;case"sent":return"Payment to "+b.addr;case"self":return"Payment to yourself";case"other":default:return""}},b.prototype.getTotalOutValue=function(){var a=BigInteger.ZERO;for(var b=0;b=0?{sign:1,value:b.subtract(f)}:{sign:-1,value:f.subtract(b)}}return BigInteger.ZERO};var h=Bitcoin.TransactionIn=function(b){this.outpoint=b.outpoint,b.script instanceof a?this.script=b.script:this.script=new a(b.script),this.sequence=b.sequence};h.prototype.clone=function(){var a=new h({outpoint:{hash:this.outpoint.hash,index:this.outpoint.index},script:this.script.clone(),sequence:this.sequence});return a};var i=Bitcoin.TransactionOut=function(b){b.script instanceof a?this.script=b.script:this.script=new a(b.script);if(Bitcoin.Util.isArray(b.value))this.value=b.value;else if("string"==typeof b.value){var c=(new BigInteger(b.value,10)).toString(16);while(c.length<16)c="0"+c;this.value=Crypto.util.hexToBytes(c)}};i.prototype.clone=function(){var a=new i({script:this.script.clone(),value:this.value.slice(0)});return a}})(); diff --git a/package.json b/package.json index d73f073..f6b2f39 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bitcoinjs-lib", - "version": "0.1.1", + "version": "0.1.2", "description": "Client-side Bitcoin JavaScript library", "keywords": [