gamegold 5.1.0 → 5.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -196,7 +196,7 @@ let i=[];[r(557),r(558),r(559),r(560),r(561),r(562),r(563),r(564),r(565),r(566),
196
196
  * pkg.js - package constants
197
197
  * Copyright (c) 2019-2022, Bookman Software (MIT License).
198
198
  * https://github.com/bookmansoft/gamegold
199
- */t.protocol="vallnet",t.version="v5.0.11",t.url="https://github.com/bookmansoft/gamegold"},function(e,t,r){"use strict";
199
+ */t.protocol="vallnet",t.version="v5.1.2",t.url="https://github.com/bookmansoft/gamegold"},function(e,t,r){"use strict";
200
200
  /*!
201
201
  * common.js - p2p constants for vallnet
202
202
  * Copyright (c) 2019-2022, Bookman Software (MIT License).
@@ -314,7 +314,7 @@ const i=r(20).opcodes;function a(e){let t=null;var r=a.list[e.type];return new(r
314
314
  * merkleblock.js - merkleblock object for vallnet
315
315
  * Copyright (c) 2019-2022, Bookman Software (MIT License).
316
316
  * https://github.com/bookmansoft/gamegold
317
- */const i=r(0),a=r(2),s=r(1),n=r(4),o=r(3),c=r(6),u=r(7);var h=r(115);const l=r(89),p=Buffer.from([0]);class d extends h{constructor(e){super(),this.txs=[],this.hashes=[],this.flags=p,this.totalTX=0,this._tree=null,e&&this.fromOptions(e)}fromOptions(e){if(this.parseOptions(e),i(e,"MerkleBlock data is required."),i(Array.isArray(e.hashes)),i(Buffer.isBuffer(e.flags)),i(a.isU32(e.totalTX)),e.hashes)for(var t of e.hashes)"string"==typeof t&&(t=Buffer.from(t,"hex")),i(Buffer.isBuffer(t)),this.hashes.push(t);return e.flags&&(i(Buffer.isBuffer(e.flags)),this.flags=e.flags),null!=e.totalTX&&(i(a.isU32(e.totalTX)),this.totalTX=e.totalTX),this}static fromOptions(e){return(new d).fromOptions(e)}refresh(e){if(this._refresh(),this._tree=null,e)for(const e of this.txs)e.refresh()}hasTX(e){return-1!==this.indexOf(e)}indexOf(e){return null==(e=this.getTree().map.get(e))?-1:e}verifyBody(){var[e]=this.checkBody();return e}checkBody(){return this.getTree().root!==this.merkleRoot?[!1,"bad-txnmrklroot",100]:[!0,"valid",0]}getTree(){if(!this._tree)try{this._tree=this.extractTree()}catch(e){this._tree=new f}return this._tree}extractTree(){const e=[],t=[],r=new Map,i=this.hashes,a=this.flags,s=this.totalTX;let n=0,h=0,l=!1,p=0;const d=e=>s+(1<<e)-1>>>e,m=(s,u)=>{if(n>=8*a.length)return l=!0,o.ZERO_HASH;var p,f=a[n/8|0]>>>n%8&1;if(n++,0===s||!f)return h>=i.length?(l=!0,o.ZERO_HASH):(p=i[h++],0===s&&f&&(f=p.toString("hex"),e.push(p),t.push(u),r.set(f,u)),p);let g;return f=m(s-1,2*u),2*u+1<d(s-1)?(g=m(s-1,2*u+1)).equals(f)&&(l=!0):g=f,c.root256(f,g)};if(0===s)throw new Error("Zero transactions.");if(s>(u.MAX_BLOCK_SIZE-81)/60)throw new Error("Too many transactions.");if(i.length>s)throw new Error("Too many hashes.");if(8*a.length<i.length)throw new Error("Flags too small.");for(;1<d(p);)p++;var g=m(p,0);if(l)throw new Error("Mutated merkle tree.");if(((n+7)/8|0)!==a.length)throw new Error("Too many flag bits.");if(h!==i.length)throw new Error("Incorrect number of hashes.");return new f(g,e,t,r)}getCoinbaseHeight(){return-1}inspect(){return this.format()}format(e,t){return{hash:this.rhash(),height:null!=t?t:-1,date:a.date(this.time),version:a.hex32(this.version),prevBlock:a.revHex(this.prevBlock),merkleRoot:a.revHex(this.merkleRoot),time:this.time,bits:this.bits,nonce:this.nonce,totalTX:this.totalTX,hashes:this.hashes.map(e=>e.toString("hex")),flags:this.flags,map:this.getTree().map,txs:this.txs.length}}getSize(){return 84+o.sizeVarint(this.hashes.length)+32*this.hashes.length+o.sizeVarint(this.flags.length)+this.flags.length}toWriter(e){this.writeHead(e),e.writeU32(this.totalTX),e.writeVarint(this.hashes.length);for(const t of this.hashes)e.writeHash(t);return e.writeVarBytes(this.flags),e}toRaw(){var e=this.getSize();return this.toWriter(new n(e)).render()}fromReader(e){this.readHead(e),this.totalTX=e.readU32();var t=e.readVarint();for(let r=0;r<t;r++)this.hashes.push(e.readHash());return this.flags=e.readVarBytes(),this}fromRaw(e){return this.fromReader(new s(e))}static fromReader(e){return(new d).fromReader(e)}static fromRaw(e,t){return"string"==typeof e&&(e=Buffer.from(e,t)),(new d).fromRaw(e)}toJSON(){return this.getJSON()}getJSON(e,t,r){return{hash:this.rhash(),height:r,version:this.version,prevBlock:a.revHex(this.prevBlock),merkleRoot:a.revHex(this.merkleRoot),time:this.time,bits:this.bits,nonce:this.nonce,totalTX:this.totalTX,hashes:this.hashes.map(e=>a.revHex(e.toString("hex"))),flags:this.flags.toString("hex")}}fromJSON(e){for(var t of(i(e,"MerkleBlock data is required."),i(Array.isArray(e.hashes)),i("string"==typeof e.flags),i(a.isU32(e.totalTX)),this.parseJSON(e),e.hashes))t=a.revHex(t),this.hashes.push(Buffer.from(t,"hex"));return this.flags=Buffer.from(e.flags,"hex"),this.totalTX=e.totalTX,this}static fromJSON(e){return(new d).fromJSON(e)}static fromBlock(e,t){var r=[];for(const i of e.txs)r.push(i.isWatched(t)?1:0);return d.fromMatches(e,r)}static fromHashes(e,t){var r,i=new Set;for(r of t)Buffer.isBuffer(r)&&(r=r.toString("hex")),i.add(r);var a=[];for(const t of e.txs){var s=t.hash("hex");a.push(i.has(s)?1:0)}return d.fromMatches(e,a)}static fromMatches(e,t){var r=[],i=[];const a=[],s=[],n=e.txs.length;let o=0;const u=e=>n+(1<<e)-1>>>e,h=(e,t,r)=>{if(0===e)return r[t];var i=h(e-1,2*t,r);let a;return a=2*t+1<u(e-1)?h(e-1,2*t+1,r):i,c.root256(i,a)},l=(e,t,r,i)=>{let o=0;for(let r=t<<e;r<t+1<<e&&r<n;r++)o|=i[r];a.push(o),0!==e&&o?(l(e-1,2*t,r,i),2*t+1<u(e-1)&&l(e-1,2*t+1,r,i)):s.push(h(e,t,r))};for(let a=0;a<e.txs.length;a++){var p=e.txs[a];t[a]&&r.push(p),i.push(p.hash())}for(;1<u(o);)o++;l(o,0,i,t);var f=Buffer.allocUnsafe((a.length+7)/8|0);f.fill(0);for(let e=0;e<a.length;e++)f[e/8|0]|=a[e]<<e%8;var m=new d;return m._hash=e._hash,m._hhash=e._hhash,m.version=e.version,m.prevBlock=e.prevBlock,m.merkleRoot=e.merkleRoot,m.time=e.time,m.bits=e.bits,m.nonce=e.nonce,m.totalTX=n,m.hashes=s,m.flags=f,m.txs=r,m}static isMerkleBlock(e){return e instanceof d}toHeaders(){return l.fromBlock(this)}}function f(e,t,r,i){this.root=e?e.toString("hex"):o.NULL_HASH,this.matches=t||[],this.indexes=r||[],this.map=i||new Map}e.exports=d},function(e,t,r){const i=r(5).PropStatus;r=r(35);class a extends r{constructor(e){super(),this.db=e||{getVp:async e=>this.get(e),setVp:e=>{this.set(e.pid,e)},delVp:e=>{this.delete(e)},loadVpList:()=>{}}}async loadHistory(){}setAccount(e,t,r){var i;e&&e.wid&&e.account&&(i=e.wid+"."+e.account,this.account.get(i))&&this.account.get(i).delete(e.pid),e.wid=t,e.account=r,t&&r&&(i=e.wid+"."+e.account,this.account.get(i)||this.account.set(i,new Map),this.account.get(i).set(e.pid,e))}delAccount(e){var t;e&&e.wid&&e.account&&(t=e.wid+"."+e.account,this.account.get(t))&&this.account.get(t).delete(e.pid)}async getVp(e){return this.db.getVp(e)}async getVpByAddress(e){return this.db.getVpByAddress(e)}async getVpByOid(e){return this.db.getVpByOid(e)}async setVp(e,t){e=new s(e),await this.db.setVp(e,t)}async delVp(e){this.delete(e.pid),await this.db.delVp(e)}}class s{constructor(e){this.fromOptions(e=e||{})}fromOptions(e){this.pid=e.pid,this.cid=e.cid||"",this.oid=e.oid||"",this.gold=e.gold,this.current=null,e.current&&(this.current={},this.current.hash=e.current.hash,this.current.index=e.current.index,this.current.address=e.current.address),this.height=e.height,this.pst=e.pst||i.Ready,this.wid=e.wid||0,this.account=e.account||"",this.bid=null,e.bid&&(this.bid={},this.bid.raw=e.bid.raw||"",this.bid.fixed=e.bid.fixed||0,this.bid.period=e.bid.period||0,this.bid.hash=e.bid.hash||"",this.bid.value=e.bid.value||0,this.bid.address=e.bid.address||"")}toRaw(){var e={};return e.pid=this.pid,e.cid=this.cid||"",e.oid=this.oid||"",e.gold=this.gold,this.current&&(e.current={},e.current.hash=this.current.hash,e.current.index=this.current.index,e.current.address=this.current.address),e.height=this.height,e.pst=this.pst||i.Ready,e.wid=this.wid||0,e.account=this.account||"",this.bid&&(e.bid={},e.bid.raw=this.bid.raw||"",e.bid.fixed=this.bid.fixed||0,e.bid.period=this.bid.period||0,e.bid.hash=this.bid.hash||"",e.bid.value=this.bid.value||0,e.bid.address=this.bid.address||""),Buffer.from(JSON.stringify(e),"utf-8")}fromRaw(e){return e=JSON.parse(e.toString("utf8")),this.fromOptions(e),this}static fromRaw(e){return(new s).fromRaw(e)}}a.vpItem=s,e.exports=a},function(e,t,r){var i=r(10),a=r(175),s=(r=r(9),{sha1:!0,sha256:!0,sha512:!0}),n={rsa:!0,dsa:!0,ecdsa:!0};function o(e,t){Error.captureStackTrace&&Error.captureStackTrace(this,t||o),this.message=e,this.name=t.name}function c(e){o.call(this,e,c)}r.inherits(o,Error),r.inherits(c,o),e.exports={HASH_ALGOS:s,PK_ALGOS:n,HttpSignatureError:o,InvalidAlgorithmError:c,validateAlgorithm:function(e){if(2!==(e=e.toLowerCase().split("-")).length)throw new c(e[0].toUpperCase()+" is not a valid algorithm");if("hmac"!==e[0]&&!n[e[0]])throw new c(e[0].toUpperCase()+" type keys are not supported");if(s[e[1]])return e;throw new c(e[1].toUpperCase()+" is not a supported hash algorithm")},sshKeyToPEM:function(e){return i.string(e,"ssh_key"),a.parseKey(e,"ssh").toString("pem")},fingerprint:function(e){return i.string(e,"ssh_key"),a.parseKey(e,"ssh").fingerprint("md5").toString("hex")},pemToRsaSSHKey:function(e,t){return i.equal("string",typeof e,"typeof pem"),(e=a.parseKey(e,"pem")).comment=t,e.toString("ssh")}}},function(e,t,r){var i=r(102).BigInteger,a=i.prototype.Barrett;function s(e,t){this.x=t,this.q=e}function n(e,t,r,a){this.curve=e,this.x=t,this.y=r,this.z=null==a?i.ONE:a,this.zinv=null}function o(e,t,r){this.q=e,this.a=this.fromBigInteger(t),this.b=this.fromBigInteger(r),this.infinity=new n(this,null,null),this.reducer=new a(this.q)}s.prototype.equals=function(e){return e==this||this.q.equals(e.q)&&this.x.equals(e.x)},s.prototype.toBigInteger=function(){return this.x},s.prototype.negate=function(){return new s(this.q,this.x.negate().mod(this.q))},s.prototype.add=function(e){return new s(this.q,this.x.add(e.toBigInteger()).mod(this.q))},s.prototype.subtract=function(e){return new s(this.q,this.x.subtract(e.toBigInteger()).mod(this.q))},s.prototype.multiply=function(e){return new s(this.q,this.x.multiply(e.toBigInteger()).mod(this.q))},s.prototype.square=function(){return new s(this.q,this.x.square().mod(this.q))},s.prototype.divide=function(e){return new s(this.q,this.x.multiply(e.toBigInteger().modInverse(this.q)).mod(this.q))},n.prototype.getX=function(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var e=this.x.toBigInteger().multiply(this.zinv);return this.curve.reduce(e),this.curve.fromBigInteger(e)},n.prototype.getY=function(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var e=this.y.toBigInteger().multiply(this.zinv);return this.curve.reduce(e),this.curve.fromBigInteger(e)},n.prototype.equals=function(e){return e==this||(this.isInfinity()?e.isInfinity():e.isInfinity()?this.isInfinity():!!e.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(e.z)).mod(this.curve.q).equals(i.ZERO)&&e.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(e.z)).mod(this.curve.q).equals(i.ZERO))},n.prototype.isInfinity=function(){return null==this.x&&null==this.y||this.z.equals(i.ZERO)&&!this.y.toBigInteger().equals(i.ZERO)},n.prototype.negate=function(){return new n(this.curve,this.x,this.y.negate(),this.z)},n.prototype.add=function(e){var t,r,a,s,o,c,u;return this.isInfinity()?e:e.isInfinity()?this:(t=e.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(e.z)).mod(this.curve.q),o=e.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(e.z)).mod(this.curve.q),i.ZERO.equals(o)?i.ZERO.equals(t)?this.twice():this.curve.getInfinity():(u=new i("3"),c=this.x.toBigInteger(),r=this.y.toBigInteger(),e.x.toBigInteger(),e.y.toBigInteger(),a=(s=o.square()).multiply(o),c=c.multiply(s),o=(s=t.square().multiply(this.z)).subtract(c.shiftLeft(1)).multiply(e.z).subtract(a).multiply(o).mod(this.curve.q),c=c.multiply(u).multiply(t).subtract(r.multiply(a)).subtract(s.multiply(t)).multiply(e.z).add(t.multiply(a)).mod(this.curve.q),u=a.multiply(this.z).multiply(e.z).mod(this.curve.q),new n(this.curve,this.curve.fromBigInteger(o),this.curve.fromBigInteger(c),u)))},n.prototype.twice=function(){var e,t,r,a,s,o;return this.isInfinity()?this:0==this.y.toBigInteger().signum()?this.curve.getInfinity():(s=new i("3"),o=this.x.toBigInteger(),t=(e=(t=this.y.toBigInteger()).multiply(this.z)).multiply(t).mod(this.curve.q),a=this.curve.a.toBigInteger(),r=o.square().multiply(s),a=(r=(r=i.ZERO.equals(a)?r:r.add(this.z.square().multiply(a))).mod(this.curve.q)).square().subtract(o.shiftLeft(3).multiply(t)).shiftLeft(1).multiply(e).mod(this.curve.q),s=r.multiply(s).multiply(o).subtract(t.shiftLeft(1)).shiftLeft(2).multiply(t).subtract(r.square().multiply(r)).mod(this.curve.q),o=e.square().multiply(e).shiftLeft(3).mod(this.curve.q),new n(this.curve,this.curve.fromBigInteger(a),this.curve.fromBigInteger(s),o))},n.prototype.multiply=function(e){if(this.isInfinity())return this;if(0==e.signum())return this.curve.getInfinity();for(var t=e,r=t.multiply(new i("3")),a=this.negate(),s=this,n=r.bitLength()-2;0<n;--n){s=s.twice();var o=r.testBit(n);o!=t.testBit(n)&&(s=s.add(o?this:a))}return s},n.prototype.multiplyTwo=function(e,t,r){for(var i=e.bitLength()>r.bitLength()?e.bitLength()-1:r.bitLength()-1,a=this.curve.getInfinity(),s=this.add(t);0<=i;)a=a.twice(),e.testBit(i)?a=r.testBit(i)?a.add(s):a.add(this):r.testBit(i)&&(a=a.add(t)),--i;return a},o.prototype.getQ=function(){return this.q},o.prototype.getA=function(){return this.a},o.prototype.getB=function(){return this.b},o.prototype.equals=function(e){return e==this||this.q.equals(e.q)&&this.a.equals(e.a)&&this.b.equals(e.b)},o.prototype.getInfinity=function(){return this.infinity},o.prototype.fromBigInteger=function(e){return new s(this.q,e)},o.prototype.reduce=function(e){this.reducer.reduce(e)},o.prototype.encodePointHex=function(e){if(e.isInfinity())return"00";var t=e.getX().toBigInteger().toString(16),r=e.getY().toBigInteger().toString(16),i=this.getQ().toString(16).length;for(i%2!=0&&i++;t.length<i;)t="0"+t;for(;r.length<i;)r="0"+r;return"04"+t+r},o.prototype.decodePointHex=function(e){switch(parseInt(e.substr(0,2),16)){case 0:return this.infinity;case 2:c=!1;case 3:null==c&&(c=!0);var t=e.length-2,r=e.substr(2,t),a=this.fromBigInteger(new i(r,16)),s=a.multiply(a.square().add(this.getA())).add(this.getB()).sqrt();if(null==s)throw"Invalid point compression";var o=s.toBigInteger();return o.testBit(0)!=c&&(s=this.fromBigInteger(this.getQ().subtract(o))),new n(this,a,s);case 4:case 6:case 7:t=(e.length-2)/2,r=e.substr(2,t);var c=e.substr(t+2,t);return new n(this,this.fromBigInteger(new i(r,16)),this.fromBigInteger(new i(c,16)));default:return null}},o.prototype.encodeCompressedPointHex=function(e){if(e.isInfinity())return"00";var t=e.getX().toBigInteger().toString(16),r=this.getQ().toString(16).length;for(r%2!=0&&r++;t.length<r;)t="0"+t;return(e.getY().toBigInteger().isEven()?"02":"03")+t},s.prototype.getR=function(){var e;return null==this.r&&(this.r=null,128<(e=this.q.bitLength())&&-1==this.q.shiftRight(e-64).intValue())&&(this.r=i.ONE.shiftLeft(e).subtract(this.q)),this.r},s.prototype.modMult=function(e,t){return this.modReduce(e.multiply(t))},s.prototype.modReduce=function(e){if(null!=this.getR()){for(var t=q.bitLength();e.bitLength()>t+1;){var r=e.shiftRight(t),a=e.subtract(r.shiftLeft(t));e=(r=this.getR().equals(i.ONE)?r:r.multiply(this.getR())).add(a)}for(;0<=e.compareTo(q);)e=e.subtract(q)}else e=e.mod(q);return e},s.prototype.sqrt=function(){if(!this.q.testBit(0))throw"unsupported";var e;if(this.q.testBit(1))return(e=new s(this.q,this.x.modPow(this.q.shiftRight(2).add(i.ONE),this.q))).square().equals(this)?e:null;var t=this.q.subtract(i.ONE),r=t.shiftRight(1);if(this.x.modPow(r,this.q).equals(i.ONE)){var a,n=t.shiftRight(2).shiftLeft(1).add(i.ONE),o=this.x,c=modDouble(modDouble(o));do{for(;0<=(a=new i(this.q.bitLength(),new SecureRandom)).compareTo(this.q)||!a.multiply(a).subtract(c).modPow(r,this.q).equals(t););var u=(h=this.lucasSequence(a,o,n))[0],h=h[1];if(this.modMult(h,h).equals(c))return h=(h=h.testBit(0)?h.add(q):h).shiftRight(1),new s(q,h)}while(u.equals(i.ONE)||u.equals(t))}return null},s.prototype.lucasSequence=function(e,t,r){for(var a=r.bitLength(),s=r.getLowestSetBit(),n=i.ONE,o=i.TWO,c=e,u=i.ONE,h=i.ONE,l=a-1;s+1<=l;--l)u=this.modMult(u,h),r.testBit(l)?(h=this.modMult(u,t),n=this.modMult(n,c),o=this.modReduce(c.multiply(o).subtract(e.multiply(u))),c=this.modReduce(c.multiply(c).subtract(h.shiftLeft(1)))):(h=u,n=this.modReduce(n.multiply(o).subtract(u)),c=this.modReduce(c.multiply(o).subtract(e.multiply(u))),o=this.modReduce(o.multiply(o).subtract(u.shiftLeft(1))));for(u=this.modMult(u,h),h=this.modMult(u,t),n=this.modReduce(n.multiply(o).subtract(u)),o=this.modReduce(c.multiply(o).subtract(e.multiply(u))),u=this.modMult(u,h),l=1;l<=s;++l)n=this.modMult(n,o),o=this.modReduce(o.multiply(o).subtract(u.shiftLeft(1))),u=this.modMult(u,u);return[n,o]},e.exports={ECCurveFp:o,ECPointFp:n,ECFieldElementFp:s}},function(e,t,r){e.exports={read:function(e,t){return u.read(e,t)},readSSHPrivate:function(e,t,c){var u=(t=new l({buffer:t})).readCString(),f=(a.strictEqual(u,d,"bad magic string"),t.readString()),m=t.readString();u=t.readBuffer();if(1!==t.readInt())throw new Error("OpenSSH-format key file contains multiple keys: this is unsupported.");var g=t.readBuffer();if("public"===e)return a.ok(t.atEnd(),"excess bytes left after key"),h.read(g);var y=t.readBuffer(),v=(a.ok(t.atEnd(),"excess bytes left after key"),new l({buffer:u}));switch(m){case"none":if("none"!==f)throw new Error('OpenSSH-format key uses KDF "none" but specifies a cipher other than "none"');break;case"bcrypt":var b=v.readBuffer(),w=v.readInt(),k=n.opensshCipherInfo(f);if(void 0===i&&(i=r(274)),"string"==typeof c.passphrase&&(c.passphrase=s.from(c.passphrase,"utf-8")),!s.isBuffer(c.passphrase))throw new p.KeyEncryptedError(c.filename,"OpenSSH");var x=new Uint8Array(c.passphrase),S=(b=new Uint8Array(b),new Uint8Array(k.keySize+k.blockSize));if(0!==i.pbkdf(x,x.length,b,b.length,S,S.length,w))throw new Error("bcrypt_pbkdf function returned failure, parameters invalid");x=(S=s.from(S)).slice(0,k.keySize),b=S.slice(k.keySize,k.keySize+k.blockSize);var _=o.createDecipheriv(k.opensslName,x,b);_.setAutoPadding(!1);var E,j=[];for(_.once("error",(function(e){if(-1!==e.toString().indexOf("bad decrypt"))throw new Error("Incorrect passphrase supplied, could not decrypt key");throw e})),_.write(y),_.end();null!==(E=_.read());)j.push(E);y=s.concat(j);break;default:throw new Error('OpenSSH-format key uses unknown KDF "'+m+'"')}if((e=(t=new l({buffer:y})).readInt())!==(g=t.readInt()))throw new Error("Incorrect passphrase supplied, could not decrypt key");return u={},e=h.readInternal(u,"private",t.remainder()),t.skip(u.consumed),g=t.readString(),e.comment=g,e},write:function(e,t){var u;u=c.isPrivateKey(e)?e.toPublic():e;var h,p,f="none",m="none",g=s.alloc(0),y={blockSize:8};if(void 0!==t&&void 0!==(h="string"==typeof(h=t.passphrase)?s.from(h,"utf-8"):h)&&(a.buffer(h,"options.passphrase"),a.optionalString(t.cipher,"options.cipher"),void 0===(f=t.cipher)&&(f="aes128-ctr"),y=n.opensshCipherInfo(f),m="bcrypt"),c.isPrivateKey(e)){p=new l({});t=o.randomBytes(4).readUInt32BE(0);for(var v=(p.writeInt(t),p.writeInt(t),p.write(e.toBuffer("rfc4253")),p.writeString(e.comment||""),1);p._offset%y.blockSize!=0;)p.writeChar(v++);p=p.toBuffer()}switch(m){case"none":break;case"bcrypt":var b=o.randomBytes(16),w=((w=new l({})).writeBuffer(b),w.writeInt(16),g=w.toBuffer(),void 0===i&&(i=r(274)),new Uint8Array(h)),k=(b=new Uint8Array(b),new Uint8Array(y.keySize+y.blockSize));if(0!==i.pbkdf(w,w.length,b,b.length,k,k.length,16))throw new Error("bcrypt_pbkdf function returned failure, parameters invalid");w=(k=s.from(k)).slice(0,y.keySize),b=k.slice(y.keySize,y.keySize+y.blockSize);var x=o.createCipheriv(y.opensslName,w,b);x.setAutoPadding(!1);var S,_=[];for(x.once("error",(function(e){throw e})),x.write(p),x.end();null!==(S=x.read());)_.push(S);p=s.concat(_);break;default:throw new Error("Unsupported kdf "+m)}var E=new l({});E.writeCString(d),E.writeString(f),E.writeString(m),E.writeBuffer(g),E.writeInt(1),E.writeBuffer(u.toBuffer("rfc4253")),p&&E.writeBuffer(p),E=E.toBuffer(),t=c.isPrivateKey(e)?"OPENSSH PRIVATE KEY":"OPENSSH PUBLIC KEY";var j=E.toString("base64"),A=(f=j.length+j.length/70+18+16+2*t.length+10,E=s.alloc(f),0);A+=E.write("-----BEGIN "+t+"-----\n",A);for(var R=0;R<j.length;){var I=R+70;I>j.length&&(I=j.length),A+=E.write(j.slice(R,I),A),E[A++]=10,R=I}return A+=E.write("-----END "+t+"-----\n",A),E.slice(0,A)}};var i,a=r(10),s=(r(57),r(12).Buffer),n=(r(30),r(25)),o=r(8),c=(r(23),r(24)),u=r(65),h=r(66),l=r(91),p=r(51),d="openssh-key-v1"},function(e,t,r){var i=r(58);const a=r(82),s=r(17),n=r(28),o=r(7),c=r(0),{Transform:u,ContractType:h,HtlcStatus:l,ContractEnvType:p}=r(5),d=new u("\n /*携带合约信息*/\n HTLCSUGGEST var_contract DROP\n /*校验秘密,持有秘密者才可执行*/\n HASH160 var_ab EQUALVERIFY \n IF\n /*Bob确认时执行: 校验Bob签名*/\n DUP HASH160 var_ba EQUALVERIFY CHECKSIG\n ELSE\n /*Alice取消时执行: 校验延时和Alice签名*/\n var_period CHECKSEQUENCEVERIFY DROP\n DUP HASH160 var_aa EQUALVERIFY CHECKSIG\n ENDIF\n");e.exports=class extends i{async confirm(){var{env:e,output:t,hash:r,i:i,data:s,height:n}=this.options,o=t.getHashs("hex"),r={type:"suggest",src:a.protocol+"."+e.network.type,dst:s.dst,shash:r,sidx:i,sheight:n,pst:l.Sent,amount:t.value,rate:s.rate,ab:t.script.code[4].data.toString("hex"),aa:o[1],ba:o[0]};await e.setSuggest(r),e.mode==p.Block&&e.node.transmit("htlcsuggest.receive",r)}async unconfirm(){var{env:e,data:t}=this.options,t={shash:t.hash,sidx:t.index};await e.delHtlc(t)}async spent(e){var t=this.options.env,r=t.htlcList.get(""+e.prevout.hash+e.prevout.index);r&&(81==e.script.code[2].value?(r.pst=l.Finished,await t.setSuggest(r),t.mode==p.Block&&t.node.transmit("htlcsuggest.deal",r)):(r.pst=l.Cancel,await t.setSuggest(r),t.mode==p.Block&&t.node.transmit("htlcsuggest.cancel",r)))}async verify(){var{output:e,data:t}=this.options,r=(t={oper:h.htlcSuggest,rate:t.rate,dst:t.dst},e.getHashs("hex")),i=e.script.code[4].data.toString("hex"),t={contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),ab:"0x"+i.toString("hex"),aa:"0x"+r[1].toString("hex"),ba:"0x"+r[0].toString("hex"),period:2*o.HTLC_CANCEL_PERIOD};i=s.fromString(d.replace(t));return c(i.toString()===e.script.toString()),!0}static create(e){var t={oper:h.htlcSuggest,rate:e.rate,dst:e.dst};t={contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),ab:"0x"+e.ab.toString("hex"),aa:"0x"+e.aa.toString("hex"),ba:"0x"+e.ba.toString("hex"),period:2*o.HTLC_CANCEL_PERIOD},t=s.fromString(d.replace(t));return n.fromScript(t,e.amount)}}},function(e,t,r){var i=r(58);const a=r(82),s=r(17),n=r(28),o=r(7),{Transform:c,ContractType:u,HtlcStatus:h,ContractEnvType:l}=r(5),p=new c("\n /*携带合约信息*/\n HTLCASSENT var_contract DROP\n IF\n /*Alice确认时执行: 校验签名*/\n DUP HASH160 var_ab EQUALVERIFY CHECKSIG\n ELSE\n /*Bob取消时执行: 校验延时和签名*/\n var_period CHECKSEQUENCEVERIFY DROP\n DUP HASH160 var_bb EQUALVERIFY CHECKSIG\n ENDIF\n");e.exports=class extends i{async confirm(){var{env:e,i:t,output:r,hash:i,height:s,data:n}=this.options,r=r.getHashs("hex"),i={src:n.src,dst:a.protocol+"."+e.network.type,shash:n.hash,sidx:n.index,ahash:i,aidx:t,aheight:s,pst:h.Assent,amount:n.value,rate:n.rate,ab:r[0],bb:r[1]};await e.setAssent(i),e.mode==l.Block&&e.node.transmit("htlcassent.receive",i)}async unconfirm(){var{env:e,data:t}=this.options,t={shash:t.hash,sidx:t.index};await e.delHtlc(t)}async spent(e){var t=this.options.env,r=t.htlcList.query([["ahash",e.prevout.hash],["aidx",e.prevout.index]]);r&&1===r.list.length&&r.list[0].pst===h.Assent&&(r=r.list[0],81==e.script.code[2].value?(r.secret=e.script.code[1].data.toString("hex"),r.pst=h.Deal,await t.setAssent(r),t.mode==l.Block&&t.node.transmit("htlcassent.deal",r)):(r.pst=h.Cancel,await t.setAssent(r),t.mode==l.Block&&t.node.transmit("htlcassent.cancel",r)))}async verify(){var{env:e,output:t,data:r}=this.options;return r.dst==a.protocol+"."+e.network.type&&(e={oper:u.htlcAssent,hash:r.hash,index:r.index},r=t.getHashs("hex"),e=s.fromString(p.replace({contract:"0x"+Buffer.from(JSON.stringify(e)).toString("hex"),ab:"0x"+r[0].toString("hex"),bb:"0x"+r[1].toString("hex"),period:o.HTLC_CANCEL_PERIOD})),assert(e.toString()===t.script.toString()),!0)}static create(e){var t={oper:u.htlcAssent,hash:e.hash,index:e.index};t=s.fromString(p.replace({contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),ab:"0x"+e.ab.toString("hex"),bb:"0x"+e.bb.toString("hex"),period:o.HTLC_CANCEL_PERIOD}));return n.fromScript(t,e.amount)}}},function(e,t,r){var i=r(58);const a=r(17),s=r(28),n=r(0),{Transform:o,ContractType:c,ContractEnvType:u}=r(5),h=r(13),l=r(72).verifyData,p=new o("\n /*携带合约信息*/\n COMMENT var_contract DROP\n /*Bob确认时执行: 校验Bob签名*/\n DUP HASH160 var_bob EQUALVERIFY CHECKSIG\n");e.exports=class extends i{async insert(){var{env:e,output:t,hash:r,i:i,data:a}=this.options,t=h.fromWitnessPubkeyhash(t.getHash(),e.network).toString(),r={shash:r,sidx:i,alice:a.payload.addr,bob:t,body:a.payload.body};e.mode==u.Wallet&&await e.setComment(r)}async erase(){var{env:e,hash:t,i:r}=this.options,t={shash:t,sidx:r};e.mode==u.Wallet&&await e.delComment(t)}async verify(){var{output:e,data:t}=this.options,r=e.getHash();r=a.fromString(p.replace({contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),bob:"0x"+r.toString("hex")})),n(r.toString()===e.script.toString()),r=t.payload.sig;return delete(t=t.payload).sig,n.strictEqual(!0,l({data:t,sig:r})),!0}static create(e){var t={oper:c.comment,payload:e};t={contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),bob:"0x"+h.fromString(e.bob).hash.toString("hex")},t=a.fromString(p.replace(t));return s.fromScript(t,e.amount)}}},function(e,t,r){"use strict";
317
+ */const i=r(0),a=r(2),s=r(1),n=r(4),o=r(3),c=r(6),u=r(7);var h=r(115);const l=r(89),p=Buffer.from([0]);class d extends h{constructor(e){super(),this.txs=[],this.hashes=[],this.flags=p,this.totalTX=0,this._tree=null,e&&this.fromOptions(e)}fromOptions(e){if(this.parseOptions(e),i(e,"MerkleBlock data is required."),i(Array.isArray(e.hashes)),i(Buffer.isBuffer(e.flags)),i(a.isU32(e.totalTX)),e.hashes)for(var t of e.hashes)"string"==typeof t&&(t=Buffer.from(t,"hex")),i(Buffer.isBuffer(t)),this.hashes.push(t);return e.flags&&(i(Buffer.isBuffer(e.flags)),this.flags=e.flags),null!=e.totalTX&&(i(a.isU32(e.totalTX)),this.totalTX=e.totalTX),this}static fromOptions(e){return(new d).fromOptions(e)}refresh(e){if(this._refresh(),this._tree=null,e)for(const e of this.txs)e.refresh()}hasTX(e){return-1!==this.indexOf(e)}indexOf(e){return null==(e=this.getTree().map.get(e))?-1:e}verifyBody(){var[e]=this.checkBody();return e}checkBody(){return this.getTree().root!==this.merkleRoot?[!1,"bad-txnmrklroot",100]:[!0,"valid",0]}getTree(){if(!this._tree)try{this._tree=this.extractTree()}catch(e){this._tree=new f}return this._tree}extractTree(){const e=[],t=[],r=new Map,i=this.hashes,a=this.flags,s=this.totalTX;let n=0,h=0,l=!1,p=0;const d=e=>s+(1<<e)-1>>>e,m=(s,u)=>{if(n>=8*a.length)return l=!0,o.ZERO_HASH;var p,f=a[n/8|0]>>>n%8&1;if(n++,0===s||!f)return h>=i.length?(l=!0,o.ZERO_HASH):(p=i[h++],0===s&&f&&(f=p.toString("hex"),e.push(p),t.push(u),r.set(f,u)),p);let g;return f=m(s-1,2*u),2*u+1<d(s-1)?(g=m(s-1,2*u+1)).equals(f)&&(l=!0):g=f,c.root256(f,g)};if(0===s)throw new Error("Zero transactions.");if(s>(u.MAX_BLOCK_SIZE-81)/60)throw new Error("Too many transactions.");if(i.length>s)throw new Error("Too many hashes.");if(8*a.length<i.length)throw new Error("Flags too small.");for(;1<d(p);)p++;var g=m(p,0);if(l)throw new Error("Mutated merkle tree.");if(((n+7)/8|0)!==a.length)throw new Error("Too many flag bits.");if(h!==i.length)throw new Error("Incorrect number of hashes.");return new f(g,e,t,r)}getCoinbaseHeight(){return-1}inspect(){return this.format()}format(e,t){return{hash:this.rhash(),height:null!=t?t:-1,date:a.date(this.time),version:a.hex32(this.version),prevBlock:a.revHex(this.prevBlock),merkleRoot:a.revHex(this.merkleRoot),time:this.time,bits:this.bits,nonce:this.nonce,totalTX:this.totalTX,hashes:this.hashes.map(e=>e.toString("hex")),flags:this.flags,map:this.getTree().map,txs:this.txs.length}}getSize(){return 84+o.sizeVarint(this.hashes.length)+32*this.hashes.length+o.sizeVarint(this.flags.length)+this.flags.length}toWriter(e){this.writeHead(e),e.writeU32(this.totalTX),e.writeVarint(this.hashes.length);for(const t of this.hashes)e.writeHash(t);return e.writeVarBytes(this.flags),e}toRaw(){var e=this.getSize();return this.toWriter(new n(e)).render()}fromReader(e){this.readHead(e),this.totalTX=e.readU32();var t=e.readVarint();for(let r=0;r<t;r++)this.hashes.push(e.readHash());return this.flags=e.readVarBytes(),this}fromRaw(e){return this.fromReader(new s(e))}static fromReader(e){return(new d).fromReader(e)}static fromRaw(e,t){return"string"==typeof e&&(e=Buffer.from(e,t)),(new d).fromRaw(e)}toJSON(){return this.getJSON()}getJSON(e,t,r){return{hash:this.rhash(),height:r,version:this.version,prevBlock:a.revHex(this.prevBlock),merkleRoot:a.revHex(this.merkleRoot),time:this.time,bits:this.bits,nonce:this.nonce,totalTX:this.totalTX,hashes:this.hashes.map(e=>a.revHex(e.toString("hex"))),flags:this.flags.toString("hex")}}fromJSON(e){for(var t of(i(e,"MerkleBlock data is required."),i(Array.isArray(e.hashes)),i("string"==typeof e.flags),i(a.isU32(e.totalTX)),this.parseJSON(e),e.hashes))t=a.revHex(t),this.hashes.push(Buffer.from(t,"hex"));return this.flags=Buffer.from(e.flags,"hex"),this.totalTX=e.totalTX,this}static fromJSON(e){return(new d).fromJSON(e)}static fromBlock(e,t){var r=[];for(const i of e.txs)r.push(i.isWatched(t)?1:0);return d.fromMatches(e,r)}static fromHashes(e,t){var r,i=new Set;for(r of t)Buffer.isBuffer(r)&&(r=r.toString("hex")),i.add(r);var a=[];for(const t of e.txs){var s=t.hash("hex");a.push(i.has(s)?1:0)}return d.fromMatches(e,a)}static fromMatches(e,t){var r=[],i=[];const a=[],s=[],n=e.txs.length;let o=0;const u=e=>n+(1<<e)-1>>>e,h=(e,t,r)=>{if(0===e)return r[t];var i=h(e-1,2*t,r);let a;return a=2*t+1<u(e-1)?h(e-1,2*t+1,r):i,c.root256(i,a)},l=(e,t,r,i)=>{let o=0;for(let r=t<<e;r<t+1<<e&&r<n;r++)o|=i[r];a.push(o),0!==e&&o?(l(e-1,2*t,r,i),2*t+1<u(e-1)&&l(e-1,2*t+1,r,i)):s.push(h(e,t,r))};for(let a=0;a<e.txs.length;a++){var p=e.txs[a];t[a]&&r.push(p),i.push(p.hash())}for(;1<u(o);)o++;l(o,0,i,t);var f=Buffer.allocUnsafe((a.length+7)/8|0);f.fill(0);for(let e=0;e<a.length;e++)f[e/8|0]|=a[e]<<e%8;var m=new d;return m._hash=e._hash,m._hhash=e._hhash,m.version=e.version,m.prevBlock=e.prevBlock,m.merkleRoot=e.merkleRoot,m.time=e.time,m.bits=e.bits,m.nonce=e.nonce,m.totalTX=n,m.hashes=s,m.flags=f,m.txs=r,m}static isMerkleBlock(e){return e instanceof d}toHeaders(){return l.fromBlock(this)}}function f(e,t,r,i){this.root=e?e.toString("hex"):o.NULL_HASH,this.matches=t||[],this.indexes=r||[],this.map=i||new Map}e.exports=d},function(e,t,r){const i=r(5).PropStatus;r=r(35);class a extends r{constructor(e){super(),this.db=e||{getVp:async e=>this.get(e),setVp:e=>{this.set(e.pid,e)},delVp:e=>{this.delete(e)},loadVpList:()=>{}}}async loadHistory(){}setAccount(e,t,r){var i;e&&e.wid&&e.account&&(i=e.wid+"."+e.account,this.account.get(i))&&this.account.get(i).delete(e.pid),e.wid=t,e.account=r,t&&r&&(i=e.wid+"."+e.account,this.account.get(i)||this.account.set(i,new Map),this.account.get(i).set(e.pid,e))}delAccount(e){var t;e&&e.wid&&e.account&&(t=e.wid+"."+e.account,this.account.get(t))&&this.account.get(t).delete(e.pid)}async getVp(e){return this.db.getVp(e)}async getVpByAddress(e){return this.db.getVpByAddress(e)}async getVpByOid(e){return this.db.getVpByOid(e)}async setVp(e,t){e=new s(e),await this.db.setVp(e,t)}async delVp(e){this.delete(e.pid),await this.db.delVp(e)}}class s{constructor(e){this.fromOptions(e=e||{})}fromOptions(e){this.pid=e.pid,this.cid=e.cid||"",this.oid=e.oid||"",this.gold=e.gold,this.current=null,e.current&&(this.current={},this.current.hash=e.current.hash,this.current.index=e.current.index,this.current.address=e.current.address),this.height=e.height,this.pst=e.pst||i.Ready,this.wid=e.wid||0,this.account=e.account||"",this.bid=null,e.bid&&(this.bid={},this.bid.raw=e.bid.raw||"",this.bid.fixed=e.bid.fixed||0,this.bid.period=e.bid.period||0,this.bid.hash=e.bid.hash||"",this.bid.value=e.bid.value||0,this.bid.address=e.bid.address||"")}toRaw(){var e={};return e.pid=this.pid,e.cid=this.cid||"",e.oid=this.oid||"",e.gold=this.gold,this.current&&(e.current={},e.current.hash=this.current.hash,e.current.index=this.current.index,e.current.address=this.current.address),e.height=this.height,e.pst=this.pst||i.Ready,e.wid=this.wid||0,e.account=this.account||"",this.bid&&(e.bid={},e.bid.raw=this.bid.raw||"",e.bid.fixed=this.bid.fixed||0,e.bid.period=this.bid.period||0,e.bid.hash=this.bid.hash||"",e.bid.value=this.bid.value||0,e.bid.address=this.bid.address||""),Buffer.from(JSON.stringify(e),"utf-8")}fromRaw(e){return e=JSON.parse(e.toString("utf8")),this.fromOptions(e),this}static fromRaw(e){return(new s).fromRaw(e)}}a.vpItem=s,e.exports=a},function(e,t,r){var i=r(10),a=r(175),s=(r=r(9),{sha1:!0,sha256:!0,sha512:!0}),n={rsa:!0,dsa:!0,ecdsa:!0};function o(e,t){Error.captureStackTrace&&Error.captureStackTrace(this,t||o),this.message=e,this.name=t.name}function c(e){o.call(this,e,c)}r.inherits(o,Error),r.inherits(c,o),e.exports={HASH_ALGOS:s,PK_ALGOS:n,HttpSignatureError:o,InvalidAlgorithmError:c,validateAlgorithm:function(e){if(2!==(e=e.toLowerCase().split("-")).length)throw new c(e[0].toUpperCase()+" is not a valid algorithm");if("hmac"!==e[0]&&!n[e[0]])throw new c(e[0].toUpperCase()+" type keys are not supported");if(s[e[1]])return e;throw new c(e[1].toUpperCase()+" is not a supported hash algorithm")},sshKeyToPEM:function(e){return i.string(e,"ssh_key"),a.parseKey(e,"ssh").toString("pem")},fingerprint:function(e){return i.string(e,"ssh_key"),a.parseKey(e,"ssh").fingerprint("md5").toString("hex")},pemToRsaSSHKey:function(e,t){return i.equal("string",typeof e,"typeof pem"),(e=a.parseKey(e,"pem")).comment=t,e.toString("ssh")}}},function(e,t,r){var i=r(102).BigInteger,a=i.prototype.Barrett;function s(e,t){this.x=t,this.q=e}function n(e,t,r,a){this.curve=e,this.x=t,this.y=r,this.z=null==a?i.ONE:a,this.zinv=null}function o(e,t,r){this.q=e,this.a=this.fromBigInteger(t),this.b=this.fromBigInteger(r),this.infinity=new n(this,null,null),this.reducer=new a(this.q)}s.prototype.equals=function(e){return e==this||this.q.equals(e.q)&&this.x.equals(e.x)},s.prototype.toBigInteger=function(){return this.x},s.prototype.negate=function(){return new s(this.q,this.x.negate().mod(this.q))},s.prototype.add=function(e){return new s(this.q,this.x.add(e.toBigInteger()).mod(this.q))},s.prototype.subtract=function(e){return new s(this.q,this.x.subtract(e.toBigInteger()).mod(this.q))},s.prototype.multiply=function(e){return new s(this.q,this.x.multiply(e.toBigInteger()).mod(this.q))},s.prototype.square=function(){return new s(this.q,this.x.square().mod(this.q))},s.prototype.divide=function(e){return new s(this.q,this.x.multiply(e.toBigInteger().modInverse(this.q)).mod(this.q))},n.prototype.getX=function(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var e=this.x.toBigInteger().multiply(this.zinv);return this.curve.reduce(e),this.curve.fromBigInteger(e)},n.prototype.getY=function(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var e=this.y.toBigInteger().multiply(this.zinv);return this.curve.reduce(e),this.curve.fromBigInteger(e)},n.prototype.equals=function(e){return e==this||(this.isInfinity()?e.isInfinity():e.isInfinity()?this.isInfinity():!!e.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(e.z)).mod(this.curve.q).equals(i.ZERO)&&e.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(e.z)).mod(this.curve.q).equals(i.ZERO))},n.prototype.isInfinity=function(){return null==this.x&&null==this.y||this.z.equals(i.ZERO)&&!this.y.toBigInteger().equals(i.ZERO)},n.prototype.negate=function(){return new n(this.curve,this.x,this.y.negate(),this.z)},n.prototype.add=function(e){var t,r,a,s,o,c,u;return this.isInfinity()?e:e.isInfinity()?this:(t=e.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(e.z)).mod(this.curve.q),o=e.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(e.z)).mod(this.curve.q),i.ZERO.equals(o)?i.ZERO.equals(t)?this.twice():this.curve.getInfinity():(u=new i("3"),c=this.x.toBigInteger(),r=this.y.toBigInteger(),e.x.toBigInteger(),e.y.toBigInteger(),a=(s=o.square()).multiply(o),c=c.multiply(s),o=(s=t.square().multiply(this.z)).subtract(c.shiftLeft(1)).multiply(e.z).subtract(a).multiply(o).mod(this.curve.q),c=c.multiply(u).multiply(t).subtract(r.multiply(a)).subtract(s.multiply(t)).multiply(e.z).add(t.multiply(a)).mod(this.curve.q),u=a.multiply(this.z).multiply(e.z).mod(this.curve.q),new n(this.curve,this.curve.fromBigInteger(o),this.curve.fromBigInteger(c),u)))},n.prototype.twice=function(){var e,t,r,a,s,o;return this.isInfinity()?this:0==this.y.toBigInteger().signum()?this.curve.getInfinity():(s=new i("3"),o=this.x.toBigInteger(),t=(e=(t=this.y.toBigInteger()).multiply(this.z)).multiply(t).mod(this.curve.q),a=this.curve.a.toBigInteger(),r=o.square().multiply(s),a=(r=(r=i.ZERO.equals(a)?r:r.add(this.z.square().multiply(a))).mod(this.curve.q)).square().subtract(o.shiftLeft(3).multiply(t)).shiftLeft(1).multiply(e).mod(this.curve.q),s=r.multiply(s).multiply(o).subtract(t.shiftLeft(1)).shiftLeft(2).multiply(t).subtract(r.square().multiply(r)).mod(this.curve.q),o=e.square().multiply(e).shiftLeft(3).mod(this.curve.q),new n(this.curve,this.curve.fromBigInteger(a),this.curve.fromBigInteger(s),o))},n.prototype.multiply=function(e){if(this.isInfinity())return this;if(0==e.signum())return this.curve.getInfinity();for(var t=e,r=t.multiply(new i("3")),a=this.negate(),s=this,n=r.bitLength()-2;0<n;--n){s=s.twice();var o=r.testBit(n);o!=t.testBit(n)&&(s=s.add(o?this:a))}return s},n.prototype.multiplyTwo=function(e,t,r){for(var i=e.bitLength()>r.bitLength()?e.bitLength()-1:r.bitLength()-1,a=this.curve.getInfinity(),s=this.add(t);0<=i;)a=a.twice(),e.testBit(i)?a=r.testBit(i)?a.add(s):a.add(this):r.testBit(i)&&(a=a.add(t)),--i;return a},o.prototype.getQ=function(){return this.q},o.prototype.getA=function(){return this.a},o.prototype.getB=function(){return this.b},o.prototype.equals=function(e){return e==this||this.q.equals(e.q)&&this.a.equals(e.a)&&this.b.equals(e.b)},o.prototype.getInfinity=function(){return this.infinity},o.prototype.fromBigInteger=function(e){return new s(this.q,e)},o.prototype.reduce=function(e){this.reducer.reduce(e)},o.prototype.encodePointHex=function(e){if(e.isInfinity())return"00";var t=e.getX().toBigInteger().toString(16),r=e.getY().toBigInteger().toString(16),i=this.getQ().toString(16).length;for(i%2!=0&&i++;t.length<i;)t="0"+t;for(;r.length<i;)r="0"+r;return"04"+t+r},o.prototype.decodePointHex=function(e){switch(parseInt(e.substr(0,2),16)){case 0:return this.infinity;case 2:c=!1;case 3:null==c&&(c=!0);var t=e.length-2,r=e.substr(2,t),a=this.fromBigInteger(new i(r,16)),s=a.multiply(a.square().add(this.getA())).add(this.getB()).sqrt();if(null==s)throw"Invalid point compression";var o=s.toBigInteger();return o.testBit(0)!=c&&(s=this.fromBigInteger(this.getQ().subtract(o))),new n(this,a,s);case 4:case 6:case 7:t=(e.length-2)/2,r=e.substr(2,t);var c=e.substr(t+2,t);return new n(this,this.fromBigInteger(new i(r,16)),this.fromBigInteger(new i(c,16)));default:return null}},o.prototype.encodeCompressedPointHex=function(e){if(e.isInfinity())return"00";var t=e.getX().toBigInteger().toString(16),r=this.getQ().toString(16).length;for(r%2!=0&&r++;t.length<r;)t="0"+t;return(e.getY().toBigInteger().isEven()?"02":"03")+t},s.prototype.getR=function(){var e;return null==this.r&&(this.r=null,128<(e=this.q.bitLength())&&-1==this.q.shiftRight(e-64).intValue())&&(this.r=i.ONE.shiftLeft(e).subtract(this.q)),this.r},s.prototype.modMult=function(e,t){return this.modReduce(e.multiply(t))},s.prototype.modReduce=function(e){if(null!=this.getR()){for(var t=q.bitLength();e.bitLength()>t+1;){var r=e.shiftRight(t),a=e.subtract(r.shiftLeft(t));e=(r=this.getR().equals(i.ONE)?r:r.multiply(this.getR())).add(a)}for(;0<=e.compareTo(q);)e=e.subtract(q)}else e=e.mod(q);return e},s.prototype.sqrt=function(){if(!this.q.testBit(0))throw"unsupported";var e;if(this.q.testBit(1))return(e=new s(this.q,this.x.modPow(this.q.shiftRight(2).add(i.ONE),this.q))).square().equals(this)?e:null;var t=this.q.subtract(i.ONE),r=t.shiftRight(1);if(this.x.modPow(r,this.q).equals(i.ONE)){var a,n=t.shiftRight(2).shiftLeft(1).add(i.ONE),o=this.x,c=modDouble(modDouble(o));do{for(;0<=(a=new i(this.q.bitLength(),new SecureRandom)).compareTo(this.q)||!a.multiply(a).subtract(c).modPow(r,this.q).equals(t););var u=(h=this.lucasSequence(a,o,n))[0],h=h[1];if(this.modMult(h,h).equals(c))return h=(h=h.testBit(0)?h.add(q):h).shiftRight(1),new s(q,h)}while(u.equals(i.ONE)||u.equals(t))}return null},s.prototype.lucasSequence=function(e,t,r){for(var a=r.bitLength(),s=r.getLowestSetBit(),n=i.ONE,o=i.TWO,c=e,u=i.ONE,h=i.ONE,l=a-1;s+1<=l;--l)u=this.modMult(u,h),r.testBit(l)?(h=this.modMult(u,t),n=this.modMult(n,c),o=this.modReduce(c.multiply(o).subtract(e.multiply(u))),c=this.modReduce(c.multiply(c).subtract(h.shiftLeft(1)))):(h=u,n=this.modReduce(n.multiply(o).subtract(u)),c=this.modReduce(c.multiply(o).subtract(e.multiply(u))),o=this.modReduce(o.multiply(o).subtract(u.shiftLeft(1))));for(u=this.modMult(u,h),h=this.modMult(u,t),n=this.modReduce(n.multiply(o).subtract(u)),o=this.modReduce(c.multiply(o).subtract(e.multiply(u))),u=this.modMult(u,h),l=1;l<=s;++l)n=this.modMult(n,o),o=this.modReduce(o.multiply(o).subtract(u.shiftLeft(1))),u=this.modMult(u,u);return[n,o]},e.exports={ECCurveFp:o,ECPointFp:n,ECFieldElementFp:s}},function(e,t,r){e.exports={read:function(e,t){return u.read(e,t)},readSSHPrivate:function(e,t,c){var u=(t=new l({buffer:t})).readCString(),f=(a.strictEqual(u,d,"bad magic string"),t.readString()),m=t.readString();u=t.readBuffer();if(1!==t.readInt())throw new Error("OpenSSH-format key file contains multiple keys: this is unsupported.");var g=t.readBuffer();if("public"===e)return a.ok(t.atEnd(),"excess bytes left after key"),h.read(g);var y=t.readBuffer(),v=(a.ok(t.atEnd(),"excess bytes left after key"),new l({buffer:u}));switch(m){case"none":if("none"!==f)throw new Error('OpenSSH-format key uses KDF "none" but specifies a cipher other than "none"');break;case"bcrypt":var b=v.readBuffer(),w=v.readInt(),k=n.opensshCipherInfo(f);if(void 0===i&&(i=r(274)),"string"==typeof c.passphrase&&(c.passphrase=s.from(c.passphrase,"utf-8")),!s.isBuffer(c.passphrase))throw new p.KeyEncryptedError(c.filename,"OpenSSH");var x=new Uint8Array(c.passphrase),S=(b=new Uint8Array(b),new Uint8Array(k.keySize+k.blockSize));if(0!==i.pbkdf(x,x.length,b,b.length,S,S.length,w))throw new Error("bcrypt_pbkdf function returned failure, parameters invalid");x=(S=s.from(S)).slice(0,k.keySize),b=S.slice(k.keySize,k.keySize+k.blockSize);var _=o.createDecipheriv(k.opensslName,x,b);_.setAutoPadding(!1);var E,j=[];for(_.once("error",(function(e){if(-1!==e.toString().indexOf("bad decrypt"))throw new Error("Incorrect passphrase supplied, could not decrypt key");throw e})),_.write(y),_.end();null!==(E=_.read());)j.push(E);y=s.concat(j);break;default:throw new Error('OpenSSH-format key uses unknown KDF "'+m+'"')}if((e=(t=new l({buffer:y})).readInt())!==(g=t.readInt()))throw new Error("Incorrect passphrase supplied, could not decrypt key");return u={},e=h.readInternal(u,"private",t.remainder()),t.skip(u.consumed),g=t.readString(),e.comment=g,e},write:function(e,t){var u;u=c.isPrivateKey(e)?e.toPublic():e;var h,p,f="none",m="none",g=s.alloc(0),y={blockSize:8};if(void 0!==t&&void 0!==(h="string"==typeof(h=t.passphrase)?s.from(h,"utf-8"):h)&&(a.buffer(h,"options.passphrase"),a.optionalString(t.cipher,"options.cipher"),void 0===(f=t.cipher)&&(f="aes128-ctr"),y=n.opensshCipherInfo(f),m="bcrypt"),c.isPrivateKey(e)){p=new l({});t=o.randomBytes(4).readUInt32BE(0);for(var v=(p.writeInt(t),p.writeInt(t),p.write(e.toBuffer("rfc4253")),p.writeString(e.comment||""),1);p._offset%y.blockSize!=0;)p.writeChar(v++);p=p.toBuffer()}switch(m){case"none":break;case"bcrypt":var b=o.randomBytes(16),w=((w=new l({})).writeBuffer(b),w.writeInt(16),g=w.toBuffer(),void 0===i&&(i=r(274)),new Uint8Array(h)),k=(b=new Uint8Array(b),new Uint8Array(y.keySize+y.blockSize));if(0!==i.pbkdf(w,w.length,b,b.length,k,k.length,16))throw new Error("bcrypt_pbkdf function returned failure, parameters invalid");w=(k=s.from(k)).slice(0,y.keySize),b=k.slice(y.keySize,y.keySize+y.blockSize);var x=o.createCipheriv(y.opensslName,w,b);x.setAutoPadding(!1);var S,_=[];for(x.once("error",(function(e){throw e})),x.write(p),x.end();null!==(S=x.read());)_.push(S);p=s.concat(_);break;default:throw new Error("Unsupported kdf "+m)}var E=new l({});E.writeCString(d),E.writeString(f),E.writeString(m),E.writeBuffer(g),E.writeInt(1),E.writeBuffer(u.toBuffer("rfc4253")),p&&E.writeBuffer(p),E=E.toBuffer(),t=c.isPrivateKey(e)?"OPENSSH PRIVATE KEY":"OPENSSH PUBLIC KEY";var j=E.toString("base64"),A=(f=j.length+j.length/70+18+16+2*t.length+10,E=s.alloc(f),0);A+=E.write("-----BEGIN "+t+"-----\n",A);for(var R=0;R<j.length;){var I=R+70;I>j.length&&(I=j.length),A+=E.write(j.slice(R,I),A),E[A++]=10,R=I}return A+=E.write("-----END "+t+"-----\n",A),E.slice(0,A)}};var i,a=r(10),s=(r(57),r(12).Buffer),n=(r(30),r(25)),o=r(8),c=(r(23),r(24)),u=r(65),h=r(66),l=r(91),p=r(51),d="openssh-key-v1"},function(e,t,r){var i=r(58);const a=r(82),s=r(17),n=r(28),o=r(7),c=r(0),{Transform:u,ContractType:h,HtlcStatus:l,ContractEnvType:p}=r(5),d=new u("\n /*携带合约信息*/\n HTLCSUGGEST var_contract DROP\n /*校验秘密,持有秘密者才可执行*/\n HASH160 var_ab EQUALVERIFY \n IF\n /*Bob确认时执行: 校验Bob签名*/\n DUP HASH160 var_ba EQUALVERIFY CHECKSIG\n ELSE\n /*Alice取消时执行: 校验延时和Alice签名*/\n var_period CHECKSEQUENCEVERIFY DROP\n DUP HASH160 var_aa EQUALVERIFY CHECKSIG\n ENDIF\n");e.exports=class extends i{async confirm(){var{env:e,output:t,hash:r,i:i,data:s,height:n}=this.options,o=t.getHashs("hex"),r={type:"suggest",src:a.protocol+"."+e.network.type,dst:s.dst,shash:r,sidx:i,sheight:n,pst:l.Sent,amount:t.value,rate:s.rate,ab:t.script.code[4].data.toString("hex"),aa:o[1],ba:o[0]};await e.setSuggest(r),e.mode==p.Block&&e.node.transmit("htlcsuggest.receive",r)}async unconfirm(){var{env:e,data:t}=this.options,t={shash:t.hash,sidx:t.index};await e.delHtlc(t)}async spent(e){var t=this.options.env,r=t.htlcList.get(""+e.prevout.hash+e.prevout.index);r&&(81==e.script.code[2].value?(r.pst=l.Finished,await t.setSuggest(r),t.mode==p.Block&&t.node.transmit("htlcsuggest.deal",r)):(r.pst=l.Cancel,await t.setSuggest(r),t.mode==p.Block&&t.node.transmit("htlcsuggest.cancel",r)))}async verify(){var{output:e,data:t}=this.options,r=(t={oper:h.htlcSuggest,rate:t.rate,dst:t.dst},e.getHashs("hex")),i=e.script.code[4].data.toString("hex"),t={contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),ab:"0x"+i.toString("hex"),aa:"0x"+r[1].toString("hex"),ba:"0x"+r[0].toString("hex"),period:2*o.HTLC_CANCEL_PERIOD};i=s.fromString(d.replace(t));return c(i.toString()===e.script.toString()),!0}static create(e){var t={oper:h.htlcSuggest,rate:e.rate,dst:e.dst};t={contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),ab:"0x"+e.ab.toString("hex"),aa:"0x"+e.aa.toString("hex"),ba:"0x"+e.ba.toString("hex"),period:2*o.HTLC_CANCEL_PERIOD},t=s.fromString(d.replace(t));return n.fromScript(t,e.amount)}}},function(e,t,r){var i=r(58);const a=r(82),s=r(17),n=r(28),o=r(7),{Transform:c,ContractType:u,HtlcStatus:h,ContractEnvType:l}=r(5),p=r(0),d=new c("\n /*携带合约信息*/\n HTLCASSENT var_contract DROP\n IF\n /*Alice确认时执行: 校验签名*/\n DUP HASH160 var_ab EQUALVERIFY CHECKSIG\n ELSE\n /*Bob取消时执行: 校验延时和签名*/\n var_period CHECKSEQUENCEVERIFY DROP\n DUP HASH160 var_bb EQUALVERIFY CHECKSIG\n ENDIF\n");e.exports=class extends i{async confirm(){var{env:e,i:t,output:r,hash:i,height:s,data:n}=this.options,r=r.getHashs("hex"),i={src:n.src,dst:a.protocol+"."+e.network.type,shash:n.hash,sidx:n.index,ahash:i,aidx:t,aheight:s,pst:h.Assent,amount:n.value,rate:n.rate,ab:r[0],bb:r[1]};await e.setAssent(i),e.mode==l.Block&&e.node.transmit("htlcassent.receive",i)}async unconfirm(){var{env:e,data:t}=this.options,t={shash:t.hash,sidx:t.index};await e.delHtlc(t)}async spent(e){var t=this.options.env,r=t.htlcList.query([["ahash",e.prevout.hash],["aidx",e.prevout.index]]);r&&1===r.list.length&&r.list[0].pst===h.Assent&&(r=r.list[0],81==e.script.code[2].value?(r.secret=e.script.code[1].data.toString("hex"),r.pst=h.Deal,await t.setAssent(r),t.mode==l.Block&&t.node.transmit("htlcassent.deal",r)):(r.pst=h.Cancel,await t.setAssent(r),t.mode==l.Block&&t.node.transmit("htlcassent.cancel",r)))}async verify(){var{output:e,data:t}=this.options,r=(t={oper:u.htlcAssent,hash:t.hash,index:t.index},e.getHashs("hex")),t=s.fromString(d.replace({contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),ab:"0x"+r[0].toString("hex"),bb:"0x"+r[1].toString("hex"),period:o.HTLC_CANCEL_PERIOD}));return p(t.toString()===e.script.toString()),!0}static create(e){var t={oper:u.htlcAssent,hash:e.hash,index:e.index};t=s.fromString(d.replace({contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),ab:"0x"+e.ab.toString("hex"),bb:"0x"+e.bb.toString("hex"),period:o.HTLC_CANCEL_PERIOD}));return n.fromScript(t,e.amount)}}},function(e,t,r){var i=r(58);const a=r(17),s=r(28),n=r(0),{Transform:o,ContractType:c,ContractEnvType:u}=r(5),h=r(13),l=r(72).verifyData,p=new o("\n /*携带合约信息*/\n COMMENT var_contract DROP\n /*Bob确认时执行: 校验Bob签名*/\n DUP HASH160 var_bob EQUALVERIFY CHECKSIG\n");e.exports=class extends i{async insert(){var{env:e,output:t,hash:r,i:i,data:a}=this.options,t=h.fromWitnessPubkeyhash(t.getHash(),e.network).toString(),r={shash:r,sidx:i,alice:a.payload.addr,bob:t,body:a.payload.body};e.mode==u.Wallet&&await e.setComment(r)}async erase(){var{env:e,hash:t,i:r}=this.options,t={shash:t,sidx:r};e.mode==u.Wallet&&await e.delComment(t)}async verify(){var{output:e,data:t}=this.options,r=e.getHash();r=a.fromString(p.replace({contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),bob:"0x"+r.toString("hex")})),n(r.toString()===e.script.toString()),r=t.payload.sig;return delete(t=t.payload).sig,n.strictEqual(!0,l({data:t,sig:r})),!0}static create(e){var t={oper:c.comment,payload:e};t={contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),bob:"0x"+h.fromString(e.bob).hash.toString("hex")},t=a.fromString(p.replace(t));return s.fromScript(t,e.amount)}}},function(e,t,r){"use strict";
318
318
  /*!
319
319
  * netaddress.js - network address object for vallnet
320
320
  * Copyright (c) 2019-2022, Bookman Software (MIT License).
package/lib/gamegold.js CHANGED
@@ -206,7 +206,7 @@ let r=[];[i(557),i(558),i(559),i(560),i(561),i(562),i(563),i(564),i(565),i(566),
206
206
  * pkg.js - package constants
207
207
  * Copyright (c) 2019-2022, Bookman Software (MIT License).
208
208
  * https://github.com/bookmansoft/gamegold
209
- */t.protocol="vallnet",t.version="v5.0.11",t.url="https://github.com/bookmansoft/gamegold"},function(e,t,i){"use strict";
209
+ */t.protocol="vallnet",t.version="v5.1.2",t.url="https://github.com/bookmansoft/gamegold"},function(e,t,i){"use strict";
210
210
  /*!
211
211
  * common.js - p2p constants for vallnet
212
212
  * Copyright (c) 2019-2022, Bookman Software (MIT License).
@@ -328,7 +328,7 @@ const r=i(20).opcodes;function s(e){let t=null;var i=s.list[e.type];return new(i
328
328
  * merkleblock.js - merkleblock object for vallnet
329
329
  * Copyright (c) 2019-2022, Bookman Software (MIT License).
330
330
  * https://github.com/bookmansoft/gamegold
331
- */const r=i(0),s=i(2),n=i(1),a=i(4),o=i(3),c=i(6),h=i(7);var u=i(115);const l=i(89),p=Buffer.from([0]);class d extends u{constructor(e){super(),this.txs=[],this.hashes=[],this.flags=p,this.totalTX=0,this._tree=null,e&&this.fromOptions(e)}fromOptions(e){if(this.parseOptions(e),r(e,"MerkleBlock data is required."),r(Array.isArray(e.hashes)),r(Buffer.isBuffer(e.flags)),r(s.isU32(e.totalTX)),e.hashes)for(var t of e.hashes)"string"==typeof t&&(t=Buffer.from(t,"hex")),r(Buffer.isBuffer(t)),this.hashes.push(t);return e.flags&&(r(Buffer.isBuffer(e.flags)),this.flags=e.flags),null!=e.totalTX&&(r(s.isU32(e.totalTX)),this.totalTX=e.totalTX),this}static fromOptions(e){return(new d).fromOptions(e)}refresh(e){if(this._refresh(),this._tree=null,e)for(const e of this.txs)e.refresh()}hasTX(e){return-1!==this.indexOf(e)}indexOf(e){return null==(e=this.getTree().map.get(e))?-1:e}verifyBody(){var[e]=this.checkBody();return e}checkBody(){return this.getTree().root!==this.merkleRoot?[!1,"bad-txnmrklroot",100]:[!0,"valid",0]}getTree(){if(!this._tree)try{this._tree=this.extractTree()}catch(e){this._tree=new f}return this._tree}extractTree(){const e=[],t=[],i=new Map,r=this.hashes,s=this.flags,n=this.totalTX;let a=0,u=0,l=!1,p=0;const d=e=>n+(1<<e)-1>>>e,m=(n,h)=>{if(a>=8*s.length)return l=!0,o.ZERO_HASH;var p,f=s[a/8|0]>>>a%8&1;if(a++,0===n||!f)return u>=r.length?(l=!0,o.ZERO_HASH):(p=r[u++],0===n&&f&&(f=p.toString("hex"),e.push(p),t.push(h),i.set(f,h)),p);let g;return f=m(n-1,2*h),2*h+1<d(n-1)?(g=m(n-1,2*h+1)).equals(f)&&(l=!0):g=f,c.root256(f,g)};if(0===n)throw new Error("Zero transactions.");if(n>(h.MAX_BLOCK_SIZE-81)/60)throw new Error("Too many transactions.");if(r.length>n)throw new Error("Too many hashes.");if(8*s.length<r.length)throw new Error("Flags too small.");for(;1<d(p);)p++;var g=m(p,0);if(l)throw new Error("Mutated merkle tree.");if(((a+7)/8|0)!==s.length)throw new Error("Too many flag bits.");if(u!==r.length)throw new Error("Incorrect number of hashes.");return new f(g,e,t,i)}getCoinbaseHeight(){return-1}inspect(){return this.format()}format(e,t){return{hash:this.rhash(),height:null!=t?t:-1,date:s.date(this.time),version:s.hex32(this.version),prevBlock:s.revHex(this.prevBlock),merkleRoot:s.revHex(this.merkleRoot),time:this.time,bits:this.bits,nonce:this.nonce,totalTX:this.totalTX,hashes:this.hashes.map(e=>e.toString("hex")),flags:this.flags,map:this.getTree().map,txs:this.txs.length}}getSize(){return 84+o.sizeVarint(this.hashes.length)+32*this.hashes.length+o.sizeVarint(this.flags.length)+this.flags.length}toWriter(e){this.writeHead(e),e.writeU32(this.totalTX),e.writeVarint(this.hashes.length);for(const t of this.hashes)e.writeHash(t);return e.writeVarBytes(this.flags),e}toRaw(){var e=this.getSize();return this.toWriter(new a(e)).render()}fromReader(e){this.readHead(e),this.totalTX=e.readU32();var t=e.readVarint();for(let i=0;i<t;i++)this.hashes.push(e.readHash());return this.flags=e.readVarBytes(),this}fromRaw(e){return this.fromReader(new n(e))}static fromReader(e){return(new d).fromReader(e)}static fromRaw(e,t){return"string"==typeof e&&(e=Buffer.from(e,t)),(new d).fromRaw(e)}toJSON(){return this.getJSON()}getJSON(e,t,i){return{hash:this.rhash(),height:i,version:this.version,prevBlock:s.revHex(this.prevBlock),merkleRoot:s.revHex(this.merkleRoot),time:this.time,bits:this.bits,nonce:this.nonce,totalTX:this.totalTX,hashes:this.hashes.map(e=>s.revHex(e.toString("hex"))),flags:this.flags.toString("hex")}}fromJSON(e){for(var t of(r(e,"MerkleBlock data is required."),r(Array.isArray(e.hashes)),r("string"==typeof e.flags),r(s.isU32(e.totalTX)),this.parseJSON(e),e.hashes))t=s.revHex(t),this.hashes.push(Buffer.from(t,"hex"));return this.flags=Buffer.from(e.flags,"hex"),this.totalTX=e.totalTX,this}static fromJSON(e){return(new d).fromJSON(e)}static fromBlock(e,t){var i=[];for(const r of e.txs)i.push(r.isWatched(t)?1:0);return d.fromMatches(e,i)}static fromHashes(e,t){var i,r=new Set;for(i of t)Buffer.isBuffer(i)&&(i=i.toString("hex")),r.add(i);var s=[];for(const t of e.txs){var n=t.hash("hex");s.push(r.has(n)?1:0)}return d.fromMatches(e,s)}static fromMatches(e,t){var i=[],r=[];const s=[],n=[],a=e.txs.length;let o=0;const h=e=>a+(1<<e)-1>>>e,u=(e,t,i)=>{if(0===e)return i[t];var r=u(e-1,2*t,i);let s;return s=2*t+1<h(e-1)?u(e-1,2*t+1,i):r,c.root256(r,s)},l=(e,t,i,r)=>{let o=0;for(let i=t<<e;i<t+1<<e&&i<a;i++)o|=r[i];s.push(o),0!==e&&o?(l(e-1,2*t,i,r),2*t+1<h(e-1)&&l(e-1,2*t+1,i,r)):n.push(u(e,t,i))};for(let s=0;s<e.txs.length;s++){var p=e.txs[s];t[s]&&i.push(p),r.push(p.hash())}for(;1<h(o);)o++;l(o,0,r,t);var f=Buffer.allocUnsafe((s.length+7)/8|0);f.fill(0);for(let e=0;e<s.length;e++)f[e/8|0]|=s[e]<<e%8;var m=new d;return m._hash=e._hash,m._hhash=e._hhash,m.version=e.version,m.prevBlock=e.prevBlock,m.merkleRoot=e.merkleRoot,m.time=e.time,m.bits=e.bits,m.nonce=e.nonce,m.totalTX=a,m.hashes=n,m.flags=f,m.txs=i,m}static isMerkleBlock(e){return e instanceof d}toHeaders(){return l.fromBlock(this)}}function f(e,t,i,r){this.root=e?e.toString("hex"):o.NULL_HASH,this.matches=t||[],this.indexes=i||[],this.map=r||new Map}e.exports=d},function(e,t,i){const r=i(5).PropStatus;i=i(35);class s extends i{constructor(e){super(),this.db=e||{getVp:async e=>this.get(e),setVp:e=>{this.set(e.pid,e)},delVp:e=>{this.delete(e)},loadVpList:()=>{}}}async loadHistory(){}setAccount(e,t,i){var r;e&&e.wid&&e.account&&(r=e.wid+"."+e.account,this.account.get(r))&&this.account.get(r).delete(e.pid),e.wid=t,e.account=i,t&&i&&(r=e.wid+"."+e.account,this.account.get(r)||this.account.set(r,new Map),this.account.get(r).set(e.pid,e))}delAccount(e){var t;e&&e.wid&&e.account&&(t=e.wid+"."+e.account,this.account.get(t))&&this.account.get(t).delete(e.pid)}async getVp(e){return this.db.getVp(e)}async getVpByAddress(e){return this.db.getVpByAddress(e)}async getVpByOid(e){return this.db.getVpByOid(e)}async setVp(e,t){e=new n(e),await this.db.setVp(e,t)}async delVp(e){this.delete(e.pid),await this.db.delVp(e)}}class n{constructor(e){this.fromOptions(e=e||{})}fromOptions(e){this.pid=e.pid,this.cid=e.cid||"",this.oid=e.oid||"",this.gold=e.gold,this.current=null,e.current&&(this.current={},this.current.hash=e.current.hash,this.current.index=e.current.index,this.current.address=e.current.address),this.height=e.height,this.pst=e.pst||r.Ready,this.wid=e.wid||0,this.account=e.account||"",this.bid=null,e.bid&&(this.bid={},this.bid.raw=e.bid.raw||"",this.bid.fixed=e.bid.fixed||0,this.bid.period=e.bid.period||0,this.bid.hash=e.bid.hash||"",this.bid.value=e.bid.value||0,this.bid.address=e.bid.address||"")}toRaw(){var e={};return e.pid=this.pid,e.cid=this.cid||"",e.oid=this.oid||"",e.gold=this.gold,this.current&&(e.current={},e.current.hash=this.current.hash,e.current.index=this.current.index,e.current.address=this.current.address),e.height=this.height,e.pst=this.pst||r.Ready,e.wid=this.wid||0,e.account=this.account||"",this.bid&&(e.bid={},e.bid.raw=this.bid.raw||"",e.bid.fixed=this.bid.fixed||0,e.bid.period=this.bid.period||0,e.bid.hash=this.bid.hash||"",e.bid.value=this.bid.value||0,e.bid.address=this.bid.address||""),Buffer.from(JSON.stringify(e),"utf-8")}fromRaw(e){return e=JSON.parse(e.toString("utf8")),this.fromOptions(e),this}static fromRaw(e){return(new n).fromRaw(e)}}s.vpItem=n,e.exports=s},function(e,t,i){var r=i(10),s=i(175),n=(i=i(9),{sha1:!0,sha256:!0,sha512:!0}),a={rsa:!0,dsa:!0,ecdsa:!0};function o(e,t){Error.captureStackTrace&&Error.captureStackTrace(this,t||o),this.message=e,this.name=t.name}function c(e){o.call(this,e,c)}i.inherits(o,Error),i.inherits(c,o),e.exports={HASH_ALGOS:n,PK_ALGOS:a,HttpSignatureError:o,InvalidAlgorithmError:c,validateAlgorithm:function(e){if(2!==(e=e.toLowerCase().split("-")).length)throw new c(e[0].toUpperCase()+" is not a valid algorithm");if("hmac"!==e[0]&&!a[e[0]])throw new c(e[0].toUpperCase()+" type keys are not supported");if(n[e[1]])return e;throw new c(e[1].toUpperCase()+" is not a supported hash algorithm")},sshKeyToPEM:function(e){return r.string(e,"ssh_key"),s.parseKey(e,"ssh").toString("pem")},fingerprint:function(e){return r.string(e,"ssh_key"),s.parseKey(e,"ssh").fingerprint("md5").toString("hex")},pemToRsaSSHKey:function(e,t){return r.equal("string",typeof e,"typeof pem"),(e=s.parseKey(e,"pem")).comment=t,e.toString("ssh")}}},function(e,t,i){var r=i(102).BigInteger,s=r.prototype.Barrett;function n(e,t){this.x=t,this.q=e}function a(e,t,i,s){this.curve=e,this.x=t,this.y=i,this.z=null==s?r.ONE:s,this.zinv=null}function o(e,t,i){this.q=e,this.a=this.fromBigInteger(t),this.b=this.fromBigInteger(i),this.infinity=new a(this,null,null),this.reducer=new s(this.q)}n.prototype.equals=function(e){return e==this||this.q.equals(e.q)&&this.x.equals(e.x)},n.prototype.toBigInteger=function(){return this.x},n.prototype.negate=function(){return new n(this.q,this.x.negate().mod(this.q))},n.prototype.add=function(e){return new n(this.q,this.x.add(e.toBigInteger()).mod(this.q))},n.prototype.subtract=function(e){return new n(this.q,this.x.subtract(e.toBigInteger()).mod(this.q))},n.prototype.multiply=function(e){return new n(this.q,this.x.multiply(e.toBigInteger()).mod(this.q))},n.prototype.square=function(){return new n(this.q,this.x.square().mod(this.q))},n.prototype.divide=function(e){return new n(this.q,this.x.multiply(e.toBigInteger().modInverse(this.q)).mod(this.q))},a.prototype.getX=function(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var e=this.x.toBigInteger().multiply(this.zinv);return this.curve.reduce(e),this.curve.fromBigInteger(e)},a.prototype.getY=function(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var e=this.y.toBigInteger().multiply(this.zinv);return this.curve.reduce(e),this.curve.fromBigInteger(e)},a.prototype.equals=function(e){return e==this||(this.isInfinity()?e.isInfinity():e.isInfinity()?this.isInfinity():!!e.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(e.z)).mod(this.curve.q).equals(r.ZERO)&&e.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(e.z)).mod(this.curve.q).equals(r.ZERO))},a.prototype.isInfinity=function(){return null==this.x&&null==this.y||this.z.equals(r.ZERO)&&!this.y.toBigInteger().equals(r.ZERO)},a.prototype.negate=function(){return new a(this.curve,this.x,this.y.negate(),this.z)},a.prototype.add=function(e){var t,i,s,n,o,c,h;return this.isInfinity()?e:e.isInfinity()?this:(t=e.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(e.z)).mod(this.curve.q),o=e.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(e.z)).mod(this.curve.q),r.ZERO.equals(o)?r.ZERO.equals(t)?this.twice():this.curve.getInfinity():(h=new r("3"),c=this.x.toBigInteger(),i=this.y.toBigInteger(),e.x.toBigInteger(),e.y.toBigInteger(),s=(n=o.square()).multiply(o),c=c.multiply(n),o=(n=t.square().multiply(this.z)).subtract(c.shiftLeft(1)).multiply(e.z).subtract(s).multiply(o).mod(this.curve.q),c=c.multiply(h).multiply(t).subtract(i.multiply(s)).subtract(n.multiply(t)).multiply(e.z).add(t.multiply(s)).mod(this.curve.q),h=s.multiply(this.z).multiply(e.z).mod(this.curve.q),new a(this.curve,this.curve.fromBigInteger(o),this.curve.fromBigInteger(c),h)))},a.prototype.twice=function(){var e,t,i,s,n,o;return this.isInfinity()?this:0==this.y.toBigInteger().signum()?this.curve.getInfinity():(n=new r("3"),o=this.x.toBigInteger(),t=(e=(t=this.y.toBigInteger()).multiply(this.z)).multiply(t).mod(this.curve.q),s=this.curve.a.toBigInteger(),i=o.square().multiply(n),s=(i=(i=r.ZERO.equals(s)?i:i.add(this.z.square().multiply(s))).mod(this.curve.q)).square().subtract(o.shiftLeft(3).multiply(t)).shiftLeft(1).multiply(e).mod(this.curve.q),n=i.multiply(n).multiply(o).subtract(t.shiftLeft(1)).shiftLeft(2).multiply(t).subtract(i.square().multiply(i)).mod(this.curve.q),o=e.square().multiply(e).shiftLeft(3).mod(this.curve.q),new a(this.curve,this.curve.fromBigInteger(s),this.curve.fromBigInteger(n),o))},a.prototype.multiply=function(e){if(this.isInfinity())return this;if(0==e.signum())return this.curve.getInfinity();for(var t=e,i=t.multiply(new r("3")),s=this.negate(),n=this,a=i.bitLength()-2;0<a;--a){n=n.twice();var o=i.testBit(a);o!=t.testBit(a)&&(n=n.add(o?this:s))}return n},a.prototype.multiplyTwo=function(e,t,i){for(var r=e.bitLength()>i.bitLength()?e.bitLength()-1:i.bitLength()-1,s=this.curve.getInfinity(),n=this.add(t);0<=r;)s=s.twice(),e.testBit(r)?s=i.testBit(r)?s.add(n):s.add(this):i.testBit(r)&&(s=s.add(t)),--r;return s},o.prototype.getQ=function(){return this.q},o.prototype.getA=function(){return this.a},o.prototype.getB=function(){return this.b},o.prototype.equals=function(e){return e==this||this.q.equals(e.q)&&this.a.equals(e.a)&&this.b.equals(e.b)},o.prototype.getInfinity=function(){return this.infinity},o.prototype.fromBigInteger=function(e){return new n(this.q,e)},o.prototype.reduce=function(e){this.reducer.reduce(e)},o.prototype.encodePointHex=function(e){if(e.isInfinity())return"00";var t=e.getX().toBigInteger().toString(16),i=e.getY().toBigInteger().toString(16),r=this.getQ().toString(16).length;for(r%2!=0&&r++;t.length<r;)t="0"+t;for(;i.length<r;)i="0"+i;return"04"+t+i},o.prototype.decodePointHex=function(e){switch(parseInt(e.substr(0,2),16)){case 0:return this.infinity;case 2:c=!1;case 3:null==c&&(c=!0);var t=e.length-2,i=e.substr(2,t),s=this.fromBigInteger(new r(i,16)),n=s.multiply(s.square().add(this.getA())).add(this.getB()).sqrt();if(null==n)throw"Invalid point compression";var o=n.toBigInteger();return o.testBit(0)!=c&&(n=this.fromBigInteger(this.getQ().subtract(o))),new a(this,s,n);case 4:case 6:case 7:t=(e.length-2)/2,i=e.substr(2,t);var c=e.substr(t+2,t);return new a(this,this.fromBigInteger(new r(i,16)),this.fromBigInteger(new r(c,16)));default:return null}},o.prototype.encodeCompressedPointHex=function(e){if(e.isInfinity())return"00";var t=e.getX().toBigInteger().toString(16),i=this.getQ().toString(16).length;for(i%2!=0&&i++;t.length<i;)t="0"+t;return(e.getY().toBigInteger().isEven()?"02":"03")+t},n.prototype.getR=function(){var e;return null==this.r&&(this.r=null,128<(e=this.q.bitLength())&&-1==this.q.shiftRight(e-64).intValue())&&(this.r=r.ONE.shiftLeft(e).subtract(this.q)),this.r},n.prototype.modMult=function(e,t){return this.modReduce(e.multiply(t))},n.prototype.modReduce=function(e){if(null!=this.getR()){for(var t=q.bitLength();e.bitLength()>t+1;){var i=e.shiftRight(t),s=e.subtract(i.shiftLeft(t));e=(i=this.getR().equals(r.ONE)?i:i.multiply(this.getR())).add(s)}for(;0<=e.compareTo(q);)e=e.subtract(q)}else e=e.mod(q);return e},n.prototype.sqrt=function(){if(!this.q.testBit(0))throw"unsupported";var e;if(this.q.testBit(1))return(e=new n(this.q,this.x.modPow(this.q.shiftRight(2).add(r.ONE),this.q))).square().equals(this)?e:null;var t=this.q.subtract(r.ONE),i=t.shiftRight(1);if(this.x.modPow(i,this.q).equals(r.ONE)){var s,a=t.shiftRight(2).shiftLeft(1).add(r.ONE),o=this.x,c=modDouble(modDouble(o));do{for(;0<=(s=new r(this.q.bitLength(),new SecureRandom)).compareTo(this.q)||!s.multiply(s).subtract(c).modPow(i,this.q).equals(t););var h=(u=this.lucasSequence(s,o,a))[0],u=u[1];if(this.modMult(u,u).equals(c))return u=(u=u.testBit(0)?u.add(q):u).shiftRight(1),new n(q,u)}while(h.equals(r.ONE)||h.equals(t))}return null},n.prototype.lucasSequence=function(e,t,i){for(var s=i.bitLength(),n=i.getLowestSetBit(),a=r.ONE,o=r.TWO,c=e,h=r.ONE,u=r.ONE,l=s-1;n+1<=l;--l)h=this.modMult(h,u),i.testBit(l)?(u=this.modMult(h,t),a=this.modMult(a,c),o=this.modReduce(c.multiply(o).subtract(e.multiply(h))),c=this.modReduce(c.multiply(c).subtract(u.shiftLeft(1)))):(u=h,a=this.modReduce(a.multiply(o).subtract(h)),c=this.modReduce(c.multiply(o).subtract(e.multiply(h))),o=this.modReduce(o.multiply(o).subtract(h.shiftLeft(1))));for(h=this.modMult(h,u),u=this.modMult(h,t),a=this.modReduce(a.multiply(o).subtract(h)),o=this.modReduce(c.multiply(o).subtract(e.multiply(h))),h=this.modMult(h,u),l=1;l<=n;++l)a=this.modMult(a,o),o=this.modReduce(o.multiply(o).subtract(h.shiftLeft(1))),h=this.modMult(h,h);return[a,o]},e.exports={ECCurveFp:o,ECPointFp:a,ECFieldElementFp:n}},function(e,t,i){e.exports={read:function(e,t){return h.read(e,t)},readSSHPrivate:function(e,t,c){var h=(t=new l({buffer:t})).readCString(),f=(s.strictEqual(h,d,"bad magic string"),t.readString()),m=t.readString();h=t.readBuffer();if(1!==t.readInt())throw new Error("OpenSSH-format key file contains multiple keys: this is unsupported.");var g=t.readBuffer();if("public"===e)return s.ok(t.atEnd(),"excess bytes left after key"),u.read(g);var y=t.readBuffer(),v=(s.ok(t.atEnd(),"excess bytes left after key"),new l({buffer:h}));switch(m){case"none":if("none"!==f)throw new Error('OpenSSH-format key uses KDF "none" but specifies a cipher other than "none"');break;case"bcrypt":var b=v.readBuffer(),w=v.readInt(),k=a.opensshCipherInfo(f);if(void 0===r&&(r=i(274)),"string"==typeof c.passphrase&&(c.passphrase=n.from(c.passphrase,"utf-8")),!n.isBuffer(c.passphrase))throw new p.KeyEncryptedError(c.filename,"OpenSSH");var x=new Uint8Array(c.passphrase),S=(b=new Uint8Array(b),new Uint8Array(k.keySize+k.blockSize));if(0!==r.pbkdf(x,x.length,b,b.length,S,S.length,w))throw new Error("bcrypt_pbkdf function returned failure, parameters invalid");x=(S=n.from(S)).slice(0,k.keySize),b=S.slice(k.keySize,k.keySize+k.blockSize);var _=o.createDecipheriv(k.opensslName,x,b);_.setAutoPadding(!1);var E,R=[];for(_.once("error",(function(e){if(-1!==e.toString().indexOf("bad decrypt"))throw new Error("Incorrect passphrase supplied, could not decrypt key");throw e})),_.write(y),_.end();null!==(E=_.read());)R.push(E);y=n.concat(R);break;default:throw new Error('OpenSSH-format key uses unknown KDF "'+m+'"')}if((e=(t=new l({buffer:y})).readInt())!==(g=t.readInt()))throw new Error("Incorrect passphrase supplied, could not decrypt key");return h={},e=u.readInternal(h,"private",t.remainder()),t.skip(h.consumed),g=t.readString(),e.comment=g,e},write:function(e,t){var h;h=c.isPrivateKey(e)?e.toPublic():e;var u,p,f="none",m="none",g=n.alloc(0),y={blockSize:8};if(void 0!==t&&void 0!==(u="string"==typeof(u=t.passphrase)?n.from(u,"utf-8"):u)&&(s.buffer(u,"options.passphrase"),s.optionalString(t.cipher,"options.cipher"),void 0===(f=t.cipher)&&(f="aes128-ctr"),y=a.opensshCipherInfo(f),m="bcrypt"),c.isPrivateKey(e)){p=new l({});t=o.randomBytes(4).readUInt32BE(0);for(var v=(p.writeInt(t),p.writeInt(t),p.write(e.toBuffer("rfc4253")),p.writeString(e.comment||""),1);p._offset%y.blockSize!=0;)p.writeChar(v++);p=p.toBuffer()}switch(m){case"none":break;case"bcrypt":var b=o.randomBytes(16),w=((w=new l({})).writeBuffer(b),w.writeInt(16),g=w.toBuffer(),void 0===r&&(r=i(274)),new Uint8Array(u)),k=(b=new Uint8Array(b),new Uint8Array(y.keySize+y.blockSize));if(0!==r.pbkdf(w,w.length,b,b.length,k,k.length,16))throw new Error("bcrypt_pbkdf function returned failure, parameters invalid");w=(k=n.from(k)).slice(0,y.keySize),b=k.slice(y.keySize,y.keySize+y.blockSize);var x=o.createCipheriv(y.opensslName,w,b);x.setAutoPadding(!1);var S,_=[];for(x.once("error",(function(e){throw e})),x.write(p),x.end();null!==(S=x.read());)_.push(S);p=n.concat(_);break;default:throw new Error("Unsupported kdf "+m)}var E=new l({});E.writeCString(d),E.writeString(f),E.writeString(m),E.writeBuffer(g),E.writeInt(1),E.writeBuffer(h.toBuffer("rfc4253")),p&&E.writeBuffer(p),E=E.toBuffer(),t=c.isPrivateKey(e)?"OPENSSH PRIVATE KEY":"OPENSSH PUBLIC KEY";var R=E.toString("base64"),A=(f=R.length+R.length/70+18+16+2*t.length+10,E=n.alloc(f),0);A+=E.write("-----BEGIN "+t+"-----\n",A);for(var O=0;O<R.length;){var C=O+70;C>R.length&&(C=R.length),A+=E.write(R.slice(O,C),A),E[A++]=10,O=C}return A+=E.write("-----END "+t+"-----\n",A),E.slice(0,A)}};var r,s=i(10),n=(i(57),i(12).Buffer),a=(i(30),i(25)),o=i(8),c=(i(23),i(24)),h=i(65),u=i(66),l=i(91),p=i(51),d="openssh-key-v1"},function(e,t,i){var r=i(58);const s=i(82),n=i(17),a=i(28),o=i(7),c=i(0),{Transform:h,ContractType:u,HtlcStatus:l,ContractEnvType:p}=i(5),d=new h("\n /*携带合约信息*/\n HTLCSUGGEST var_contract DROP\n /*校验秘密,持有秘密者才可执行*/\n HASH160 var_ab EQUALVERIFY \n IF\n /*Bob确认时执行: 校验Bob签名*/\n DUP HASH160 var_ba EQUALVERIFY CHECKSIG\n ELSE\n /*Alice取消时执行: 校验延时和Alice签名*/\n var_period CHECKSEQUENCEVERIFY DROP\n DUP HASH160 var_aa EQUALVERIFY CHECKSIG\n ENDIF\n");e.exports=class extends r{async confirm(){var{env:e,output:t,hash:i,i:r,data:n,height:a}=this.options,o=t.getHashs("hex"),i={type:"suggest",src:s.protocol+"."+e.network.type,dst:n.dst,shash:i,sidx:r,sheight:a,pst:l.Sent,amount:t.value,rate:n.rate,ab:t.script.code[4].data.toString("hex"),aa:o[1],ba:o[0]};await e.setSuggest(i),e.mode==p.Block&&e.node.transmit("htlcsuggest.receive",i)}async unconfirm(){var{env:e,data:t}=this.options,t={shash:t.hash,sidx:t.index};await e.delHtlc(t)}async spent(e){var t=this.options.env,i=t.htlcList.get(""+e.prevout.hash+e.prevout.index);i&&(81==e.script.code[2].value?(i.pst=l.Finished,await t.setSuggest(i),t.mode==p.Block&&t.node.transmit("htlcsuggest.deal",i)):(i.pst=l.Cancel,await t.setSuggest(i),t.mode==p.Block&&t.node.transmit("htlcsuggest.cancel",i)))}async verify(){var{output:e,data:t}=this.options,i=(t={oper:u.htlcSuggest,rate:t.rate,dst:t.dst},e.getHashs("hex")),r=e.script.code[4].data.toString("hex"),t={contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),ab:"0x"+r.toString("hex"),aa:"0x"+i[1].toString("hex"),ba:"0x"+i[0].toString("hex"),period:2*o.HTLC_CANCEL_PERIOD};r=n.fromString(d.replace(t));return c(r.toString()===e.script.toString()),!0}static create(e){var t={oper:u.htlcSuggest,rate:e.rate,dst:e.dst};t={contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),ab:"0x"+e.ab.toString("hex"),aa:"0x"+e.aa.toString("hex"),ba:"0x"+e.ba.toString("hex"),period:2*o.HTLC_CANCEL_PERIOD},t=n.fromString(d.replace(t));return a.fromScript(t,e.amount)}}},function(e,t,i){var r=i(58);const s=i(82),n=i(17),a=i(28),o=i(7),{Transform:c,ContractType:h,HtlcStatus:u,ContractEnvType:l}=i(5),p=new c("\n /*携带合约信息*/\n HTLCASSENT var_contract DROP\n IF\n /*Alice确认时执行: 校验签名*/\n DUP HASH160 var_ab EQUALVERIFY CHECKSIG\n ELSE\n /*Bob取消时执行: 校验延时和签名*/\n var_period CHECKSEQUENCEVERIFY DROP\n DUP HASH160 var_bb EQUALVERIFY CHECKSIG\n ENDIF\n");e.exports=class extends r{async confirm(){var{env:e,i:t,output:i,hash:r,height:n,data:a}=this.options,i=i.getHashs("hex"),r={src:a.src,dst:s.protocol+"."+e.network.type,shash:a.hash,sidx:a.index,ahash:r,aidx:t,aheight:n,pst:u.Assent,amount:a.value,rate:a.rate,ab:i[0],bb:i[1]};await e.setAssent(r),e.mode==l.Block&&e.node.transmit("htlcassent.receive",r)}async unconfirm(){var{env:e,data:t}=this.options,t={shash:t.hash,sidx:t.index};await e.delHtlc(t)}async spent(e){var t=this.options.env,i=t.htlcList.query([["ahash",e.prevout.hash],["aidx",e.prevout.index]]);i&&1===i.list.length&&i.list[0].pst===u.Assent&&(i=i.list[0],81==e.script.code[2].value?(i.secret=e.script.code[1].data.toString("hex"),i.pst=u.Deal,await t.setAssent(i),t.mode==l.Block&&t.node.transmit("htlcassent.deal",i)):(i.pst=u.Cancel,await t.setAssent(i),t.mode==l.Block&&t.node.transmit("htlcassent.cancel",i)))}async verify(){var{env:e,output:t,data:i}=this.options;return i.dst==s.protocol+"."+e.network.type&&(e={oper:h.htlcAssent,hash:i.hash,index:i.index},i=t.getHashs("hex"),e=n.fromString(p.replace({contract:"0x"+Buffer.from(JSON.stringify(e)).toString("hex"),ab:"0x"+i[0].toString("hex"),bb:"0x"+i[1].toString("hex"),period:o.HTLC_CANCEL_PERIOD})),assert(e.toString()===t.script.toString()),!0)}static create(e){var t={oper:h.htlcAssent,hash:e.hash,index:e.index};t=n.fromString(p.replace({contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),ab:"0x"+e.ab.toString("hex"),bb:"0x"+e.bb.toString("hex"),period:o.HTLC_CANCEL_PERIOD}));return a.fromScript(t,e.amount)}}},function(e,t,i){var r=i(58);const s=i(17),n=i(28),a=i(0),{Transform:o,ContractType:c,ContractEnvType:h}=i(5),u=i(13),l=i(72).verifyData,p=new o("\n /*携带合约信息*/\n COMMENT var_contract DROP\n /*Bob确认时执行: 校验Bob签名*/\n DUP HASH160 var_bob EQUALVERIFY CHECKSIG\n");e.exports=class extends r{async insert(){var{env:e,output:t,hash:i,i:r,data:s}=this.options,t=u.fromWitnessPubkeyhash(t.getHash(),e.network).toString(),i={shash:i,sidx:r,alice:s.payload.addr,bob:t,body:s.payload.body};e.mode==h.Wallet&&await e.setComment(i)}async erase(){var{env:e,hash:t,i:i}=this.options,t={shash:t,sidx:i};e.mode==h.Wallet&&await e.delComment(t)}async verify(){var{output:e,data:t}=this.options,i=e.getHash();i=s.fromString(p.replace({contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),bob:"0x"+i.toString("hex")})),a(i.toString()===e.script.toString()),i=t.payload.sig;return delete(t=t.payload).sig,a.strictEqual(!0,l({data:t,sig:i})),!0}static create(e){var t={oper:c.comment,payload:e};t={contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),bob:"0x"+u.fromString(e.bob).hash.toString("hex")},t=s.fromString(p.replace(t));return n.fromScript(t,e.amount)}}},function(e,t,i){"use strict";
331
+ */const r=i(0),s=i(2),n=i(1),a=i(4),o=i(3),c=i(6),h=i(7);var u=i(115);const l=i(89),p=Buffer.from([0]);class d extends u{constructor(e){super(),this.txs=[],this.hashes=[],this.flags=p,this.totalTX=0,this._tree=null,e&&this.fromOptions(e)}fromOptions(e){if(this.parseOptions(e),r(e,"MerkleBlock data is required."),r(Array.isArray(e.hashes)),r(Buffer.isBuffer(e.flags)),r(s.isU32(e.totalTX)),e.hashes)for(var t of e.hashes)"string"==typeof t&&(t=Buffer.from(t,"hex")),r(Buffer.isBuffer(t)),this.hashes.push(t);return e.flags&&(r(Buffer.isBuffer(e.flags)),this.flags=e.flags),null!=e.totalTX&&(r(s.isU32(e.totalTX)),this.totalTX=e.totalTX),this}static fromOptions(e){return(new d).fromOptions(e)}refresh(e){if(this._refresh(),this._tree=null,e)for(const e of this.txs)e.refresh()}hasTX(e){return-1!==this.indexOf(e)}indexOf(e){return null==(e=this.getTree().map.get(e))?-1:e}verifyBody(){var[e]=this.checkBody();return e}checkBody(){return this.getTree().root!==this.merkleRoot?[!1,"bad-txnmrklroot",100]:[!0,"valid",0]}getTree(){if(!this._tree)try{this._tree=this.extractTree()}catch(e){this._tree=new f}return this._tree}extractTree(){const e=[],t=[],i=new Map,r=this.hashes,s=this.flags,n=this.totalTX;let a=0,u=0,l=!1,p=0;const d=e=>n+(1<<e)-1>>>e,m=(n,h)=>{if(a>=8*s.length)return l=!0,o.ZERO_HASH;var p,f=s[a/8|0]>>>a%8&1;if(a++,0===n||!f)return u>=r.length?(l=!0,o.ZERO_HASH):(p=r[u++],0===n&&f&&(f=p.toString("hex"),e.push(p),t.push(h),i.set(f,h)),p);let g;return f=m(n-1,2*h),2*h+1<d(n-1)?(g=m(n-1,2*h+1)).equals(f)&&(l=!0):g=f,c.root256(f,g)};if(0===n)throw new Error("Zero transactions.");if(n>(h.MAX_BLOCK_SIZE-81)/60)throw new Error("Too many transactions.");if(r.length>n)throw new Error("Too many hashes.");if(8*s.length<r.length)throw new Error("Flags too small.");for(;1<d(p);)p++;var g=m(p,0);if(l)throw new Error("Mutated merkle tree.");if(((a+7)/8|0)!==s.length)throw new Error("Too many flag bits.");if(u!==r.length)throw new Error("Incorrect number of hashes.");return new f(g,e,t,i)}getCoinbaseHeight(){return-1}inspect(){return this.format()}format(e,t){return{hash:this.rhash(),height:null!=t?t:-1,date:s.date(this.time),version:s.hex32(this.version),prevBlock:s.revHex(this.prevBlock),merkleRoot:s.revHex(this.merkleRoot),time:this.time,bits:this.bits,nonce:this.nonce,totalTX:this.totalTX,hashes:this.hashes.map(e=>e.toString("hex")),flags:this.flags,map:this.getTree().map,txs:this.txs.length}}getSize(){return 84+o.sizeVarint(this.hashes.length)+32*this.hashes.length+o.sizeVarint(this.flags.length)+this.flags.length}toWriter(e){this.writeHead(e),e.writeU32(this.totalTX),e.writeVarint(this.hashes.length);for(const t of this.hashes)e.writeHash(t);return e.writeVarBytes(this.flags),e}toRaw(){var e=this.getSize();return this.toWriter(new a(e)).render()}fromReader(e){this.readHead(e),this.totalTX=e.readU32();var t=e.readVarint();for(let i=0;i<t;i++)this.hashes.push(e.readHash());return this.flags=e.readVarBytes(),this}fromRaw(e){return this.fromReader(new n(e))}static fromReader(e){return(new d).fromReader(e)}static fromRaw(e,t){return"string"==typeof e&&(e=Buffer.from(e,t)),(new d).fromRaw(e)}toJSON(){return this.getJSON()}getJSON(e,t,i){return{hash:this.rhash(),height:i,version:this.version,prevBlock:s.revHex(this.prevBlock),merkleRoot:s.revHex(this.merkleRoot),time:this.time,bits:this.bits,nonce:this.nonce,totalTX:this.totalTX,hashes:this.hashes.map(e=>s.revHex(e.toString("hex"))),flags:this.flags.toString("hex")}}fromJSON(e){for(var t of(r(e,"MerkleBlock data is required."),r(Array.isArray(e.hashes)),r("string"==typeof e.flags),r(s.isU32(e.totalTX)),this.parseJSON(e),e.hashes))t=s.revHex(t),this.hashes.push(Buffer.from(t,"hex"));return this.flags=Buffer.from(e.flags,"hex"),this.totalTX=e.totalTX,this}static fromJSON(e){return(new d).fromJSON(e)}static fromBlock(e,t){var i=[];for(const r of e.txs)i.push(r.isWatched(t)?1:0);return d.fromMatches(e,i)}static fromHashes(e,t){var i,r=new Set;for(i of t)Buffer.isBuffer(i)&&(i=i.toString("hex")),r.add(i);var s=[];for(const t of e.txs){var n=t.hash("hex");s.push(r.has(n)?1:0)}return d.fromMatches(e,s)}static fromMatches(e,t){var i=[],r=[];const s=[],n=[],a=e.txs.length;let o=0;const h=e=>a+(1<<e)-1>>>e,u=(e,t,i)=>{if(0===e)return i[t];var r=u(e-1,2*t,i);let s;return s=2*t+1<h(e-1)?u(e-1,2*t+1,i):r,c.root256(r,s)},l=(e,t,i,r)=>{let o=0;for(let i=t<<e;i<t+1<<e&&i<a;i++)o|=r[i];s.push(o),0!==e&&o?(l(e-1,2*t,i,r),2*t+1<h(e-1)&&l(e-1,2*t+1,i,r)):n.push(u(e,t,i))};for(let s=0;s<e.txs.length;s++){var p=e.txs[s];t[s]&&i.push(p),r.push(p.hash())}for(;1<h(o);)o++;l(o,0,r,t);var f=Buffer.allocUnsafe((s.length+7)/8|0);f.fill(0);for(let e=0;e<s.length;e++)f[e/8|0]|=s[e]<<e%8;var m=new d;return m._hash=e._hash,m._hhash=e._hhash,m.version=e.version,m.prevBlock=e.prevBlock,m.merkleRoot=e.merkleRoot,m.time=e.time,m.bits=e.bits,m.nonce=e.nonce,m.totalTX=a,m.hashes=n,m.flags=f,m.txs=i,m}static isMerkleBlock(e){return e instanceof d}toHeaders(){return l.fromBlock(this)}}function f(e,t,i,r){this.root=e?e.toString("hex"):o.NULL_HASH,this.matches=t||[],this.indexes=i||[],this.map=r||new Map}e.exports=d},function(e,t,i){const r=i(5).PropStatus;i=i(35);class s extends i{constructor(e){super(),this.db=e||{getVp:async e=>this.get(e),setVp:e=>{this.set(e.pid,e)},delVp:e=>{this.delete(e)},loadVpList:()=>{}}}async loadHistory(){}setAccount(e,t,i){var r;e&&e.wid&&e.account&&(r=e.wid+"."+e.account,this.account.get(r))&&this.account.get(r).delete(e.pid),e.wid=t,e.account=i,t&&i&&(r=e.wid+"."+e.account,this.account.get(r)||this.account.set(r,new Map),this.account.get(r).set(e.pid,e))}delAccount(e){var t;e&&e.wid&&e.account&&(t=e.wid+"."+e.account,this.account.get(t))&&this.account.get(t).delete(e.pid)}async getVp(e){return this.db.getVp(e)}async getVpByAddress(e){return this.db.getVpByAddress(e)}async getVpByOid(e){return this.db.getVpByOid(e)}async setVp(e,t){e=new n(e),await this.db.setVp(e,t)}async delVp(e){this.delete(e.pid),await this.db.delVp(e)}}class n{constructor(e){this.fromOptions(e=e||{})}fromOptions(e){this.pid=e.pid,this.cid=e.cid||"",this.oid=e.oid||"",this.gold=e.gold,this.current=null,e.current&&(this.current={},this.current.hash=e.current.hash,this.current.index=e.current.index,this.current.address=e.current.address),this.height=e.height,this.pst=e.pst||r.Ready,this.wid=e.wid||0,this.account=e.account||"",this.bid=null,e.bid&&(this.bid={},this.bid.raw=e.bid.raw||"",this.bid.fixed=e.bid.fixed||0,this.bid.period=e.bid.period||0,this.bid.hash=e.bid.hash||"",this.bid.value=e.bid.value||0,this.bid.address=e.bid.address||"")}toRaw(){var e={};return e.pid=this.pid,e.cid=this.cid||"",e.oid=this.oid||"",e.gold=this.gold,this.current&&(e.current={},e.current.hash=this.current.hash,e.current.index=this.current.index,e.current.address=this.current.address),e.height=this.height,e.pst=this.pst||r.Ready,e.wid=this.wid||0,e.account=this.account||"",this.bid&&(e.bid={},e.bid.raw=this.bid.raw||"",e.bid.fixed=this.bid.fixed||0,e.bid.period=this.bid.period||0,e.bid.hash=this.bid.hash||"",e.bid.value=this.bid.value||0,e.bid.address=this.bid.address||""),Buffer.from(JSON.stringify(e),"utf-8")}fromRaw(e){return e=JSON.parse(e.toString("utf8")),this.fromOptions(e),this}static fromRaw(e){return(new n).fromRaw(e)}}s.vpItem=n,e.exports=s},function(e,t,i){var r=i(10),s=i(175),n=(i=i(9),{sha1:!0,sha256:!0,sha512:!0}),a={rsa:!0,dsa:!0,ecdsa:!0};function o(e,t){Error.captureStackTrace&&Error.captureStackTrace(this,t||o),this.message=e,this.name=t.name}function c(e){o.call(this,e,c)}i.inherits(o,Error),i.inherits(c,o),e.exports={HASH_ALGOS:n,PK_ALGOS:a,HttpSignatureError:o,InvalidAlgorithmError:c,validateAlgorithm:function(e){if(2!==(e=e.toLowerCase().split("-")).length)throw new c(e[0].toUpperCase()+" is not a valid algorithm");if("hmac"!==e[0]&&!a[e[0]])throw new c(e[0].toUpperCase()+" type keys are not supported");if(n[e[1]])return e;throw new c(e[1].toUpperCase()+" is not a supported hash algorithm")},sshKeyToPEM:function(e){return r.string(e,"ssh_key"),s.parseKey(e,"ssh").toString("pem")},fingerprint:function(e){return r.string(e,"ssh_key"),s.parseKey(e,"ssh").fingerprint("md5").toString("hex")},pemToRsaSSHKey:function(e,t){return r.equal("string",typeof e,"typeof pem"),(e=s.parseKey(e,"pem")).comment=t,e.toString("ssh")}}},function(e,t,i){var r=i(102).BigInteger,s=r.prototype.Barrett;function n(e,t){this.x=t,this.q=e}function a(e,t,i,s){this.curve=e,this.x=t,this.y=i,this.z=null==s?r.ONE:s,this.zinv=null}function o(e,t,i){this.q=e,this.a=this.fromBigInteger(t),this.b=this.fromBigInteger(i),this.infinity=new a(this,null,null),this.reducer=new s(this.q)}n.prototype.equals=function(e){return e==this||this.q.equals(e.q)&&this.x.equals(e.x)},n.prototype.toBigInteger=function(){return this.x},n.prototype.negate=function(){return new n(this.q,this.x.negate().mod(this.q))},n.prototype.add=function(e){return new n(this.q,this.x.add(e.toBigInteger()).mod(this.q))},n.prototype.subtract=function(e){return new n(this.q,this.x.subtract(e.toBigInteger()).mod(this.q))},n.prototype.multiply=function(e){return new n(this.q,this.x.multiply(e.toBigInteger()).mod(this.q))},n.prototype.square=function(){return new n(this.q,this.x.square().mod(this.q))},n.prototype.divide=function(e){return new n(this.q,this.x.multiply(e.toBigInteger().modInverse(this.q)).mod(this.q))},a.prototype.getX=function(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var e=this.x.toBigInteger().multiply(this.zinv);return this.curve.reduce(e),this.curve.fromBigInteger(e)},a.prototype.getY=function(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var e=this.y.toBigInteger().multiply(this.zinv);return this.curve.reduce(e),this.curve.fromBigInteger(e)},a.prototype.equals=function(e){return e==this||(this.isInfinity()?e.isInfinity():e.isInfinity()?this.isInfinity():!!e.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(e.z)).mod(this.curve.q).equals(r.ZERO)&&e.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(e.z)).mod(this.curve.q).equals(r.ZERO))},a.prototype.isInfinity=function(){return null==this.x&&null==this.y||this.z.equals(r.ZERO)&&!this.y.toBigInteger().equals(r.ZERO)},a.prototype.negate=function(){return new a(this.curve,this.x,this.y.negate(),this.z)},a.prototype.add=function(e){var t,i,s,n,o,c,h;return this.isInfinity()?e:e.isInfinity()?this:(t=e.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(e.z)).mod(this.curve.q),o=e.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(e.z)).mod(this.curve.q),r.ZERO.equals(o)?r.ZERO.equals(t)?this.twice():this.curve.getInfinity():(h=new r("3"),c=this.x.toBigInteger(),i=this.y.toBigInteger(),e.x.toBigInteger(),e.y.toBigInteger(),s=(n=o.square()).multiply(o),c=c.multiply(n),o=(n=t.square().multiply(this.z)).subtract(c.shiftLeft(1)).multiply(e.z).subtract(s).multiply(o).mod(this.curve.q),c=c.multiply(h).multiply(t).subtract(i.multiply(s)).subtract(n.multiply(t)).multiply(e.z).add(t.multiply(s)).mod(this.curve.q),h=s.multiply(this.z).multiply(e.z).mod(this.curve.q),new a(this.curve,this.curve.fromBigInteger(o),this.curve.fromBigInteger(c),h)))},a.prototype.twice=function(){var e,t,i,s,n,o;return this.isInfinity()?this:0==this.y.toBigInteger().signum()?this.curve.getInfinity():(n=new r("3"),o=this.x.toBigInteger(),t=(e=(t=this.y.toBigInteger()).multiply(this.z)).multiply(t).mod(this.curve.q),s=this.curve.a.toBigInteger(),i=o.square().multiply(n),s=(i=(i=r.ZERO.equals(s)?i:i.add(this.z.square().multiply(s))).mod(this.curve.q)).square().subtract(o.shiftLeft(3).multiply(t)).shiftLeft(1).multiply(e).mod(this.curve.q),n=i.multiply(n).multiply(o).subtract(t.shiftLeft(1)).shiftLeft(2).multiply(t).subtract(i.square().multiply(i)).mod(this.curve.q),o=e.square().multiply(e).shiftLeft(3).mod(this.curve.q),new a(this.curve,this.curve.fromBigInteger(s),this.curve.fromBigInteger(n),o))},a.prototype.multiply=function(e){if(this.isInfinity())return this;if(0==e.signum())return this.curve.getInfinity();for(var t=e,i=t.multiply(new r("3")),s=this.negate(),n=this,a=i.bitLength()-2;0<a;--a){n=n.twice();var o=i.testBit(a);o!=t.testBit(a)&&(n=n.add(o?this:s))}return n},a.prototype.multiplyTwo=function(e,t,i){for(var r=e.bitLength()>i.bitLength()?e.bitLength()-1:i.bitLength()-1,s=this.curve.getInfinity(),n=this.add(t);0<=r;)s=s.twice(),e.testBit(r)?s=i.testBit(r)?s.add(n):s.add(this):i.testBit(r)&&(s=s.add(t)),--r;return s},o.prototype.getQ=function(){return this.q},o.prototype.getA=function(){return this.a},o.prototype.getB=function(){return this.b},o.prototype.equals=function(e){return e==this||this.q.equals(e.q)&&this.a.equals(e.a)&&this.b.equals(e.b)},o.prototype.getInfinity=function(){return this.infinity},o.prototype.fromBigInteger=function(e){return new n(this.q,e)},o.prototype.reduce=function(e){this.reducer.reduce(e)},o.prototype.encodePointHex=function(e){if(e.isInfinity())return"00";var t=e.getX().toBigInteger().toString(16),i=e.getY().toBigInteger().toString(16),r=this.getQ().toString(16).length;for(r%2!=0&&r++;t.length<r;)t="0"+t;for(;i.length<r;)i="0"+i;return"04"+t+i},o.prototype.decodePointHex=function(e){switch(parseInt(e.substr(0,2),16)){case 0:return this.infinity;case 2:c=!1;case 3:null==c&&(c=!0);var t=e.length-2,i=e.substr(2,t),s=this.fromBigInteger(new r(i,16)),n=s.multiply(s.square().add(this.getA())).add(this.getB()).sqrt();if(null==n)throw"Invalid point compression";var o=n.toBigInteger();return o.testBit(0)!=c&&(n=this.fromBigInteger(this.getQ().subtract(o))),new a(this,s,n);case 4:case 6:case 7:t=(e.length-2)/2,i=e.substr(2,t);var c=e.substr(t+2,t);return new a(this,this.fromBigInteger(new r(i,16)),this.fromBigInteger(new r(c,16)));default:return null}},o.prototype.encodeCompressedPointHex=function(e){if(e.isInfinity())return"00";var t=e.getX().toBigInteger().toString(16),i=this.getQ().toString(16).length;for(i%2!=0&&i++;t.length<i;)t="0"+t;return(e.getY().toBigInteger().isEven()?"02":"03")+t},n.prototype.getR=function(){var e;return null==this.r&&(this.r=null,128<(e=this.q.bitLength())&&-1==this.q.shiftRight(e-64).intValue())&&(this.r=r.ONE.shiftLeft(e).subtract(this.q)),this.r},n.prototype.modMult=function(e,t){return this.modReduce(e.multiply(t))},n.prototype.modReduce=function(e){if(null!=this.getR()){for(var t=q.bitLength();e.bitLength()>t+1;){var i=e.shiftRight(t),s=e.subtract(i.shiftLeft(t));e=(i=this.getR().equals(r.ONE)?i:i.multiply(this.getR())).add(s)}for(;0<=e.compareTo(q);)e=e.subtract(q)}else e=e.mod(q);return e},n.prototype.sqrt=function(){if(!this.q.testBit(0))throw"unsupported";var e;if(this.q.testBit(1))return(e=new n(this.q,this.x.modPow(this.q.shiftRight(2).add(r.ONE),this.q))).square().equals(this)?e:null;var t=this.q.subtract(r.ONE),i=t.shiftRight(1);if(this.x.modPow(i,this.q).equals(r.ONE)){var s,a=t.shiftRight(2).shiftLeft(1).add(r.ONE),o=this.x,c=modDouble(modDouble(o));do{for(;0<=(s=new r(this.q.bitLength(),new SecureRandom)).compareTo(this.q)||!s.multiply(s).subtract(c).modPow(i,this.q).equals(t););var h=(u=this.lucasSequence(s,o,a))[0],u=u[1];if(this.modMult(u,u).equals(c))return u=(u=u.testBit(0)?u.add(q):u).shiftRight(1),new n(q,u)}while(h.equals(r.ONE)||h.equals(t))}return null},n.prototype.lucasSequence=function(e,t,i){for(var s=i.bitLength(),n=i.getLowestSetBit(),a=r.ONE,o=r.TWO,c=e,h=r.ONE,u=r.ONE,l=s-1;n+1<=l;--l)h=this.modMult(h,u),i.testBit(l)?(u=this.modMult(h,t),a=this.modMult(a,c),o=this.modReduce(c.multiply(o).subtract(e.multiply(h))),c=this.modReduce(c.multiply(c).subtract(u.shiftLeft(1)))):(u=h,a=this.modReduce(a.multiply(o).subtract(h)),c=this.modReduce(c.multiply(o).subtract(e.multiply(h))),o=this.modReduce(o.multiply(o).subtract(h.shiftLeft(1))));for(h=this.modMult(h,u),u=this.modMult(h,t),a=this.modReduce(a.multiply(o).subtract(h)),o=this.modReduce(c.multiply(o).subtract(e.multiply(h))),h=this.modMult(h,u),l=1;l<=n;++l)a=this.modMult(a,o),o=this.modReduce(o.multiply(o).subtract(h.shiftLeft(1))),h=this.modMult(h,h);return[a,o]},e.exports={ECCurveFp:o,ECPointFp:a,ECFieldElementFp:n}},function(e,t,i){e.exports={read:function(e,t){return h.read(e,t)},readSSHPrivate:function(e,t,c){var h=(t=new l({buffer:t})).readCString(),f=(s.strictEqual(h,d,"bad magic string"),t.readString()),m=t.readString();h=t.readBuffer();if(1!==t.readInt())throw new Error("OpenSSH-format key file contains multiple keys: this is unsupported.");var g=t.readBuffer();if("public"===e)return s.ok(t.atEnd(),"excess bytes left after key"),u.read(g);var y=t.readBuffer(),v=(s.ok(t.atEnd(),"excess bytes left after key"),new l({buffer:h}));switch(m){case"none":if("none"!==f)throw new Error('OpenSSH-format key uses KDF "none" but specifies a cipher other than "none"');break;case"bcrypt":var b=v.readBuffer(),w=v.readInt(),k=a.opensshCipherInfo(f);if(void 0===r&&(r=i(274)),"string"==typeof c.passphrase&&(c.passphrase=n.from(c.passphrase,"utf-8")),!n.isBuffer(c.passphrase))throw new p.KeyEncryptedError(c.filename,"OpenSSH");var x=new Uint8Array(c.passphrase),S=(b=new Uint8Array(b),new Uint8Array(k.keySize+k.blockSize));if(0!==r.pbkdf(x,x.length,b,b.length,S,S.length,w))throw new Error("bcrypt_pbkdf function returned failure, parameters invalid");x=(S=n.from(S)).slice(0,k.keySize),b=S.slice(k.keySize,k.keySize+k.blockSize);var _=o.createDecipheriv(k.opensslName,x,b);_.setAutoPadding(!1);var E,R=[];for(_.once("error",(function(e){if(-1!==e.toString().indexOf("bad decrypt"))throw new Error("Incorrect passphrase supplied, could not decrypt key");throw e})),_.write(y),_.end();null!==(E=_.read());)R.push(E);y=n.concat(R);break;default:throw new Error('OpenSSH-format key uses unknown KDF "'+m+'"')}if((e=(t=new l({buffer:y})).readInt())!==(g=t.readInt()))throw new Error("Incorrect passphrase supplied, could not decrypt key");return h={},e=u.readInternal(h,"private",t.remainder()),t.skip(h.consumed),g=t.readString(),e.comment=g,e},write:function(e,t){var h;h=c.isPrivateKey(e)?e.toPublic():e;var u,p,f="none",m="none",g=n.alloc(0),y={blockSize:8};if(void 0!==t&&void 0!==(u="string"==typeof(u=t.passphrase)?n.from(u,"utf-8"):u)&&(s.buffer(u,"options.passphrase"),s.optionalString(t.cipher,"options.cipher"),void 0===(f=t.cipher)&&(f="aes128-ctr"),y=a.opensshCipherInfo(f),m="bcrypt"),c.isPrivateKey(e)){p=new l({});t=o.randomBytes(4).readUInt32BE(0);for(var v=(p.writeInt(t),p.writeInt(t),p.write(e.toBuffer("rfc4253")),p.writeString(e.comment||""),1);p._offset%y.blockSize!=0;)p.writeChar(v++);p=p.toBuffer()}switch(m){case"none":break;case"bcrypt":var b=o.randomBytes(16),w=((w=new l({})).writeBuffer(b),w.writeInt(16),g=w.toBuffer(),void 0===r&&(r=i(274)),new Uint8Array(u)),k=(b=new Uint8Array(b),new Uint8Array(y.keySize+y.blockSize));if(0!==r.pbkdf(w,w.length,b,b.length,k,k.length,16))throw new Error("bcrypt_pbkdf function returned failure, parameters invalid");w=(k=n.from(k)).slice(0,y.keySize),b=k.slice(y.keySize,y.keySize+y.blockSize);var x=o.createCipheriv(y.opensslName,w,b);x.setAutoPadding(!1);var S,_=[];for(x.once("error",(function(e){throw e})),x.write(p),x.end();null!==(S=x.read());)_.push(S);p=n.concat(_);break;default:throw new Error("Unsupported kdf "+m)}var E=new l({});E.writeCString(d),E.writeString(f),E.writeString(m),E.writeBuffer(g),E.writeInt(1),E.writeBuffer(h.toBuffer("rfc4253")),p&&E.writeBuffer(p),E=E.toBuffer(),t=c.isPrivateKey(e)?"OPENSSH PRIVATE KEY":"OPENSSH PUBLIC KEY";var R=E.toString("base64"),A=(f=R.length+R.length/70+18+16+2*t.length+10,E=n.alloc(f),0);A+=E.write("-----BEGIN "+t+"-----\n",A);for(var O=0;O<R.length;){var C=O+70;C>R.length&&(C=R.length),A+=E.write(R.slice(O,C),A),E[A++]=10,O=C}return A+=E.write("-----END "+t+"-----\n",A),E.slice(0,A)}};var r,s=i(10),n=(i(57),i(12).Buffer),a=(i(30),i(25)),o=i(8),c=(i(23),i(24)),h=i(65),u=i(66),l=i(91),p=i(51),d="openssh-key-v1"},function(e,t,i){var r=i(58);const s=i(82),n=i(17),a=i(28),o=i(7),c=i(0),{Transform:h,ContractType:u,HtlcStatus:l,ContractEnvType:p}=i(5),d=new h("\n /*携带合约信息*/\n HTLCSUGGEST var_contract DROP\n /*校验秘密,持有秘密者才可执行*/\n HASH160 var_ab EQUALVERIFY \n IF\n /*Bob确认时执行: 校验Bob签名*/\n DUP HASH160 var_ba EQUALVERIFY CHECKSIG\n ELSE\n /*Alice取消时执行: 校验延时和Alice签名*/\n var_period CHECKSEQUENCEVERIFY DROP\n DUP HASH160 var_aa EQUALVERIFY CHECKSIG\n ENDIF\n");e.exports=class extends r{async confirm(){var{env:e,output:t,hash:i,i:r,data:n,height:a}=this.options,o=t.getHashs("hex"),i={type:"suggest",src:s.protocol+"."+e.network.type,dst:n.dst,shash:i,sidx:r,sheight:a,pst:l.Sent,amount:t.value,rate:n.rate,ab:t.script.code[4].data.toString("hex"),aa:o[1],ba:o[0]};await e.setSuggest(i),e.mode==p.Block&&e.node.transmit("htlcsuggest.receive",i)}async unconfirm(){var{env:e,data:t}=this.options,t={shash:t.hash,sidx:t.index};await e.delHtlc(t)}async spent(e){var t=this.options.env,i=t.htlcList.get(""+e.prevout.hash+e.prevout.index);i&&(81==e.script.code[2].value?(i.pst=l.Finished,await t.setSuggest(i),t.mode==p.Block&&t.node.transmit("htlcsuggest.deal",i)):(i.pst=l.Cancel,await t.setSuggest(i),t.mode==p.Block&&t.node.transmit("htlcsuggest.cancel",i)))}async verify(){var{output:e,data:t}=this.options,i=(t={oper:u.htlcSuggest,rate:t.rate,dst:t.dst},e.getHashs("hex")),r=e.script.code[4].data.toString("hex"),t={contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),ab:"0x"+r.toString("hex"),aa:"0x"+i[1].toString("hex"),ba:"0x"+i[0].toString("hex"),period:2*o.HTLC_CANCEL_PERIOD};r=n.fromString(d.replace(t));return c(r.toString()===e.script.toString()),!0}static create(e){var t={oper:u.htlcSuggest,rate:e.rate,dst:e.dst};t={contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),ab:"0x"+e.ab.toString("hex"),aa:"0x"+e.aa.toString("hex"),ba:"0x"+e.ba.toString("hex"),period:2*o.HTLC_CANCEL_PERIOD},t=n.fromString(d.replace(t));return a.fromScript(t,e.amount)}}},function(e,t,i){var r=i(58);const s=i(82),n=i(17),a=i(28),o=i(7),{Transform:c,ContractType:h,HtlcStatus:u,ContractEnvType:l}=i(5),p=i(0),d=new c("\n /*携带合约信息*/\n HTLCASSENT var_contract DROP\n IF\n /*Alice确认时执行: 校验签名*/\n DUP HASH160 var_ab EQUALVERIFY CHECKSIG\n ELSE\n /*Bob取消时执行: 校验延时和签名*/\n var_period CHECKSEQUENCEVERIFY DROP\n DUP HASH160 var_bb EQUALVERIFY CHECKSIG\n ENDIF\n");e.exports=class extends r{async confirm(){var{env:e,i:t,output:i,hash:r,height:n,data:a}=this.options,i=i.getHashs("hex"),r={src:a.src,dst:s.protocol+"."+e.network.type,shash:a.hash,sidx:a.index,ahash:r,aidx:t,aheight:n,pst:u.Assent,amount:a.value,rate:a.rate,ab:i[0],bb:i[1]};await e.setAssent(r),e.mode==l.Block&&e.node.transmit("htlcassent.receive",r)}async unconfirm(){var{env:e,data:t}=this.options,t={shash:t.hash,sidx:t.index};await e.delHtlc(t)}async spent(e){var t=this.options.env,i=t.htlcList.query([["ahash",e.prevout.hash],["aidx",e.prevout.index]]);i&&1===i.list.length&&i.list[0].pst===u.Assent&&(i=i.list[0],81==e.script.code[2].value?(i.secret=e.script.code[1].data.toString("hex"),i.pst=u.Deal,await t.setAssent(i),t.mode==l.Block&&t.node.transmit("htlcassent.deal",i)):(i.pst=u.Cancel,await t.setAssent(i),t.mode==l.Block&&t.node.transmit("htlcassent.cancel",i)))}async verify(){var{output:e,data:t}=this.options,i=(t={oper:h.htlcAssent,hash:t.hash,index:t.index},e.getHashs("hex")),t=n.fromString(d.replace({contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),ab:"0x"+i[0].toString("hex"),bb:"0x"+i[1].toString("hex"),period:o.HTLC_CANCEL_PERIOD}));return p(t.toString()===e.script.toString()),!0}static create(e){var t={oper:h.htlcAssent,hash:e.hash,index:e.index};t=n.fromString(d.replace({contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),ab:"0x"+e.ab.toString("hex"),bb:"0x"+e.bb.toString("hex"),period:o.HTLC_CANCEL_PERIOD}));return a.fromScript(t,e.amount)}}},function(e,t,i){var r=i(58);const s=i(17),n=i(28),a=i(0),{Transform:o,ContractType:c,ContractEnvType:h}=i(5),u=i(13),l=i(72).verifyData,p=new o("\n /*携带合约信息*/\n COMMENT var_contract DROP\n /*Bob确认时执行: 校验Bob签名*/\n DUP HASH160 var_bob EQUALVERIFY CHECKSIG\n");e.exports=class extends r{async insert(){var{env:e,output:t,hash:i,i:r,data:s}=this.options,t=u.fromWitnessPubkeyhash(t.getHash(),e.network).toString(),i={shash:i,sidx:r,alice:s.payload.addr,bob:t,body:s.payload.body};e.mode==h.Wallet&&await e.setComment(i)}async erase(){var{env:e,hash:t,i:i}=this.options,t={shash:t,sidx:i};e.mode==h.Wallet&&await e.delComment(t)}async verify(){var{output:e,data:t}=this.options,i=e.getHash();i=s.fromString(p.replace({contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),bob:"0x"+i.toString("hex")})),a(i.toString()===e.script.toString()),i=t.payload.sig;return delete(t=t.payload).sig,a.strictEqual(!0,l({data:t,sig:i})),!0}static create(e){var t={oper:c.comment,payload:e};t={contract:"0x"+Buffer.from(JSON.stringify(t)).toString("hex"),bob:"0x"+u.fromString(e.bob).hash.toString("hex")},t=s.fromString(p.replace(t));return n.fromScript(t,e.amount)}}},function(e,t,i){"use strict";
332
332
  /*!
333
333
  * netaddress.js - network address object for vallnet
334
334
  * Copyright (c) 2019-2022, Bookman Software (MIT License).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gamegold",
3
- "version": "5.1.0",
3
+ "version": "5.1.2",
4
4
  "description": "Vallnet Core",
5
5
  "license": "MIT",
6
6
  "repository": "git://github.com/bookmansoft/gamegold",