You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 lines
90 KiB

!function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.Bitcoin=e():"undefined"!=typeof global?global.Bitcoin=e():"undefined"!=typeof self&&(self.Bitcoin=e())}(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){var base58=require("./base58");var Crypto=require("./crypto-js/crypto");var conv=require("./convert");var util=require("./util");var address_types={prod:0,testnet:111};var p2sh_types={prod:5,testnet:196};var Address=function(bytes,version){if(arguments[0]instanceof Address){this.hash=arguments[0].hash;this.version=arguments[0].version}else if(typeof bytes==="string"){this.hash=bytes.length<=34?base58.checkDecode(bytes):bytes.length<=40?conv.hexToBytes(bytes):util.error("Bad input");this.version=version||this.hash.version||0}else{this.hash=bytes;this.version=version||0}};Address.prototype.toString=function(){return base58.checkEncode(this.hash.slice(0),this.version)};Address.prototype.getHash=function(){return conv.bytesToHex(this.hash)};Address.getVersion=function(string){return base58.decode(string)[0]};Address.validate=function(string){try{base58.checkDecode(string);return true}catch(e){return false}};Address.decodeString=function(string){return base58.checkDecode(string)};module.exports=Address},{"./base58":2,"./convert":4,"./crypto-js/crypto":5,"./util":22}],2:[function(require,module,exports){var BigInteger=require("./jsbn/jsbn");var Crypto=require("./crypto-js/crypto");var conv=require("./convert");var alphabet="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var base=BigInteger.valueOf(58);var positions={};for(var i=0;i<alphabet.length;++i){positions[alphabet[i]]=i}module.exports.encode=function(input){var bi=BigInteger.fromByteArrayUnsigned(input);var chars=[];while(bi.compareTo(base)>=0){var mod=bi.mod(base);chars.push(alphabet[mod.intValue()]);bi=bi.subtract(mod).divide(base)}chars.push(alphabet[bi.intValue()]);for(var i=0;i<input.length;i++){if(input[i]==0){chars.push(alphabet[0])}else break}return chars.reverse().join("")},module.exports.encodeHex=function(input){return conv.bytesToHex(module.exports.encode(input))};module.exports.decode=function(input){var base=BigInteger.valueOf(58);var length=input.length;var num=BigInteger.valueOf(0);var leading_zero=0;var seen_other=false;for(var i=0;i<length;++i){var chr=input[i];var p=positions[chr];if(p===undefined){throw new Error("invalid base58 string: "+input)}num=num.multiply(base).add(BigInteger.valueOf(p));if(chr=="1"&&!seen_other){++leading_zero}else{seen_other=true}}var bytes=num.toByteArrayUnsigned();while(leading_zero-->0){bytes.unshift(0)}return bytes};module.exports.decodeHex=function(input){return module.exports.decode(conv.hexToBytes(input))};module.exports.checkEncode=function(input,vbyte){vbyte=vbyte||0;var front=[vbyte].concat(input);var checksum=Crypto.SHA256(Crypto.SHA256(front,{asBytes:true}),{asBytes:true}).slice(0,4);return module.exports.encode(front.concat(checksum))};module.exports.checkEncodeHex=function(input,vbyte){return conv.bytesToHex(module.exports.encode(input))};module.exports.checkDecode=function(input){var bytes=module.exports.decode(input),front=bytes.slice(0,bytes.length-4),back=bytes.slice(bytes.length-4);var checksum=Crypto.SHA256(Crypto.SHA256(front,{asBytes:true}),{asBytes:true}).slice(0,4);if(""+checksum!=""+back){throw new Error("Checksum failed")}var o=front.slice(1);o.version=front[0];return o};module.exports.checkDecodeHex=function(input){return module.exports.checkDecode(conv.hexToBytes(input))}},{"./convert":4,"./crypto-js/crypto":5,"./jsbn/jsbn":14}],3:[function(require,module,exports){va
}function pointFpNegate(){return new ECPointFp(this.curve,this.x,this.y.negate(),this.z)}function pointFpAdd(b){if(this.isInfinity())return b;if(b.isInfinity())return this;var u=b.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(b.z)).mod(this.curve.q);var v=b.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(b.z)).mod(this.curve.q);if(BigInteger.ZERO.equals(v)){if(BigInteger.ZERO.equals(u)){return this.twice()}return this.curve.getInfinity()}var THREE=new BigInteger("3");var x1=this.x.toBigInteger();var y1=this.y.toBigInteger();var x2=b.x.toBigInteger();var y2=b.y.toBigInteger();var v2=v.square();var v3=v2.multiply(v);var x1v2=x1.multiply(v2);var zu2=u.square().multiply(this.z);var x3=zu2.subtract(x1v2.shiftLeft(1)).multiply(b.z).subtract(v3).multiply(v).mod(this.curve.q);var y3=x1v2.multiply(THREE).multiply(u).subtract(y1.multiply(v3)).subtract(zu2.multiply(u)).multiply(b.z).add(u.multiply(v3)).mod(this.curve.q);var z3=v3.multiply(this.z).multiply(b.z).mod(this.curve.q);return new ECPointFp(this.curve,this.curve.fromBigInteger(x3),this.curve.fromBigInteger(y3),z3)}function pointFpTwice(){if(this.isInfinity())return this;if(this.y.toBigInteger().signum()==0)return this.curve.getInfinity();var THREE=new BigInteger("3");var x1=this.x.toBigInteger();var y1=this.y.toBigInteger();var y1z1=y1.multiply(this.z);var y1sqz1=y1z1.multiply(y1).mod(this.curve.q);var a=this.curve.a.toBigInteger();var w=x1.square().multiply(THREE);if(!BigInteger.ZERO.equals(a)){w=w.add(this.z.square().multiply(a))}w=w.mod(this.curve.q);var x3=w.square().subtract(x1.shiftLeft(3).multiply(y1sqz1)).shiftLeft(1).multiply(y1z1).mod(this.curve.q);var y3=w.multiply(THREE).multiply(x1).subtract(y1sqz1.shiftLeft(1)).shiftLeft(2).multiply(y1sqz1).subtract(w.square().multiply(w)).mod(this.curve.q);var z3=y1z1.square().multiply(y1z1).shiftLeft(3).mod(this.curve.q);return new ECPointFp(this.curve,this.curve.fromBigInteger(x3),this.curve.fromBigInteger(y3),z3)}function pointFpMultiply(k){if(this.isInfinity())return this;if(k.signum()==0)return this.curve.getInfinity();var e=k;var h=e.multiply(new BigInteger("3"));var neg=this.negate();var R=this;var i;for(i=h.bitLength()-2;i>0;--i){R=R.twice();var hBit=h.testBit(i);var eBit=e.testBit(i);if(hBit!=eBit){R=R.add(hBit?this:neg)}}return R}function pointFpMultiplyTwo(j,x,k){var i;if(j.bitLength()>k.bitLength())i=j.bitLength()-1;else i=k.bitLength()-1;var R=this.curve.getInfinity();var both=this.add(x);while(i>=0){R=R.twice();if(j.testBit(i)){if(k.testBit(i)){R=R.add(both)}else{R=R.add(this)}}else{if(k.testBit(i)){R=R.add(x)}}--i}return R}ECPointFp.prototype.getX=pointFpGetX;ECPointFp.prototype.getY=pointFpGetY;ECPointFp.prototype.equals=pointFpEquals;ECPointFp.prototype.isInfinity=pointFpIsInfinity;ECPointFp.prototype.negate=pointFpNegate;ECPointFp.prototype.add=pointFpAdd;ECPointFp.prototype.twice=pointFpTwice;ECPointFp.prototype.multiply=pointFpMultiply;ECPointFp.prototype.multiplyTwo=pointFpMultiplyTwo;function ECCurveFp(q,a,b){this.q=q;this.a=this.fromBigInteger(a);this.b=this.fromBigInteger(b);this.infinity=new ECPointFp(this,null,null)}function curveFpGetQ(){return this.q}function curveFpGetA(){return this.a}function curveFpGetB(){return this.b}function curveFpEquals(other){if(other==this)return true;return this.q.equals(other.q)&&this.a.equals(other.a)&&this.b.equals(other.b)}function curveFpGetInfinity(){return this.infinity}function curveFpFromBigInteger(x){return new ECFieldElementFp(this.q,x)}function curveFpDecodePointHex(s){switch(parseInt(s.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:return null;case 4:case 6:case 7:var len=(s.length-2)/2;var xHex=s.substr(2,len);var yHex=s.substr(len+2,len);return new ECPointFp(this,this.fromBigInteger(new BigInteger(xHex,16)),this.fromBigInteger(new BigInteger(yHex,16)));default:return null}}ECCurveFp.prototype.getQ=curveFpGetQ;ECCurveFp.prototype.getA=curveFpGetA;ECCurveFp.prototype.getB=curveFpGetB;ECCurveFp.prototype.equals=curveFpEquals;ECCurveFp.prototype.getInfinity=curveFpGetInfinity;ECCurveFp.prototy
var a=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC");var b=fromHex("64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1");var n=fromHex("FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831");var h=BigInteger.ONE;var curve=new ECCurveFp(p,a,b);var G=curve.decodePointHex("04"+"188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012"+"07192B95FFC8DA78631011ED6B24CDD573F977A11E794811");return new X9ECParameters(curve,G,n,h)}function secp224r1(){var p=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001");var a=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE");var b=fromHex("B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4");var n=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D");var h=BigInteger.ONE;var curve=new ECCurveFp(p,a,b);var G=curve.decodePointHex("04"+"B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21"+"BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34");return new X9ECParameters(curve,G,n,h)}function secp256k1(){var p=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F");var a=BigInteger.ZERO;var b=fromHex("7");var n=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141");var h=BigInteger.ONE;var curve=new ECCurveFp(p,a,b);var G=curve.decodePointHex("04"+"79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"+"483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8");return new X9ECParameters(curve,G,n,h)}function secp256r1(){var p=fromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF");var a=fromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC");var b=fromHex("5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B");var n=fromHex("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551");var h=BigInteger.ONE;var curve=new ECCurveFp(p,a,b);var G=curve.decodePointHex("04"+"6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296"+"4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5");return new X9ECParameters(curve,G,n,h)}function getSECCurveByName(name){if(name=="secp128r1")return secp128r1();if(name=="secp160k1")return secp160k1();if(name=="secp160r1")return secp160r1();if(name=="secp192k1")return secp192k1();if(name=="secp192r1")return secp192r1();if(name=="secp224r1")return secp224r1();if(name=="secp256k1")return secp256k1();if(name=="secp256r1")return secp256r1();return null}module.exports=getSECCurveByName},{"./ec":13,"./jsbn":14}],18:[function(require,module,exports){var Crypto=require("./crypto-js/crypto");var ecdsa=require("./ecdsa");var conv=require("./convert");var util=require("./util");var Message={};Message.magicPrefix="Bitcoin Signed Message:\n";Message.makeMagicMessage=function(message){var magicBytes=conv.stringToBytes(Message.magicPrefix);var messageBytes=conv.stringToBytes(message);var buffer=[];buffer=buffer.concat(util.numToVarInt(magicBytes.length));buffer=buffer.concat(magicBytes);buffer=buffer.concat(util.numToVarInt(messageBytes.length));buffer=buffer.concat(messageBytes);return buffer};Message.getHash=function(message){var buffer=Message.makeMagicMessage(message);return Crypto.SHA256(Crypto.SHA256(buffer,{asBytes:true}),{asBytes:true})};Message.signMessage=function(key,message,compressed){var hash=Message.getHash(message);var sig=key.sign(hash);var obj=ecdsa.parseSig(sig);var address=key.getBitcoinAddress().toString();var i=ecdsa.calcPubkeyRecoveryParam(address,obj.r,obj.s,hash);i+=27;if(compressed)i+=4;var rBa=obj.r.toByteArrayUnsigned();var sBa=obj.s.toByteArrayUnsigned();while(rBa.length<32)rBa.unshift(0);while(sBa.length<32)sBa.unshift(0);sig=[i].concat(rBa).concat(sBa);return conv.bytesToHex(sig)};Message.verifyMessage=function(address,sig,message){sig=conv.hexToBytes(sig);sig=ecdsa.parseSigCompact(sig);var hash=Message.getHash(message);var isCompressed=!!(sig.i&4);var pubKey=ecdsa.recoverPubKey(sig.r,sig.s,hash,sig.i);pubKey.setCompressed(isCompressed);var expectedAddress=pubKey.getBitcoinAddress().toString();return address===expectedAddress};module.exports=Message},{"./co