2013-10-21 20:00:31 +02:00
|
|
|
!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(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":3,"./crypto-js/crypto":4,"./util":19}],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(Crypto.util.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(Crypto.util.hexToBytes(input))}},{"./convert":3,"./crypto-js/crypto":4,"./jsbn/jsbn":11}],3:[function(require,module,exports){var base64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";String.pr
|
|
|
|
return}self.t=0;self.s=0;var i=s.length,mi=false,sh=0;while(--i>=0){var x=k==8?s[i]&255:intAt(s,i);if(x<0){if(s.charAt(i)=="-")mi=true;continue}mi=false;if(sh==0)self[self.t++]=x;else if(sh+k>self.DB){self[self.t-1]|=(x&(1<<self.DB-sh)-1)<<sh;self[self.t++]=x>>self.DB-sh}else self[self.t-1]|=x<<sh;sh+=k;if(sh>=self.DB)sh-=self.DB}if(k==8&&(s[0]&128)!=0){self.s=-1;if(sh>0)self[self.t-1]|=(1<<self.DB-sh)-1<<sh}self.clamp();if(mi)BigInteger.ZERO.subTo(self,self)}function bnpClamp(){var c=this.s&this.DM;while(this.t>0&&this[this.t-1]==c)--this.t}function bnToString(b){var self=this;if(self.s<0)return"-"+self.negate().toString(b);var k;if(b==16)k=4;else if(b==8)k=3;else if(b==2)k=1;else if(b==32)k=5;else if(b==4)k=2;else return self.toRadix(b);var km=(1<<k)-1,d,m=false,r="",i=self.t;var p=self.DB-i*self.DB%k;if(i-->0){if(p<self.DB&&(d=self[i]>>p)>0){m=true;r=int2char(d)}while(i>=0){if(p<k){d=(self[i]&(1<<p)-1)<<k-p;d|=self[--i]>>(p+=self.DB-k)}else{d=self[i]>>(p-=k)&km;if(p<=0){p+=self.DB;--i}}if(d>0)m=true;if(m)r+=int2char(d)}}return m?r:"0"}function bnNegate(){var r=nbi();BigInteger.ZERO.subTo(this,r);return r}function bnAbs(){return this.s<0?this.negate():this}function bnCompareTo(a){var r=this.s-a.s;if(r!=0)return r;var i=this.t;r=i-a.t;if(r!=0)return this.s<0?-r:r;while(--i>=0)if((r=this[i]-a[i])!=0)return r;return 0}function nbits(x){var r=1,t;if((t=x>>>16)!=0){x=t;r+=16}if((t=x>>8)!=0){x=t;r+=8}if((t=x>>4)!=0){x=t;r+=4}if((t=x>>2)!=0){x=t;r+=2}if((t=x>>1)!=0){x=t;r+=1}return r}function bnBitLength(){if(this.t<=0)return 0;return this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}function bnpDLShiftTo(n,r){var i;for(i=this.t-1;i>=0;--i)r[i+n]=this[i];for(i=n-1;i>=0;--i)r[i]=0;r.t=this.t+n;r.s=this.s}function bnpDRShiftTo(n,r){for(var i=n;i<this.t;++i)r[i-n]=this[i];r.t=Math.max(this.t-n,0);r.s=this.s}function bnpLShiftTo(n,r){var self=this;var bs=n%self.DB;var cbs=self.DB-bs;var bm=(1<<cbs)-1;var ds=Math.floor(n/self.DB),c=self.s<<bs&self.DM,i;for(i=self.t-1;i>=0;--i){r[i+ds+1]=self[i]>>cbs|c;c=(self[i]&bm)<<bs}for(i=ds-1;i>=0;--i)r[i]=0;r[ds]=c;r.t=self.t+ds+1;r.s=self.s;r.clamp()}function bnpRShiftTo(n,r){var self=this;r.s=self.s;var ds=Math.floor(n/self.DB);if(ds>=self.t){r.t=0;return}var bs=n%self.DB;var cbs=self.DB-bs;var bm=(1<<bs)-1;r[0]=self[ds]>>bs;for(var i=ds+1;i<self.t;++i){r[i-ds-1]|=(self[i]&bm)<<cbs;r[i-ds]=self[i]>>bs}if(bs>0)r[self.t-ds-1]|=(self.s&bm)<<cbs;r.t=self.t-ds;r.clamp()}function bnpSubTo(a,r){var self=this;var i=0,c=0,m=Math.min(a.t,self.t);while(i<m){c+=self[i]-a[i];r[i++]=c&self.DM;c>>=self.DB}if(a.t<self.t){c-=a.s;while(i<self.t){c+=self[i];r[i++]=c&self.DM;c>>=self.DB}c+=self.s}else{c+=self.s;while(i<a.t){c-=a[i];r[i++]=c&self.DM;c>>=self.DB}c-=a.s}r.s=c<0?-1:0;if(c<-1)r[i++]=self.DV+c;else if(c>0)r[i++]=c;r.t=i;r.clamp()}function bnpMultiplyTo(a,r){var x=this.abs(),y=a.abs();var i=x.t;r.t=i+y.t;while(--i>=0)r[i]=0;for(i=0;i<y.t;++i)r[i+x.t]=x.am(0,y[i],r,i,0,x.t);r.s=0;r.clamp();if(this.s!=a.s)BigInteger.ZERO.subTo(r,r)}function bnpSquareTo(r){var x=this.abs();var i=r.t=2*x.t;while(--i>=0)r[i]=0;for(i=0;i<x.t-1;++i){var c=x.am(i,x[i],r,2*i,0,1);if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1))>=x.DV){r[i+x.t]-=x.DV;r[i+x.t+1]=1}}if(r.t>0)r[r.t-1]+=x.am(i,x[i],r,2*i,0,1);r.s=0;r.clamp()}function bnpDivRemTo(m,q,r){var self=this;var pm=m.abs();if(pm.t<=0)return;var pt=self.abs();if(pt.t<pm.t){if(q!=null)q.fromInt(0);if(r!=null)self.copyTo(r);return}if(r==null)r=nbi();var y=nbi(),ts=self.s,ms=m.s;var nsh=self.DB-nbits(pm[pm.t-1]);if(nsh>0){pm.lShiftTo(nsh,y);pt.lShiftTo(nsh,r)}else{pm.copyTo(y);pt.copyTo(r)}var ys=y.t;var y0=y[ys-1];if(y0==0)return;var yt=y0*(1<<self.F1)+(ys>1?y[ys-2]>>self.F2:0);var d1=self.FV/yt,d2=(1<<self.F1)/yt,e=1<<self.F2;var i=r.t,j=i-ys,t=q==null?nbi():q;y.dlShiftTo(j,t);if(r.compareTo(t)>=0){r[r.t++]=1;r.subTo(t,r)}BigInteger.ONE.dlShiftTo(ys,t);t.subTo(y,y);while(y.t<ys)y[y.t++]=0;while(--j>=0){var qd=r[--i]==y0?self.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);if((r[i]+=y.am(0,qd,r,j,0,ys))<qd){y.dlShiftTo(j,t);r.subTo(t,r);while(r[i]<--qd)r.subTo(t,r)}}if(q!=null)
|
|
|
|
if(!address.version){script.writeOp(Opcode.map.OP_DUP);script.writeOp(Opcode.map.OP_HASH160);script.writeBytes(address.hash);script.writeOp(Opcode.map.OP_EQUALVERIFY);script.writeOp(Opcode.map.OP_CHECKSIG)}else{script.writeOp(Opcode.map.OP_HASH160);script.writeBytes(address.hash);script.writeOp(Opcode.map.OP_EQUAL)}return script};Script.prototype.extractPubkeys=function(){return this.chunks.filter(function(chunk){return chunk[0]==4&&chunk.length==65||chunk[0]<4&&chunk.length==33})};Script.createMultiSigOutputScript=function(m,pubkeys){var script=new Script;pubkeys=pubkeys.sort();script.writeOp(Opcode.map.OP_1+m-1);for(var i=0;i<pubkeys.length;++i){script.writeBytes(pubkeys[i])}script.writeOp(Opcode.map.OP_1+pubkeys.length-1);script.writeOp(Opcode.map.OP_CHECKMULTISIG);return script};Script.createInputScript=function(signature,pubKey){var script=new Script;script.writeBytes(signature);script.writeBytes(pubKey);return script};Script.createMultiSigInputScript=function(signatures,script){script=new Script(script);var k=script.chunks[0][0];if(signatures.length<k)return false;var inScript=new Script;inScript.writeOp(Opcode.map.OP_0);signatures.map(inScript.writeBytes.bind(inScript));inScript.writeBytes(script.buffer);return inScript};Script.prototype.clone=function(){return new Script(this.buffer)};module.exports=Script},{"./address":1,"./convert":3,"./opcode":16,"./util":19}],18:[function(require,module,exports){var BigInteger=require("./jsbn/jsbn");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;this.lock_time=0;this.ins=[];this.outs=[];this.timestamp=null;this.block=null;if(doc){if(doc.hash)this.hash=doc.hash;if(doc.version)this.version=doc.version;if(doc.lock_time)this.lock_time=doc.lock_time;if(doc.ins&&doc.ins.length){for(var i=0;i<doc.ins.length;i++){this.addInput(new TransactionIn(doc.ins[i]))}}if(doc.outs&&doc.outs.length){for(var i=0;i<doc.outs.length;i++){this.addOutput(new TransactionOut(doc.outs[i]))}}if(doc.timestamp)this.timestamp=doc.timestamp;if(doc.block)this.block=doc.block}};Transaction.objectify=function(txs){var objs=[];for(var i=0;i<txs.length;i++){objs.push(new Transaction(txs[i]))}return objs};Transaction.prototype.addInput=function(tx,outIndex){if(arguments[0]instanceof TransactionIn){this.ins.push(arguments[0])}else{this.ins.push(new TransactionIn({outpoint:{hash:tx.hash,index:outIndex},script:new Script,sequence:4294967295}))}};Transaction.prototype.addOutput=function(address,value){if(arguments[0]instanceof TransactionOut){this.outs.push(arguments[0])}else{this.outs.push(new TransactionOut({value:value,script:Script.createOutputScript(address)}))}};var bytesToWords=function(bytes){for(var words=[],i=0,b=0;i<bytes.length;i++,b+=8)words[b>>>5]|=bytes[i]<<24-b%32;return words};var wordsToBytes=function(words){for(var bytes=[],b=0;b<words.length*32;b+=8)bytes.push(words[b>>>5]>>>24-b%32&255);return bytes};Transaction.prototype.serialize=function(){var buffer=[];buffer=buffer.concat(util.numToBytes(parseInt(this.version),4));buffer=buffer.concat(util.numToVarInt(this.ins.length));for(var i=0;i<this.ins.length;i++){var txin=this.ins[i];buffer=buffer.concat(conv.hexToBytes(txin.outpoint.hash).reverse());buffer=buffer.concat(util.numToBytes(parseInt(txin.outpoint.index),4));var scriptBytes=txin.script.buffer;buffer=buffer.concat(util.numToVarInt(scriptBytes.length));buffer=buffer.concat(scriptBytes);buffer=buffer.concat(util.numToBytes(parseInt(txin.sequence),4))}buffer=buffer.concat(util.numToVarInt(this.outs.length));for(var i=0;i<this.outs.length;i++){var txout=this.outs[i];buffer=buffer.concat(util.numToBytes(txout.value,8));var scriptBytes=txout.script.buffer;buffer=buffer.concat(util.numToVarInt(scriptBytes.length));buffer=buffer.concat(scriptBytes)}buffer=buffer.concat(util.numToBytes(parseInt(this.lock_time),4));return buffer};var OP_CODESEPARATOR=171;va
|