ychapi 0.945.0 → 0.1192.0

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.
package/dist/api.js CHANGED
@@ -438,49 +438,6 @@ ychapi.get_coin_server_locktime = function(coin) {
438
438
  return ychapi._get_coin_server_locktime(coin);
439
439
  };
440
440
 
441
- /*!
442
- * TODO: may obsolete
443
- *
444
- * @deprecated
445
- * ALERT: API below is expected to be obsolete and planned to be removed in next versions
446
- *
447
- */
448
- ychapi.get_coin_allowed_deposit_senders = function(coin) {
449
- return ychapi._get_coin_allowed_deposit_senders(coin);
450
- };
451
-
452
- /*!
453
- * Register the deposit evm address
454
- * @param {string} coin
455
- * @param {string} address
456
- * @returns {Promise}
457
- * - resolved (no data),
458
- * - rejected with the error from the server
459
- *
460
- * @deprecated
461
- * ALERT: API below is expected to be obsolete and planned to be removed in next versions
462
- *
463
- */
464
- ychapi.call_register_deposit_evm_address = function(coin, address) {
465
- return ychapi._call_register_deposit_evm_address(coin, address);
466
- };
467
-
468
- /*!
469
- * Unregister the deposit evm address
470
- * @param {string} coin
471
- * @param {string} address
472
- * @returns {Promise}
473
- * - resolved (no data),
474
- * - rejected with the error from the server
475
- *
476
- * @deprecated
477
- * ALERT: API below is expected to be obsolete and planned to be removed in next versions
478
- *
479
- */
480
- ychapi.call_unregister_deposit_evm_address = function(coin, address) {
481
- return ychapi._call_unregister_deposit_evm_address(coin, address);
482
- };
483
-
484
441
  /*!
485
442
  * TRADING API
486
443
  */
@@ -1 +1 @@
1
- var coinjs=window.coinjs=function(){};coinjs.bech32={charset:"qpzry9x8gf2tvdw0s3jn54khce6mua7l",version:0,hrp:"bc"},coinjs.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)},coinjs.hash256=function(t){return Crypto.SHA256(Crypto.SHA256(t,{asBytes:!0}),{asBytes:!0})},coinjs.arrayEquals=function(t,e){return Array.isArray(t)&&Array.isArray(e)&&t.length===e.length&&t.every(((t,n)=>t===e[n]))},coinjs.bech32_polymod=function(t){let e=1;const n=[996825010,642813549,513874426,1027748829,705979059];for(let i=0;i<t.length;++i){let r=e>>25;e=(33554431&e)<<5^t[i];for(let t=0;t<5;++t)r>>t&1&&(e^=n[t])}return e},coinjs.bech32_hrpExpand=function(t){var e,n=[];for(e=0;e<t.length;++e)n.push(t.charCodeAt(e)>>5);for(n.push(0),e=0;e<t.length;++e)n.push(31&t.charCodeAt(e));return n},coinjs.bech32_verifyChecksum=function(t,e){return 1===coinjs.bech32_polymod(coinjs.bech32_hrpExpand(t).concat(e))},coinjs.bech32_decode=function(t){var e,n=!1,i=!1;for(e=0;e<t.length;++e){if(t.charCodeAt(e)<33||t.charCodeAt(e)>126)return null;t.charCodeAt(e)>=97&&t.charCodeAt(e)<=122&&(n=!0),t.charCodeAt(e)>=65&&t.charCodeAt(e)<=90&&(i=!0)}if(n&&i)return null;var r=(t=t.toLowerCase()).lastIndexOf("1");if(r<1||r+7>t.length||t.length>90)return null;var o=t.substring(0,r),s=[];for(e=r+1;e<t.length;++e){var a=coinjs.bech32.charset.indexOf(t.charAt(e));if(-1===a)return null;s.push(a)}return coinjs.bech32_verifyChecksum(o,s)?{hrp:o,data:s.slice(0,s.length-6)}:null},coinjs.bech32_convert=function(t,e,n,i){for(var r=0,o=0,s=(1<<n)-1,a=[],u=0;u<t.length;++u)for(r=r<<e|t[u],o+=e;o>=n;)o-=n,a.push(r>>o&s);if(i)o>0&&a.push(r<<n-o&s);else{if(o>=e)throw new Error("Excess padding");if(r<<n-o&s)throw new Error("Non-zero padding")}return a},coinjs.bech32redeemscript=function(t){var e=coinjs.bech32_decode(t);return!!e&&(e.data.shift(),Crypto.util.bytesToHex(coinjs.bech32_convert(e.data,5,8,!1)))};var dbits,CHARSET="qpzry9x8gf2tvdw0s3jn54khce6mua7l",CHARSET_INVERSE_INDEX={q:0,p:1,z:2,r:3,y:4,9:5,x:6,8:7,g:8,f:9,2:10,t:11,v:12,d:13,w:14,0:15,s:16,3:17,j:18,n:19,5:20,4:21,k:22,h:23,c:24,e:25,6:26,m:27,u:28,a:29,7:30,l:31},convertBits=function(t,e,n){let i=Math.ceil(t.length*e/n),r=(1<<n)-1,o=[];for(let t=0;t<i;++t)o.push(0);let s=0,a=0,u=0;for(let i=0;i<t.length;++i){for(a=a<<e|t[i],u+=e;u>=n;)u-=n,o[s]=a>>u&r,++s}return u>0&&(o[s]=a<<n-u&r,++s),o},base32polymod=function(t){let e=[0x98f2bc8e61n,0x79b76d99e2n,0xf33e5fb3c4n,0xae2eabe2a8n,0x1e4f43e470n],n=1n;for(let i=0;i<t.length;++i){let r=t[i],o=n>>35n;n=(0x07ffffffffn&n)<<5n^BigInt(r);for(let t=0;t<e.length;++t)1n==(o>>BigInt(t)&1n)&&(n^=BigInt(e[t]))}return 1n^n},decodeBase32AsBytes=function(t){let e=[];for(let n=0;n<t.length;++n){let i=t[n];e.push(CHARSET_INVERSE_INDEX[i])}e=e.slice(0,e.length-8);let n=convertBits(e,5,8);return n=n.slice(0,n.length-1),encodeBytesToBase32(n)==t&&n},encodeBytesToBase32=function(t){let e=convertBits(t,8,5),n=function(t){let e=[];for(let n=0;n<t.length;++n)e.push(31&t[n].charCodeAt(0));return e}(coinjs.base32pref);n.push(0),n.push(...e),n.push(0,0,0,0,0,0,0,0);e.push(...function(t){let e=[0,0,0,0,0,0,0,0];for(let n=0;n<8;++n)e[7-n]=Number(31n&t),t>>=5n;return e}(base32polymod(n)));let i="";for(let t=0;t<e.length;++t){let n=e[t];i+=CHARSET[n]}return i};coinjs.signHash=function(t,e){const n=EllipticCurve.getSECCurveByName("secp256k1"),i=coinjs.wif2privkey(t),r=BigInteger.fromByteArrayUnsigned(Crypto.util.hexToBytes(i.privkey)),o=n.getN(),s=BigInteger.fromByteArrayUnsigned(e);let a=0,u=null,c=null;do{const i=coinjs.deterministicK(t,e,a);c=n.getG().multiply(i).getX().toBigInteger().mod(o),u=i.modInverse(o).multiply(s.add(r.multiply(c))).mod(o),a++}while(c.compareTo(BigInteger.ZERO)<=0||u.compareTo(BigInteger.ZERO)<=0);const l=o.shiftRight(1);u.compareTo(l)>0&&(u=o.subtract(u));let p=function serializeSig(t,e){const n=t.toByteArraySigned(),i=e.toByteArraySigned();let r=[];return r.push(2),r.push(n.length),r=r.concat(n),r.push(2),r.push(i.length),r=r.concat(i),r.unshift(r.length),r.unshift(48),r}(c,u);return p.push(parseInt(1,10)),Crypto.util.bytesToHex(p)},coinjs.script=function(t){var e={};return t?"string"==typeof t?e.buffer=Crypto.util.hexToBytes(t):coinjs.isArray(t)?e.buffer=t:t instanceof coinjs.script?e.buffer=t.buffer:e.buffer=t:e.buffer=[],e.parse=function(){var t=this;e.chunks=[];var n=0;function readChunk(e){t.chunks.push(t.buffer.slice(n,n+e)),n+=e}for(;n<this.buffer.length;){var i=this.buffer[n++];if(i>=240&&(i=i<<8|this.buffer[n++]),i>0&&i<76?readChunk(i):76==i?readChunk(this.buffer[n++]):77==i?readChunk(this.buffer[n++]<<8|this.buffer[n++]):78==i?readChunk(this.buffer[n++]<<24|this.buffer[n++]<<16|this.buffer[n++]<<8|this.buffer[n++]):this.chunks.push(i),n<0)break}return!0},e.spendToScript=function(t){var e=coinjs.addressDecode(t),n=coinjs.script();return"bech32"==e.type?(n.writeOp(0),n.writeBytes(Crypto.util.hexToBytes(e.redeemscript))):coinjs.arrayEquals(e.version,coinjs.multisig)||"multisig"==e.type?(n.writeOp(169),n.writeBytes(e.bytes),n.writeOp(135)):(n.writeOp(118),n.writeOp(169),n.writeBytes(e.bytes),n.writeOp(136),n.writeOp(172)),n},e.pubkeyHash=function(t){var e=coinjs.addressDecode(t),n=coinjs.script();return n.writeOp(118),n.writeOp(169),n.writeBytes(e.bytes),n.writeOp(136),n.writeOp(172),n},e.writeOp=function(t){return this.buffer.push(t),this.chunks.push(t),!0},e.writeBytes=function(t){return t.length<76?this.buffer.push(t.length):t.length<=255?(this.buffer.push(76),this.buffer.push(t.length)):t.length<=65535?(this.buffer.push(77),this.buffer.push(255&t.length),this.buffer.push(t.length>>>8&255)):(this.buffer.push(78),this.buffer.push(255&t.length),this.buffer.push(t.length>>>8&255),this.buffer.push(t.length>>>16&255),this.buffer.push(t.length>>>24&255)),this.buffer=this.buffer.concat(t),this.chunks.push(t),!0},e.parse(),e},coinjs.transaction=function(){var t={};return t.version=coinjs.txversion,t.lock_time=0,t.ins=[],t.outs=[],t.witness=[],t.timestamp=null,t.block=null,t.nTime=0,t.addinput=function(e,n,i,r,o){var s={};return s.outpoint={hash:e,index:n},s.script=coinjs.script(i||[]),s.sequence=r||(0==t.lock_time?4294967295:0),s.value="bigint"==typeof o?new BigInteger(o.toString()):o?new BigInteger(""+Math.round(1*o*1e8),10):null,this.ins.push(s)},t.addoutput=function(t,e){var n={};n.value="bigint"==typeof e?new BigInteger(e.toString()):new BigInteger(""+Math.round(1*e*1e8),10);var i=coinjs.script();return n.script=i.spendToScript(t),this.outs.push(n)},t.adddata=function(t,e){if(t.match(/^[a-f0-9]+$/gi)&&t.length<160&&t.length%2==0){var n=coinjs.script();return n.writeOp(106),n.writeBytes(Crypto.util.hexToBytes(t)),o={},o.value=e,o.script=n,this.outs.push(o)}return!1},t.transactionHash=function(t,e){var n=coinjs.clone(this),i=e||1;64==coinjs.shf&&(i|=64);for(var r=0;r<n.ins.length;r++)t!=r&&(n.ins[r].script=coinjs.script());var o=this.extractScriptKey(t);if(n.ins[t].script=coinjs.script(o.script),n.ins&&n.ins[t]){var s=224&i,a=31&i;if(1==a);else if(2==a){n.outs=[];for(r=0;r<n.ins.length;r++)t!=r&&(n.ins[r].sequence=0)}else if(3==a){n.outs.length=t+1;for(r=0;r<t;r++)n.outs[r].value=-1,n.outs[r].script.buffer=[];for(r=0;r<n.ins.length;r++)t!=r&&(n.ins[r].sequence=0)}var u,c=n.ins[t];if(128&s&&(n.ins=[n.ins[t]]),64&s){let e=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];u=(u=[]).concat(coinjs.numToBytes(parseInt(n.version),4)),u=128&s?u.concat(e):u.concat(coinjs.hash256(n.getPrevouts())),u=(u=(u=(u=(u=(u=(u=128&s||3==a||2==a?u.concat(e):u.concat(coinjs.hash256(n.getSequences()))).concat(Crypto.util.hexToBytes(c.outpoint.hash).reverse())).concat(coinjs.numToBytes(parseInt(c.outpoint.index),4))).concat(coinjs.numToVarInt(c.script.buffer.length))).concat(c.script.buffer)).concat(coinjs.numToBytes(c.value,8))).concat(coinjs.numToBytes(parseInt(c.sequence),4)),u=(u=(u=3!=a&&2!=a?u.concat(coinjs.hash256(n.getOutputs())):3==a?u.concat(coinjs.hash256(n.getOutput(t))):u.concat(e)).concat(coinjs.numToBytes(parseInt(this.lock_time),4))).concat(coinjs.numToBytes(parseInt(i),4))}else u=(u=Crypto.util.hexToBytes(n.serialize())).concat(coinjs.numToBytes(parseInt(i),4));var l=Crypto.SHA256(u,{asBytes:!0});return Crypto.util.bytesToHex(Crypto.SHA256(l,{asBytes:!0}))}return!1},t.transactionHashSegWitV0=function(t,e,n,i){var r=[],o=coinjs.script(Crypto.util.hexToBytes(e));r=(r=r.concat(coinjs.numToVarInt(o.buffer.length))).concat(o.buffer);var s=coinjs.numToBytes(i,8),a=coinjs.numToBytes(0,32),u=coinjs.numToBytes(parseInt(this.version),4),c=[];if(!(n>=80))for(var l=0;l<this.ins.length;l++)c=(c=c.concat(Crypto.util.hexToBytes(this.ins[l].outpoint.hash).reverse())).concat(coinjs.numToBytes(this.ins[l].outpoint.index,4));var p=c.length>=1?Crypto.SHA256(Crypto.SHA256(c,{asBytes:!0}),{asBytes:!0}):a;c=[];if(!(n>=80)&&2!=n&&3!=n)for(l=0;l<this.ins.length;l++)c=c.concat(coinjs.numToBytes(this.ins[l].sequence,4));var h=c.length>=1?Crypto.SHA256(Crypto.SHA256(c,{asBytes:!0}),{asBytes:!0}):a,y=Crypto.util.hexToBytes(this.ins[t].outpoint.hash).reverse();y=y.concat(coinjs.numToBytes(this.ins[t].outpoint.index,4));var d=coinjs.numToBytes(this.ins[t].sequence,4),f=a;c=[];if(2!=n&&3!=n){for(l=0;l<this.outs.length;l++)c=(c=(c=c.concat(coinjs.numToBytes(this.outs[l].value,8))).concat(coinjs.numToVarInt(this.outs[l].script.buffer.length))).concat(this.outs[l].script.buffer);f=Crypto.SHA256(Crypto.SHA256(c,{asBytes:!0}),{asBytes:!0})}else 2==n&&t<this.outs.length&&(c=(c=(c=c.concat(coinjs.numToBytes(this.outs[t].value,8))).concat(coinjs.numToVarInt(this.outs[l].script.buffer.length))).concat(this.outs[t].script.buffer),f=Crypto.SHA256(Crypto.SHA256(c,{asBytes:!0}),{asBytes:!0}));var _=coinjs.numToBytes(this.lock_time,4),g=coinjs.numToBytes(n,4),m=[];m=(m=(m=(m=(m=(m=(m=(m=(m=(m=m.concat(u)).concat(p)).concat(h)).concat(y)).concat(r)).concat(s)).concat(d)).concat(f)).concat(_)).concat(g);var b=Crypto.SHA256(m,{asBytes:!0});return{result:1,hash:Crypto.util.bytesToHex(Crypto.SHA256(b,{asBytes:!0})),response:"hash generated"}},t.getPrevouts=function(){for(var t=[],e=0;e<this.ins.length;e++){var n=this.ins[e];t=(t=t.concat(Crypto.util.hexToBytes(n.outpoint.hash).reverse())).concat(coinjs.numToBytes(parseInt(n.outpoint.index),4))}return t},t.getSequences=function(){for(var t=[],e=0;e<this.ins.length;e++){var n=this.ins[e];t=t.concat(coinjs.numToBytes(parseInt(n.sequence),4))}return t},t.getOutputs=function(){for(var t=[],e=0;e<this.outs.length;e++){var n=this.outs[e];t=t.concat(coinjs.numToBytes(n.value,8));var i=n.script.buffer;t=(t=t.concat(coinjs.numToVarInt(i.length))).concat(i)}return t},t.getOutput=function(t){for(var e=[],n=0;n<this.outs.length;n++)if(n==t){var i=this.outs[n];e=e.concat(coinjs.numToBytes(i.value,8));var r=i.script.buffer;e=(e=e.concat(coinjs.numToVarInt(r.length))).concat(r)}return e},t.extractScriptKey=function(t){if(this.ins[t]){if(5==this.ins[t].script.chunks.length&&172==this.ins[t].script.chunks[4]&&coinjs.isArray(this.ins[t].script.chunks[2]))return{type:"scriptpubkey",signed:"false",signatures:0,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)};if(2==this.ins[t].script.chunks.length&&48==this.ins[t].script.chunks[0][0]&&5==this.ins[t].script.chunks[1].length&&177==this.ins[t].script.chunks[1][1])return{type:"hodl",signed:"true",signatures:1,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)};if(2==this.ins[t].script.chunks.length&&48==this.ins[t].script.chunks[0][0])return{type:"scriptpubkey",signed:"true",signatures:1,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)};if(5==this.ins[t].script.chunks.length&&177==this.ins[t].script.chunks[1])return{type:"hodl",signed:"false",signatures:0,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)};if(this.ins[t].script.chunks.length<=3&&this.ins[t].script.chunks.length>0&&22==this.ins[t].script.chunks[0].length&&0==this.ins[t].script.chunks[0][0]){var e=this.witness[t]&&2==this.witness[t].length?"true":"false";return{type:"segwit",signed:e,signatures:"true"==e?1:0,script:Crypto.util.bytesToHex(this.ins[t].script.chunks[0])}}return 0==this.ins[t].script.chunks[0]&&174==this.ins[t].script.chunks[this.ins[t].script.chunks.length-1][this.ins[t].script.chunks[this.ins[t].script.chunks.length-1].length-1]?{type:"multisig",signed:"true",signatures:this.ins[t].script.chunks.length-2,script:Crypto.util.bytesToHex(this.ins[t].script.chunks[this.ins[t].script.chunks.length-1])}:this.ins[t].script.chunks[0]>=80&&174==this.ins[t].script.chunks[this.ins[t].script.chunks.length-1]?{type:"multisig",signed:"false",signatures:0,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)}:0==this.ins[t].script.chunks.length?{type:"empty",signed:"false",signatures:0,script:""}:{type:"unknown",signed:"false",signatures:0,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)}}return!1},t.transactionSig=function(t,e,n,i){var r=n||1;64==coinjs.shf&&(r|=64);var o=i||Crypto.util.hexToBytes(this.transactionHash(t,r));if(o){var s=EllipticCurve.getSECCurveByName("secp256k1"),a=coinjs.wif2privkey(e),u=BigInteger.fromByteArrayUnsigned(Crypto.util.hexToBytes(a.privkey)),c=s.getN(),l=BigInteger.fromByteArrayUnsigned(o),p=0;do{var h=coinjs.deterministicK(e,o,p),y=s.getG().multiply(h).getX().toBigInteger().mod(c),d=h.modInverse(c).multiply(l.add(u.multiply(y))).mod(c);p++}while(y.compareTo(BigInteger.ZERO)<=0||d.compareTo(BigInteger.ZERO)<=0);var f=c.shiftRight(1);d.compareTo(f)>0&&(d=c.subtract(d));var _=function serializeSig(t,e){var n=t.toByteArraySigned(),i=e.toByteArraySigned(),r=[];return r.push(2),r.push(n.length),(r=r.concat(n)).push(2),r.push(i.length),(r=r.concat(i)).unshift(r.length),r.unshift(48),r}(y,d);return _.push(parseInt(r,10)),Crypto.util.bytesToHex(_)}return!1},t.serialize=function(){var t=[];t=t.concat(coinjs.numToBytes(parseInt(this.version),4)),this.witness.length>=1&&(t=t.concat([0,1])),coinjs.txExtraTimeField&&(t=t.concat(coinjs.numToBytes(parseInt(this.nTime),4))),t=t.concat(coinjs.numToVarInt(this.ins.length));for(var e=0;e<this.ins.length;e++){var n=this.ins[e];t=(t=t.concat(Crypto.util.hexToBytes(n.outpoint.hash).reverse())).concat(coinjs.numToBytes(parseInt(n.outpoint.index),4));var i=n.script.buffer;t=(t=(t=t.concat(coinjs.numToVarInt(i.length))).concat(i)).concat(coinjs.numToBytes(parseInt(n.sequence),4))}t=t.concat(coinjs.numToVarInt(this.outs.length));for(e=0;e<this.outs.length;e++){var r=this.outs[e];t=t.concat(coinjs.numToBytes(r.value,8));i=r.script.buffer;t=(t=t.concat(coinjs.numToVarInt(i.length))).concat(i)}if(this.witness.length>=1)for(e=0;e<this.witness.length;e++){t=t.concat(coinjs.numToVarInt(this.witness[e].length));for(var o=0;o<this.witness[e].length;o++)t=(t=t.concat(coinjs.numToVarInt(Crypto.util.hexToBytes(this.witness[e][o]).length))).concat(Crypto.util.hexToBytes(this.witness[e][o]))}return t=t.concat(coinjs.numToBytes(parseInt(this.lock_time),4)),Crypto.util.bytesToHex(t)},t.deserialize=function(t){"string"==typeof t&&(t=Crypto.util.hexToBytes(t));var e=0,n=!1,readAsInt=function(n){return 0==n?0:(e++,t[e-1]+256*readAsInt(n-1))},readVarInt=function(){return e++,t[e-1]<253?t[e-1]:readAsInt(t[e-1]-251)},readBytes=function(n){return e+=n,t.slice(e-n,e)},readVarString=function(){var t=readVarInt();return readBytes(t)},i=new coinjs.transaction;i.version=readAsInt(4),coinjs.txExtraTimeField&&(i.nTime=readAsInt(4)),0==t[e]&&1==t[e+1]&&(n=!0,i.witness=[],e+=2);for(var r=readVarInt(),o=0;o<r;o++)i.ins.push({outpoint:{hash:Crypto.util.bytesToHex(readBytes(32).reverse()),index:readAsInt(4)},script:coinjs.script(readVarString()),sequence:readAsInt(4)});var s=readVarInt();for(o=0;o<s;o++)i.outs.push({value:coinjs.bytesToNum(readBytes(8)),script:coinjs.script(readVarString())});if(1==n)for(o=0;o<r;++o)for(var a=readVarInt(),u=0;u<a;u++){var c=readVarInt();e+=c,coinjs.isArray(i.witness[o])||(i.witness[o]=[]),i.witness[o].push(Crypto.util.bytesToHex(t.slice(e-c,e)))}return i.lock_time=readAsInt(4),i},t.size=function(){return(this.serialize().length/2).toFixed(0)},t},coinjs.deterministicK=function(t,e,n){n=n||0;var i=coinjs.wif2privkey(t),r=Crypto.util.hexToBytes(i.privkey),o=EllipticCurve.getSECCurveByName("secp256k1").getN(),s=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];a=Crypto.HMAC(Crypto.SHA256,s.concat([0]).concat(r).concat(e),a,{asBytes:!0}),s=Crypto.HMAC(Crypto.SHA256,s,a,{asBytes:!0}),a=Crypto.HMAC(Crypto.SHA256,s.concat([1]).concat(r).concat(e),a,{asBytes:!0}),s=Crypto.HMAC(Crypto.SHA256,s,a,{asBytes:!0});var u=[];u=s=Crypto.HMAC(Crypto.SHA256,s,a,{asBytes:!0});for(var c=BigInteger.fromByteArrayUnsigned(u),l=0;c.compareTo(o)>=0||c.compareTo(BigInteger.ZERO)<=0||l<n;)a=Crypto.HMAC(Crypto.SHA256,s.concat([0]),a,{asBytes:!0}),s=Crypto.HMAC(Crypto.SHA256,s,a,{asBytes:!0}),u=s=Crypto.HMAC(Crypto.SHA256,s,a,{asBytes:!0}),c=BigInteger.fromByteArrayUnsigned(u),l++;return c},coinjs.countObject=function(t){var e,n=0;for(e in t)t.hasOwnProperty(e)&&n++;return n},coinjs.clone=function(t){if(null==t||"object"!=typeof t)return t;var e=new t.constructor;for(var n in t)t.hasOwnProperty(n)&&(e[n]=coinjs.clone(t[n]));return e},coinjs.numToBytes=function(t,e){return void 0===e&&(e=8),0==e?[]:-1==t?Crypto.util.hexToBytes("ffffffffffffffff"):[t%256].concat(coinjs.numToBytes(Math.floor(t/256),e-1))},coinjs.numToByteArray=function(t){return t<=256?[t]:[t%256].concat(coinjs.numToByteArray(Math.floor(t/256)))},coinjs.numToVarInt=function(t){return t<253?[t]:t<65536?[253].concat(coinjs.numToBytes(t,2)):t<4294967296?[254].concat(coinjs.numToBytes(t,4)):[255].concat(coinjs.numToBytes(t,8))},coinjs.bytesToNum=function(t){return 0==t.length?0:t[0]+256*coinjs.bytesToNum(t.slice(1))},coinjs.addressDecodeWithBase32Prefix=function(t,e){if(!t.startsWith(e+":"))return!1;const n=decodeBase32AsBytes(t.slice(e.length+1));if(0==n)return!1;const i=n,r={};return 0==n[0]?(r.type="standard",r.bytes=i.slice(1),r.version=[i[0]]):8==n[0]?(r.type="multisig",r.bytes=i.slice(1),r.version=[i[0]]):(r.type="other",r.bytes=i.slice(1),r.version=[i[0]]),r},coinjs.addressDecodeStd=function(t){const e=coinjs.base58decode(t),n=e.slice(0,e.length-4),i=e.slice(e.length-4);if(Crypto.SHA256(Crypto.SHA256(n,{asBytes:!0}),{asBytes:!0}).slice(0,4)+""==i+""){const t={};return coinjs.arrayEquals(n.slice(0,coinjs.pub.length),coinjs.pub)?(t.type="standard",t.bytes=n.slice(coinjs.pub.length),t.version=n.slice(0,coinjs.pub.length)):coinjs.arrayEquals(n.slice(0,coinjs.multisig.length),coinjs.multisig)?(t.type="multisig",t.bytes=n.slice(coinjs.multisig.length),t.version=n.slice(0,coinjs.multisig.length)):coinjs.arrayEquals(n.slice(0,coinjs.priv.length),coinjs.priv)?(t.type="wifkey",t.bytes=n.slice(coinjs.priv.length),t.version=n.slice(0,coinjs.priv.length)):(t.type="other",t.bytes=n.slice(1),t.version=[n[0]]),t}return!1},coinjs.addressDecode=function(t){try{return""!=coinjs.base32pref&&t.startsWith(coinjs.base32pref+":")?coinjs.addressDecodeWithBase32Prefix(t,coinjs.base32pref):coinjs.addressDecodeStd(t)}catch(e){return bech32rs=coinjs.bech32redeemscript(t),!!bech32rs&&{type:"bech32",redeemscript:bech32rs}}},coinjs.base58encode=function(t){for(var e="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",n=BigInteger.valueOf(58),i=BigInteger.fromByteArrayUnsigned(t),r=[];i.compareTo(n)>=0;){var o=i.mod(n);r.unshift(e[o.intValue()]),i=i.subtract(o).divide(n)}r.unshift(e[i.intValue()]);for(var s=0;s<t.length&&0==t[s];s++)r.unshift(e[0]);return r.join("")},coinjs.base58decode=function(t){for(var e=BigInteger.valueOf(58),n=BigInteger.valueOf(0),i=0,r=t.length-1;r>=0;r--){var o="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".indexOf(t[r]);if(o<0)throw"Invalid character";n=n.add(BigInteger.valueOf(o).multiply(e.pow(t.length-1-r))),"1"==t[r]?i++:i=0}for(var s=n.toByteArrayUnsigned();i-- >0;)s.unshift(0);return s},coinjs.privkey2wif=function(t){var e=Crypto.util.hexToBytes(t);1==coinjs.compressed&&e.push(1),e.unshift(...coinjs.priv);var n=Crypto.SHA256(Crypto.SHA256(e,{asBytes:!0}),{asBytes:!0}).slice(0,4);return coinjs.base58encode(e.concat(n))},coinjs.wif2privkey=function(t){var e=!1,n=coinjs.base58decode(t),i=n.slice(0,n.length-4);return(i=i.slice(1,i.length)).length>=33&&1==i[i.length-1]&&(i=i.slice(0,i.length-1),e=!0),{privkey:Crypto.util.bytesToHex(i),compressed:e}},coinjs.pubkeys2MultisigAddressWithBackup=function(t,e,n,i){var r=coinjs.script();0==n&&0==i?(r.writeOp(82),r.writeBytes(Crypto.util.hexToBytes(t)),r.writeBytes(Crypto.util.hexToBytes(e)),r.writeOp(82),r.writeOp(174)):(r.writeOp(99),r.writeOp(82),r.writeBytes(Crypto.util.hexToBytes(t)),r.writeBytes(Crypto.util.hexToBytes(e)),r.writeOp(82),r.writeOp(174),r.writeOp(103),r.writeOp(99),r.writeBytes(coinjs.numToByteArray(n)),r.writeOp(177),r.writeOp(117),r.writeBytes(Crypto.util.hexToBytes(t)),r.writeOp(172),r.writeOp(103),r.writeBytes(coinjs.numToByteArray(i)),r.writeOp(177),r.writeOp(117),r.writeBytes(Crypto.util.hexToBytes(e)),r.writeOp(172),r.writeOp(104),r.writeOp(104));let o=ripemd160(Crypto.SHA256(r.buffer,{asBytes:!0}),{asBytes:!0});if(""!=coinjs.base32pref){let t=8+(o.length-20)/4;o.unshift(t);let e=Crypto.util.bytesToHex(r.buffer);return{address:coinjs.base32pref+":"+encodeBytesToBase32(o),redeemScript:e}}o.unshift(...coinjs.multisig);let s=o;s=Crypto.SHA256(Crypto.SHA256(s,{asBytes:!0}),{asBytes:!0});let a=s.slice(0,4),u=Crypto.util.bytesToHex(r.buffer);return{address:coinjs.base58encode(o.concat(a)),redeemScript:u}},coinjs.pubkeydecompress=function(t){if("string"==typeof t&&t.match(/^[a-f0-9]+$/i)){var e=EllipticCurve.getSECCurveByName("secp256k1");try{var n=e.curve.decodePointHex(t),i=n.getX().toBigInteger(),r=n.getY().toBigInteger(),o=EllipticCurve.integerToBytes(i,32);return(o=o.concat(EllipticCurve.integerToBytes(r,32))).unshift(4),Crypto.util.bytesToHex(o)}catch(t){return!1}}return!1},coinjs.pubkey2address=function(t,e){var n=ripemd160(Crypto.SHA256(Crypto.util.hexToBytes(t),{asBytes:!0}));n.unshift(e||coinjs.pub);var i=Crypto.SHA256(Crypto.SHA256(n,{asBytes:!0}),{asBytes:!0}).slice(0,4);return coinjs.base58encode(n.concat(i))},coinjs.verifySignature=function(t,e,n){var i,r,o;if(coinjs.isArray(e)){var s=function parseSig(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:BigInteger.fromByteArrayUnsigned(n),s:BigInteger.fromByteArrayUnsigned(i)}}(e);i=s.r,r=s.s}else{if("object"!=typeof e||!e.r||!e.s)throw"Invalid value for signature";i=e.r,r=e.s}if(!coinjs.isArray(n))throw"Invalid format for pubkey value, must be byte array";var a=EllipticCurve.getSECCurveByName("secp256k1");o=EllipticCurve.PointFp.decodeFrom(a.getCurve(),n);var u=BigInteger.fromByteArrayUnsigned(t);return coinjs.verifySignatureRaw(u,i,r,o)},coinjs.verifySignatureRaw=function(t,e,n,i){var r=EllipticCurve.getSECCurveByName("secp256k1"),o=r.getN(),s=r.getG();if(e.compareTo(BigInteger.ONE)<0||e.compareTo(o)>=0)return!1;if(n.compareTo(BigInteger.ONE)<0||n.compareTo(o)>=0)return!1;var a=n.modInverse(o),u=t.multiply(a).mod(o),c=e.multiply(a).mod(o);return s.multiply(u).add(i.multiply(c)).getX().toBigInteger().mod(o).equals(e)};var canary=0xdeadbeefcafe,j_lm=15715070==(16777215&canary);function BigInteger(t,e,n){if(!(this instanceof BigInteger))return new BigInteger(t,e,n);null!=t&&("number"==typeof t?this.fromNumber(t,e,n):null==e&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,e))}var proto=BigInteger.prototype;function nbi(){return new BigInteger(null)}function am1(t,e,n,i,r,o){for(;--o>=0;){var s=e*this[t++]+n[i]+r;r=Math.floor(s/67108864),n[i++]=67108863&s}return r}function am2(t,e,n,i,r,o){for(var s=32767&e,a=e>>15;--o>=0;){var u=32767&this[t],c=this[t++]>>15,l=a*u+c*s;r=((u=s*u+((32767&l)<<15)+n[i]+(1073741823&r))>>>30)+(l>>>15)+a*c+(r>>>30),n[i++]=1073741823&u}return r}function am3(t,e,n,i,r,o){for(var s=16383&e,a=e>>14;--o>=0;){var u=16383&this[t],c=this[t++]>>14,l=a*u+c*s;r=((u=s*u+((16383&l)<<14)+n[i]+r)>>28)+(l>>14)+a*c,n[i++]=268435455&u}return r}BigInteger.prototype.am=am1,dbits=26,BigInteger.prototype.DB=dbits,BigInteger.prototype.DM=(1<<dbits)-1;var DV=BigInteger.prototype.DV=1<<dbits,BI_FP=52;BigInteger.prototype.FV=Math.pow(2,BI_FP),BigInteger.prototype.F1=BI_FP-dbits,BigInteger.prototype.F2=2*dbits-BI_FP;var rr,vv,BI_RM="0123456789abcdefghijklmnopqrstuvwxyz",BI_RC=new Array;for(rr="0".charCodeAt(0),vv=0;vv<=9;++vv)BI_RC[rr++]=vv;for(rr="a".charCodeAt(0),vv=10;vv<36;++vv)BI_RC[rr++]=vv;for(rr="A".charCodeAt(0),vv=10;vv<36;++vv)BI_RC[rr++]=vv;function int2char(t){return BI_RM.charAt(t)}function intAt(t,e){var n=BI_RC[t.charCodeAt(e)];return null==n?-1:n}function bnpCopyTo(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s}function bnpFromInt(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+DV:this.t=0}function nbv(t){var e=nbi();return e.fromInt(t),e}function bnpFromString(t,e){var n,i=this;if(16==e)n=4;else if(8==e)n=3;else if(256==e)n=8;else if(2==e)n=1;else if(32==e)n=5;else{if(4!=e)return void i.fromRadix(t,e);n=2}i.t=0,i.s=0;for(var r=t.length,o=!1,s=0;--r>=0;){var a=8==n?255&t[r]:intAt(t,r);a<0?"-"==t.charAt(r)&&(o=!0):(o=!1,0==s?i[i.t++]=a:s+n>i.DB?(i[i.t-1]|=(a&(1<<i.DB-s)-1)<<s,i[i.t++]=a>>i.DB-s):i[i.t-1]|=a<<s,(s+=n)>=i.DB&&(s-=i.DB))}8==n&&0!=(128&t[0])&&(i.s=-1,s>0&&(i[i.t-1]|=(1<<i.DB-s)-1<<s)),i.clamp(),o&&BigInteger.ZERO.subTo(i,i)}function bnpClamp(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t}function bnToString(t){var e,n=this;if(n.s<0)return"-"+n.negate().toString(t);if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return n.toRadix(t);e=2}var i,r=(1<<e)-1,o=!1,s="",a=n.t,u=n.DB-a*n.DB%e;if(a-- >0)for(u<n.DB&&(i=n[a]>>u)>0&&(o=!0,s=int2char(i));a>=0;)u<e?(i=(n[a]&(1<<u)-1)<<e-u,i|=n[--a]>>(u+=n.DB-e)):(i=n[a]>>(u-=e)&r,u<=0&&(u+=n.DB,--a)),i>0&&(o=!0),o&&(s+=int2char(i));return o?s:"0"}function bnNegate(){var t=nbi();return BigInteger.ZERO.subTo(this,t),t}function bnAbs(){return this.s<0?this.negate():this}function bnCompareTo(t){var e=this.s-t.s;if(0!=e)return e;var n=this.t;if(0!=(e=n-t.t))return this.s<0?-e:e;for(;--n>=0;)if(0!=(e=this[n]-t[n]))return e;return 0}function nbits(t){var e,n=1;return 0!=(e=t>>>16)&&(t=e,n+=16),0!=(e=t>>8)&&(t=e,n+=8),0!=(e=t>>4)&&(t=e,n+=4),0!=(e=t>>2)&&(t=e,n+=2),0!=(e=t>>1)&&(t=e,n+=1),n}function bnBitLength(){return this.t<=0?0:this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}function bnpDLShiftTo(t,e){var n;for(n=this.t-1;n>=0;--n)e[n+t]=this[n];for(n=t-1;n>=0;--n)e[n]=0;e.t=this.t+t,e.s=this.s}function bnpDRShiftTo(t,e){for(var n=t;n<this.t;++n)e[n-t]=this[n];e.t=Math.max(this.t-t,0),e.s=this.s}function bnpLShiftTo(t,e){var n,i=this,r=t%i.DB,o=i.DB-r,s=(1<<o)-1,a=Math.floor(t/i.DB),u=i.s<<r&i.DM;for(n=i.t-1;n>=0;--n)e[n+a+1]=i[n]>>o|u,u=(i[n]&s)<<r;for(n=a-1;n>=0;--n)e[n]=0;e[a]=u,e.t=i.t+a+1,e.s=i.s,e.clamp()}function bnpRShiftTo(t,e){var n=this;e.s=n.s;var i=Math.floor(t/n.DB);if(i>=n.t)e.t=0;else{var r=t%n.DB,o=n.DB-r,s=(1<<r)-1;e[0]=n[i]>>r;for(var a=i+1;a<n.t;++a)e[a-i-1]|=(n[a]&s)<<o,e[a-i]=n[a]>>r;r>0&&(e[n.t-i-1]|=(n.s&s)<<o),e.t=n.t-i,e.clamp()}}function bnpSubTo(t,e){for(var n=this,i=0,r=0,o=Math.min(t.t,n.t);i<o;)r+=n[i]-t[i],e[i++]=r&n.DM,r>>=n.DB;if(t.t<n.t){for(r-=t.s;i<n.t;)r+=n[i],e[i++]=r&n.DM,r>>=n.DB;r+=n.s}else{for(r+=n.s;i<t.t;)r-=t[i],e[i++]=r&n.DM,r>>=n.DB;r-=t.s}e.s=r<0?-1:0,r<-1?e[i++]=n.DV+r:r>0&&(e[i++]=r),e.t=i,e.clamp()}function bnpMultiplyTo(t,e){var n=this.abs(),i=t.abs(),r=n.t;for(e.t=r+i.t;--r>=0;)e[r]=0;for(r=0;r<i.t;++r)e[r+n.t]=n.am(0,i[r],e,r,0,n.t);e.s=0,e.clamp(),this.s!=t.s&&BigInteger.ZERO.subTo(e,e)}function bnpSquareTo(t){for(var e=this.abs(),n=t.t=2*e.t;--n>=0;)t[n]=0;for(n=0;n<e.t-1;++n){var i=e.am(n,e[n],t,2*n,0,1);(t[n+e.t]+=e.am(n+1,2*e[n],t,2*n+1,i,e.t-n-1))>=e.DV&&(t[n+e.t]-=e.DV,t[n+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(n,e[n],t,2*n,0,1)),t.s=0,t.clamp()}function bnpDivRemTo(t,e,n){var i=this,r=t.abs();if(!(r.t<=0)){var o=i.abs();if(o.t<r.t)return null!=e&&e.fromInt(0),void(null!=n&&i.copyTo(n));null==n&&(n=nbi());var s=nbi(),a=i.s,u=t.s,c=i.DB-nbits(r[r.t-1]);c>0?(r.lShiftTo(c,s),o.lShiftTo(c,n)):(r.copyTo(s),o.copyTo(n));var l=s.t,p=s[l-1];if(0!=p){var h=p*(1<<i.F1)+(l>1?s[l-2]>>i.F2:0),y=i.FV/h,d=(1<<i.F1)/h,f=1<<i.F2,_=n.t,g=_-l,m=null==e?nbi():e;for(s.dlShiftTo(g,m),n.compareTo(m)>=0&&(n[n.t++]=1,n.subTo(m,n)),BigInteger.ONE.dlShiftTo(l,m),m.subTo(s,s);s.t<l;)s[s.t++]=0;for(;--g>=0;){var b=n[--_]==p?i.DM:Math.floor(n[_]*y+(n[_-1]+f)*d);if((n[_]+=s.am(0,b,n,g,0,l))<b)for(s.dlShiftTo(g,m),n.subTo(m,n);n[_]<--b;)n.subTo(m,n)}null!=e&&(n.drShiftTo(l,e),a!=u&&BigInteger.ZERO.subTo(e,e)),n.t=l,n.clamp(),c>0&&n.rShiftTo(c,n),a<0&&BigInteger.ZERO.subTo(n,n)}}}function bnMod(t){var e=nbi();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(BigInteger.ZERO)>0&&t.subTo(e,e),e}function Classic(t){this.m=t}function cConvert(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t}function cRevert(t){return t}function cReduce(t){t.divRemTo(this.m,null,t)}function cMulTo(t,e,n){t.multiplyTo(e,n),this.reduce(n)}function cSqrTo(t,e){t.squareTo(e),this.reduce(e)}function bnpInvDigit(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e}function Montgomery(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}function montConvert(t){var e=nbi();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(BigInteger.ZERO)>0&&this.m.subTo(e,e),e}function montRevert(t){var e=nbi();return t.copyTo(e),this.reduce(e),e}function montReduce(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e<this.m.t;++e){var n=32767&t[e],i=n*this.mpl+((n*this.mph+(t[e]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[n=e+this.m.t]+=this.m.am(0,i,t,e,0,this.m.t);t[n]>=t.DV;)t[n]-=t.DV,t[++n]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)}function montSqrTo(t,e){t.squareTo(e),this.reduce(e)}function montMulTo(t,e,n){t.multiplyTo(e,n),this.reduce(n)}function bnpIsEven(){return 0==(this.t>0?1&this[0]:this.s)}function bnpExp(t,e){if(t>4294967295||t<1)return BigInteger.ONE;var n=nbi(),i=nbi(),r=e.convert(this),o=nbits(t)-1;for(r.copyTo(n);--o>=0;)if(e.sqrTo(n,i),(t&1<<o)>0)e.mulTo(i,r,n);else{var s=n;n=i,i=s}return e.revert(n)}function bnModPowInt(t,e){var n;return n=t<256||e.isEven()?new Classic(e):new Montgomery(e),this.exp(t,n)}function nbi(){return new BigInteger(null)}function bnClone(){var t=nbi();return this.copyTo(t),t}function bnIntValue(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function bnByteValue(){return 0==this.t?this.s:this[0]<<24>>24}function bnShortValue(){return 0==this.t?this.s:this[0]<<16>>16}function bnpChunkSize(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}function bnSigNum(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}function bnpToRadix(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var e=this.chunkSize(t),n=Math.pow(t,e),i=nbv(n),r=nbi(),o=nbi(),s="";for(this.divRemTo(i,r,o);r.signum()>0;)s=(n+o.intValue()).toString(t).substr(1)+s,r.divRemTo(i,r,o);return o.intValue().toString(t)+s}function bnpFromRadix(t,e){var n=this;n.fromInt(0),null==e&&(e=10);for(var i=n.chunkSize(e),r=Math.pow(e,i),o=!1,s=0,a=0,u=0;u<t.length;++u){var c=intAt(t,u);c<0?"-"==t.charAt(u)&&0==n.signum()&&(o=!0):(a=e*a+c,++s>=i&&(n.dMultiply(r),n.dAddOffset(a,0),s=0,a=0))}s>0&&(n.dMultiply(Math.pow(e,s)),n.dAddOffset(a,0)),o&&BigInteger.ZERO.subTo(n,n)}function bnpFromNumber(t,e,n){var i=this;if("number"==typeof e)if(t<2)i.fromInt(1);else for(i.fromNumber(t,n),i.testBit(t-1)||i.bitwiseTo(BigInteger.ONE.shiftLeft(t-1),op_or,i),i.isEven()&&i.dAddOffset(1,0);!i.isProbablePrime(e);)i.dAddOffset(2,0),i.bitLength()>t&&i.subTo(BigInteger.ONE.shiftLeft(t-1),i);else{var r=new Array,o=7&t;r.length=1+(t>>3),e.nextBytes(r),o>0?r[0]&=(1<<o)-1:r[0]=0,i.fromString(r,256)}}function bnToByteArray(){var t=this,e=t.t,n=new Array;n[0]=t.s;var i,r=t.DB-e*t.DB%8,o=0;if(e-- >0)for(r<t.DB&&(i=t[e]>>r)!=(t.s&t.DM)>>r&&(n[o++]=i|t.s<<t.DB-r);e>=0;)r<8?(i=(t[e]&(1<<r)-1)<<8-r,i|=t[--e]>>(r+=t.DB-8)):(i=t[e]>>(r-=8)&255,r<=0&&(r+=t.DB,--e)),0!=(128&i)&&(i|=-256),0===o&&(128&t.s)!=(128&i)&&++o,(o>0||i!=t.s)&&(n[o++]=i);return n}function bnEquals(t){return 0==this.compareTo(t)}function bnMin(t){return this.compareTo(t)<0?this:t}function bnMax(t){return this.compareTo(t)>0?this:t}function bnpBitwiseTo(t,e,n){var i,r,o=this,s=Math.min(t.t,o.t);for(i=0;i<s;++i)n[i]=e(o[i],t[i]);if(t.t<o.t){for(r=t.s&o.DM,i=s;i<o.t;++i)n[i]=e(o[i],r);n.t=o.t}else{for(r=o.s&o.DM,i=s;i<t.t;++i)n[i]=e(r,t[i]);n.t=t.t}n.s=e(o.s,t.s),n.clamp()}function op_and(t,e){return t&e}function bnAnd(t){var e=nbi();return this.bitwiseTo(t,op_and,e),e}function op_or(t,e){return t|e}function bnOr(t){var e=nbi();return this.bitwiseTo(t,op_or,e),e}function op_xor(t,e){return t^e}function bnXor(t){var e=nbi();return this.bitwiseTo(t,op_xor,e),e}function op_andnot(t,e){return t&~e}function bnAndNot(t){var e=nbi();return this.bitwiseTo(t,op_andnot,e),e}function bnNot(){for(var t=nbi(),e=0;e<this.t;++e)t[e]=this.DM&~this[e];return t.t=this.t,t.s=~this.s,t}function bnShiftLeft(t){var e=nbi();return t<0?this.rShiftTo(-t,e):this.lShiftTo(t,e),e}function bnShiftRight(t){var e=nbi();return t<0?this.lShiftTo(-t,e):this.rShiftTo(t,e),e}function lbit(t){if(0==t)return-1;var e=0;return 0==(65535&t)&&(t>>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function bnGetLowestSetBit(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+lbit(this[t]);return this.s<0?this.t*this.DB:-1}function cbit(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function bnBitCount(){for(var t=0,e=this.s&this.DM,n=0;n<this.t;++n)t+=cbit(this[n]^e);return t}function bnTestBit(t){var e=Math.floor(t/this.DB);return e>=this.t?0!=this.s:0!=(this[e]&1<<t%this.DB)}function bnpChangeBit(t,e){var n=BigInteger.ONE.shiftLeft(t);return this.bitwiseTo(n,e,n),n}function bnSetBit(t){return this.changeBit(t,op_or)}function bnClearBit(t){return this.changeBit(t,op_andnot)}function bnFlipBit(t){return this.changeBit(t,op_xor)}function bnpAddTo(t,e){for(var n=this,i=0,r=0,o=Math.min(t.t,n.t);i<o;)r+=n[i]+t[i],e[i++]=r&n.DM,r>>=n.DB;if(t.t<n.t){for(r+=t.s;i<n.t;)r+=n[i],e[i++]=r&n.DM,r>>=n.DB;r+=n.s}else{for(r+=n.s;i<t.t;)r+=t[i],e[i++]=r&n.DM,r>>=n.DB;r+=t.s}e.s=r<0?-1:0,r>0?e[i++]=r:r<-1&&(e[i++]=n.DV+r),e.t=i,e.clamp()}function bnAdd(t){var e=nbi();return this.addTo(t,e),e}function bnSubtract(t){var e=nbi();return this.subTo(t,e),e}function bnMultiply(t){var e=nbi();return this.multiplyTo(t,e),e}function bnSquare(){var t=nbi();return this.squareTo(t),t}function bnDivide(t){var e=nbi();return this.divRemTo(t,e,null),e}function bnRemainder(t){var e=nbi();return this.divRemTo(t,null,e),e}function bnDivideAndRemainder(t){var e=nbi(),n=nbi();return this.divRemTo(t,e,n),new Array(e,n)}function bnpDMultiply(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}function bnpDAddOffset(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}}function NullExp(){}function nNop(t){return t}function nMulTo(t,e,n){t.multiplyTo(e,n)}function nSqrTo(t,e){t.squareTo(e)}function bnPow(t){return this.exp(t,new NullExp)}function bnpMultiplyLowerTo(t,e,n){var i,r=Math.min(this.t+t.t,e);for(n.s=0,n.t=r;r>0;)n[--r]=0;for(i=n.t-this.t;r<i;++r)n[r+this.t]=this.am(0,t[r],n,r,0,this.t);for(i=Math.min(t.t,e);r<i;++r)this.am(0,t[r],n,r,0,e-r);n.clamp()}function bnpMultiplyUpperTo(t,e,n){--e;var i=n.t=this.t+t.t-e;for(n.s=0;--i>=0;)n[i]=0;for(i=Math.max(e-this.t,0);i<t.t;++i)n[this.t+i-e]=this.am(e-i,t[i],n,0,0,this.t+i-e);n.clamp(),n.drShiftTo(1,n)}function Barrett(t){this.r2=nbi(),this.q3=nbi(),BigInteger.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}function barrettConvert(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=nbi();return t.copyTo(e),this.reduce(e),e}function barrettRevert(t){return t}function barrettReduce(t){var e=this;for(t.drShiftTo(e.m.t-1,e.r2),t.t>e.m.t+1&&(t.t=e.m.t+1,t.clamp()),e.mu.multiplyUpperTo(e.r2,e.m.t+1,e.q3),e.m.multiplyLowerTo(e.q3,e.m.t+1,e.r2);t.compareTo(e.r2)<0;)t.dAddOffset(1,e.m.t+1);for(t.subTo(e.r2,t);t.compareTo(e.m)>=0;)t.subTo(e.m,t)}function barrettSqrTo(t,e){t.squareTo(e),this.reduce(e)}function barrettMulTo(t,e,n){t.multiplyTo(e,n),this.reduce(n)}function bnModPow(t,e){var n,i,r=t.bitLength(),o=nbv(1);if(r<=0)return o;n=r<18?1:r<48?3:r<144?4:r<768?5:6,i=r<8?new Classic(e):e.isEven()?new Barrett(e):new Montgomery(e);var s=new Array,a=3,u=n-1,c=(1<<n)-1;if(s[1]=i.convert(this),n>1){var l=nbi();for(i.sqrTo(s[1],l);a<=c;)s[a]=nbi(),i.mulTo(l,s[a-2],s[a]),a+=2}var p,h,y=t.t-1,d=!0,f=nbi();for(r=nbits(t[y])-1;y>=0;){for(r>=u?p=t[y]>>r-u&c:(p=(t[y]&(1<<r+1)-1)<<u-r,y>0&&(p|=t[y-1]>>this.DB+r-u)),a=n;0==(1&p);)p>>=1,--a;if((r-=a)<0&&(r+=this.DB,--y),d)s[p].copyTo(o),d=!1;else{for(;a>1;)i.sqrTo(o,f),i.sqrTo(f,o),a-=2;a>0?i.sqrTo(o,f):(h=o,o=f,f=h),i.mulTo(f,s[p],o)}for(;y>=0&&0==(t[y]&1<<r);)i.sqrTo(o,f),h=o,o=f,f=h,--r<0&&(r=this.DB-1,--y)}return i.revert(o)}function bnGCD(t){var e=this.s<0?this.negate():this.clone(),n=t.s<0?t.negate():t.clone();if(e.compareTo(n)<0){var i=e;e=n,n=i}var r=e.getLowestSetBit(),o=n.getLowestSetBit();if(o<0)return e;for(r<o&&(o=r),o>0&&(e.rShiftTo(o,e),n.rShiftTo(o,n));e.signum()>0;)(r=e.getLowestSetBit())>0&&e.rShiftTo(r,e),(r=n.getLowestSetBit())>0&&n.rShiftTo(r,n),e.compareTo(n)>=0?(e.subTo(n,e),e.rShiftTo(1,e)):(n.subTo(e,n),n.rShiftTo(1,n));return o>0&&n.lShiftTo(o,n),n}function bnpModInt(t){if(t<=0)return 0;var e=this.DV%t,n=this.s<0?t-1:0;if(this.t>0)if(0==e)n=this[0]%t;else for(var i=this.t-1;i>=0;--i)n=(e*n+this[i])%t;return n}function bnModInverse(t){var e=t.isEven();if(this.isEven()&&e||0==t.signum())return BigInteger.ZERO;for(var n=t.clone(),i=this.clone(),r=nbv(1),o=nbv(0),s=nbv(0),a=nbv(1);0!=n.signum();){for(;n.isEven();)n.rShiftTo(1,n),e?(r.isEven()&&o.isEven()||(r.addTo(this,r),o.subTo(t,o)),r.rShiftTo(1,r)):o.isEven()||o.subTo(t,o),o.rShiftTo(1,o);for(;i.isEven();)i.rShiftTo(1,i),e?(s.isEven()&&a.isEven()||(s.addTo(this,s),a.subTo(t,a)),s.rShiftTo(1,s)):a.isEven()||a.subTo(t,a),a.rShiftTo(1,a);n.compareTo(i)>=0?(n.subTo(i,n),e&&r.subTo(s,r),o.subTo(a,o)):(i.subTo(n,i),e&&s.subTo(r,s),a.subTo(o,a))}return 0!=i.compareTo(BigInteger.ONE)?BigInteger.ZERO:a.compareTo(t)>=0?a.subtract(t):a.signum()<0?(a.addTo(t,a),a.signum()<0?a.add(t):a):a}Classic.prototype.convert=cConvert,Classic.prototype.revert=cRevert,Classic.prototype.reduce=cReduce,Classic.prototype.mulTo=cMulTo,Classic.prototype.sqrTo=cSqrTo,Montgomery.prototype.convert=montConvert,Montgomery.prototype.revert=montRevert,Montgomery.prototype.reduce=montReduce,Montgomery.prototype.mulTo=montMulTo,Montgomery.prototype.sqrTo=montSqrTo,proto.copyTo=bnpCopyTo,proto.fromInt=bnpFromInt,proto.fromString=bnpFromString,proto.clamp=bnpClamp,proto.dlShiftTo=bnpDLShiftTo,proto.drShiftTo=bnpDRShiftTo,proto.lShiftTo=bnpLShiftTo,proto.rShiftTo=bnpRShiftTo,proto.subTo=bnpSubTo,proto.multiplyTo=bnpMultiplyTo,proto.squareTo=bnpSquareTo,proto.divRemTo=bnpDivRemTo,proto.invDigit=bnpInvDigit,proto.isEven=bnpIsEven,proto.exp=bnpExp,proto.toString=bnToString,proto.negate=bnNegate,proto.abs=bnAbs,proto.compareTo=bnCompareTo,proto.bitLength=bnBitLength,proto.mod=bnMod,proto.modPowInt=bnModPowInt,NullExp.prototype.convert=nNop,NullExp.prototype.revert=nNop,NullExp.prototype.mulTo=nMulTo,NullExp.prototype.sqrTo=nSqrTo,Barrett.prototype.convert=barrettConvert,Barrett.prototype.revert=barrettRevert,Barrett.prototype.reduce=barrettReduce,Barrett.prototype.mulTo=barrettMulTo,Barrett.prototype.sqrTo=barrettSqrTo,proto.chunkSize=bnpChunkSize,proto.toRadix=bnpToRadix,proto.fromRadix=bnpFromRadix,proto.fromNumber=bnpFromNumber,proto.bitwiseTo=bnpBitwiseTo,proto.changeBit=bnpChangeBit,proto.addTo=bnpAddTo,proto.dMultiply=bnpDMultiply,proto.dAddOffset=bnpDAddOffset,proto.multiplyLowerTo=bnpMultiplyLowerTo,proto.multiplyUpperTo=bnpMultiplyUpperTo,proto.modInt=bnpModInt,proto.clone=bnClone,proto.intValue=bnIntValue,proto.byteValue=bnByteValue,proto.shortValue=bnShortValue,proto.signum=bnSigNum,proto.toByteArray=bnToByteArray,proto.equals=bnEquals,proto.min=bnMin,proto.max=bnMax,proto.and=bnAnd,proto.or=bnOr,proto.xor=bnXor,proto.andNot=bnAndNot,proto.not=bnNot,proto.shiftLeft=bnShiftLeft,proto.shiftRight=bnShiftRight,proto.getLowestSetBit=bnGetLowestSetBit,proto.bitCount=bnBitCount,proto.testBit=bnTestBit,proto.setBit=bnSetBit,proto.clearBit=bnClearBit,proto.flipBit=bnFlipBit,proto.add=bnAdd,proto.subtract=bnSubtract,proto.multiply=bnMultiply,proto.divide=bnDivide,proto.remainder=bnRemainder,proto.divideAndRemainder=bnDivideAndRemainder,proto.modPow=bnModPow,proto.modInverse=bnModInverse,proto.pow=bnPow,proto.gcd=bnGCD,proto.square=bnSquare,BigInteger.ZERO=nbv(0),BigInteger.ONE=nbv(1),BigInteger.valueOf=nbv,BigInteger.fromByteArrayUnsigned=function(t){return t.length?128&t[0]?new BigInteger([0].concat(t)):new BigInteger(t):new BigInteger.valueOf(0)},BigInteger.fromByteArraySigned=function(t){return 128&t[0]?(t[0]&=127,BigInteger.fromByteArrayUnsigned(t).negate()):BigInteger.fromByteArrayUnsigned(t)},BigInteger.prototype.toByteArrayUnsigned=function(){var t=this.abs().toByteArray();if(!t.length)return t;0===t[0]&&(t=t.slice(1));for(var e=0;e<t.length;++e)t[e]=t[e]<0?t[e]+256:t[e];return t},BigInteger.prototype.toByteArraySigned=function(){var t=this.toByteArrayUnsigned(),e=this.s<0;return 128&t[0]?t.unshift(e?128:0):e&&(t[0]|=128),t},("undefined"==typeof Crypto||!Crypto.util)&&function(){var t,e=(t=window.Crypto={}).util={rotl:function(t,e){return t<<e|t>>>32-e},rotr:function(t,e){return t<<32-e|t>>>e},endian:function(t){if(t.constructor==Number)return 16711935&e.rotl(t,8)|4278255360&e.rotl(t,24);for(var n=0;n<t.length;n++)t[n]=e.endian(t[n]);return t},randomBytes:function(t){for(var e=[];t>0;t--)e.push(Math.floor(256*Math.random()));return e},bytesToWords:function(t){for(var e=[],n=0,i=0;n<t.length;n++,i+=8)e[i>>>5]|=(255&t[n])<<24-i%32;return e},wordsToBytes:function(t){for(var e=[],n=0;n<32*t.length;n+=8)e.push(t[n>>>5]>>>24-n%32&255);return e},bytesToHex:function(t){for(var e=[],n=0;n<t.length;n++)e.push((t[n]>>>4).toString(16)),e.push((15&t[n]).toString(16));return e.join("")},hexToBytes:function(t){for(var e=[],n=0;n<t.length;n+=2)e.push(parseInt(t.substr(n,2),16));return e},bytesToBase64:function(t){for(var e=[],n=0;n<t.length;n+=3)for(var i=t[n]<<16|t[n+1]<<8|t[n+2],r=0;r<4;r++)8*n+6*r<=8*t.length?e.push("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(i>>>6*(3-r)&63)):e.push("=");return e.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var e=[],n=0,i=0;n<t.length;i=++n%4)0!=i&&e.push(("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(t.charAt(n-1))&Math.pow(2,-2*i+8)-1)<<2*i|"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(t.charAt(n))>>>6-2*i);return e}};(t=t.charenc={}).UTF8={stringToBytes:function(t){return n.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(n.bytesToString(t)))}};var n=t.Binary={stringToBytes:function(t){for(var e=[],n=0;n<t.length;n++)e.push(255&t.charCodeAt(n));return e},bytesToString:function(t){for(var e=[],n=0;n<t.length;n++)e.push(String.fromCharCode(t[n]));return e.join("")}}}(),function(){var t=Crypto,e=t.util,n=t.charenc,i=n.UTF8,r=n.Binary,o=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],s=t.SHA256=function(t,n){var i=e.wordsToBytes(s._sha256(t));return n&&n.asBytes?i:n&&n.asString?r.bytesToString(i):e.bytesToHex(i)};s._sha256=function(t){t.constructor==String&&(t=i.stringToBytes(t));var n,r,s,a,u,c,l,p,h,y,d,f=e.bytesToWords(t),_=8*t.length,g=(t=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],[]);for(f[_>>5]|=128<<24-_%32,f[15+(_+64>>9<<4)]=_,p=0;p<f.length;p+=16){for(_=t[0],n=t[1],r=t[2],s=t[3],a=t[4],u=t[5],c=t[6],l=t[7],h=0;h<64;h++){h<16?g[h]=f[h+p]:(y=g[h-15],d=g[h-2],g[h]=((y<<25|y>>>7)^(y<<14|y>>>18)^y>>>3)+(g[h-7]>>>0)+((d<<15|d>>>17)^(d<<13|d>>>19)^d>>>10)+(g[h-16]>>>0)),d=_&n^_&r^n&r;var m=(_<<30|_>>>2)^(_<<19|_>>>13)^(_<<10|_>>>22);y=(l>>>0)+((a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25))+(a&u^~a&c)+o[h]+(g[h]>>>0),l=c,c=u,u=a,a=s+y>>>0,s=r,r=n,n=_,_=y+(d=m+d)>>>0}t[0]+=_,t[1]+=n,t[2]+=r,t[3]+=s,t[4]+=a,t[5]+=u,t[6]+=c,t[7]+=l}return t},s._blocksize=16,s._digestsize=32}(),("undefined"==typeof Crypto||!Crypto.util)&&function(){var t,e=(t=window.Crypto={}).util={rotl:function(t,e){return t<<e|t>>>32-e},rotr:function(t,e){return t<<32-e|t>>>e},endian:function(t){if(t.constructor==Number)return 16711935&e.rotl(t,8)|4278255360&e.rotl(t,24);for(var n=0;n<t.length;n++)t[n]=e.endian(t[n]);return t},randomBytes:function(t){for(var e=[];t>0;t--)e.push(Math.floor(256*Math.random()));return e},bytesToWords:function(t){for(var e=[],n=0,i=0;n<t.length;n++,i+=8)e[i>>>5]|=(255&t[n])<<24-i%32;return e},wordsToBytes:function(t){for(var e=[],n=0;n<32*t.length;n+=8)e.push(t[n>>>5]>>>24-n%32&255);return e},bytesToHex:function(t){for(var e=[],n=0;n<t.length;n++)e.push((t[n]>>>4).toString(16)),e.push((15&t[n]).toString(16));return e.join("")},hexToBytes:function(t){for(var e=[],n=0;n<t.length;n+=2)e.push(parseInt(t.substr(n,2),16));return e},bytesToBase64:function(t){for(var e=[],n=0;n<t.length;n+=3)for(var i=t[n]<<16|t[n+1]<<8|t[n+2],r=0;r<4;r++)8*n+6*r<=8*t.length?e.push("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(i>>>6*(3-r)&63)):e.push("=");return e.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var e=[],n=0,i=0;n<t.length;i=++n%4)0!=i&&e.push(("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(t.charAt(n-1))&Math.pow(2,-2*i+8)-1)<<2*i|"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(t.charAt(n))>>>6-2*i);return e}};(t=t.charenc={}).UTF8={stringToBytes:function(t){return n.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(n.bytesToString(t)))}};var n=t.Binary={stringToBytes:function(t){for(var e=[],n=0;n<t.length;n++)e.push(255&t.charCodeAt(n));return e},bytesToString:function(t){for(var e=[],n=0;n<t.length;n++)e.push(String.fromCharCode(t[n]));return e.join("")}}}(),function(){var t=Crypto,e=t.util,n=t.charenc,i=n.UTF8,r=n.Binary,o=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],s=t.SHA256=function(t,n){var i=e.wordsToBytes(s._sha256(t));return n&&n.asBytes?i:n&&n.asString?r.bytesToString(i):e.bytesToHex(i)};s._sha256=function(t){t.constructor==String&&(t=i.stringToBytes(t));var n,r,s,a,u,c,l,p,h,y,d,f=e.bytesToWords(t),_=8*t.length,g=(t=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],[]);for(f[_>>5]|=128<<24-_%32,f[15+(_+64>>9<<4)]=_,p=0;p<f.length;p+=16){for(_=t[0],n=t[1],r=t[2],s=t[3],a=t[4],u=t[5],c=t[6],l=t[7],h=0;h<64;h++){h<16?g[h]=f[h+p]:(y=g[h-15],d=g[h-2],g[h]=((y<<25|y>>>7)^(y<<14|y>>>18)^y>>>3)+(g[h-7]>>>0)+((d<<15|d>>>17)^(d<<13|d>>>19)^d>>>10)+(g[h-16]>>>0)),d=_&n^_&r^n&r;var m=(_<<30|_>>>2)^(_<<19|_>>>13)^(_<<10|_>>>22);y=(l>>>0)+((a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25))+(a&u^~a&c)+o[h]+(g[h]>>>0),l=c,c=u,u=a,a=s+y>>>0,s=r,r=n,n=_,_=y+(d=m+d)>>>0}t[0]+=_,t[1]+=n,t[2]+=r,t[3]+=s,t[4]+=a,t[5]+=u,t[6]+=c,t[7]+=l}return t},s._blocksize=16,s._digestsize=32}(),function(){var t=Crypto,e=t.util,n=t.charenc,i=n.UTF8,r=n.Binary;t.HMAC=function(t,n,o,s){n.constructor==String&&(n=i.stringToBytes(n)),o.constructor==String&&(o=i.stringToBytes(o)),o.length>4*t._blocksize&&(o=t(o,{asBytes:!0}));for(var a=o.slice(0),u=(o=o.slice(0),0);u<4*t._blocksize;u++)a[u]^=92,o[u]^=54;return t=t(a.concat(t(o.concat(n),{asBytes:!0})),{asBytes:!0}),s&&s.asBytes?t:s&&s.asString?r.bytesToString(t):e.bytesToHex(t)}}(),function(){var t=window.EllipticCurve=function(){};t.FieldElementFp=function(t,e){this.x=e,this.q=t},t.FieldElementFp.prototype.equals=function(t){return t==this||this.q.equals(t.q)&&this.x.equals(t.x)},t.FieldElementFp.prototype.toBigInteger=function(){return this.x},t.FieldElementFp.prototype.negate=function(){return new t.FieldElementFp(this.q,this.x.negate().mod(this.q))},t.FieldElementFp.prototype.add=function(e){return new t.FieldElementFp(this.q,this.x.add(e.toBigInteger()).mod(this.q))},t.FieldElementFp.prototype.subtract=function(e){return new t.FieldElementFp(this.q,this.x.subtract(e.toBigInteger()).mod(this.q))},t.FieldElementFp.prototype.multiply=function(e){return new t.FieldElementFp(this.q,this.x.multiply(e.toBigInteger()).mod(this.q))},t.FieldElementFp.prototype.square=function(){return new t.FieldElementFp(this.q,this.x.square().mod(this.q))},t.FieldElementFp.prototype.divide=function(e){return new t.FieldElementFp(this.q,this.x.multiply(e.toBigInteger().modInverse(this.q)).mod(this.q))},t.FieldElementFp.prototype.getByteLength=function(){return Math.floor((this.toBigInteger().bitLength()+7)/8)},t.FieldElementFp.prototype.sqrt=function(){if(!this.q.testBit(0))throw new Error("even value of q");if(this.q.testBit(1)){var e=new t.FieldElementFp(this.q,this.x.modPow(this.q.shiftRight(2).add(BigInteger.ONE),this.q));return e.square().equals(this)?e:null}var n=this.q.subtract(BigInteger.ONE),i=n.shiftRight(1);if(!this.x.modPow(i,this.q).equals(BigInteger.ONE))return null;var r,o,s=n.shiftRight(2).shiftLeft(1).add(BigInteger.ONE),a=this.x,u=a.shiftLeft(2).mod(this.q);do{var c,l=new SecureRandom;do{c=new BigInteger(this.q.bitLength(),l)}while(c.compareTo(this.q)>=0||!c.multiply(c).subtract(u).modPow(i,this.q).equals(n));var p=t.FieldElementFp.fastLucasSequence(this.q,c,a,s);if(r=p[0],(o=p[1]).multiply(o).mod(this.q).equals(u))return o.testBit(0)&&(o=o.add(this.q)),o=o.shiftRight(1),new t.FieldElementFp(this.q,o)}while(r.equals(BigInteger.ONE)||r.equals(n));return null},t.FieldElementFp.fastLucasSequence=function(t,e,n,i){for(var r=i.bitLength(),o=i.getLowestSetBit(),s=BigInteger.ONE,a=BigInteger.TWO,u=e,c=BigInteger.ONE,l=BigInteger.ONE,p=r-1;p>=o+1;--p)c=c.multiply(l).mod(t),i.testBit(p)?(l=c.multiply(n).mod(t),s=s.multiply(u).mod(t),a=u.multiply(a).subtract(e.multiply(c)).mod(t),u=u.multiply(u).subtract(l.shiftLeft(1)).mod(t)):(l=c,s=s.multiply(a).subtract(c).mod(t),u=u.multiply(a).subtract(e.multiply(c)).mod(t),a=a.multiply(a).subtract(c.shiftLeft(1)).mod(t));l=(c=c.multiply(l).mod(t)).multiply(n).mod(t),s=s.multiply(a).subtract(c).mod(t),a=u.multiply(a).subtract(e.multiply(c)).mod(t),c=c.multiply(l).mod(t);for(p=1;p<=o;++p)s=s.multiply(a).mod(t),a=a.multiply(a).subtract(c.shiftLeft(1)).mod(t),c=c.multiply(c).mod(t);return[s,a]},t.PointFp=function(t,e,n,i,r){this.curve=t,this.x=e,this.y=n,this.z=null==i?BigInteger.ONE:i,this.zinv=null,this.compressed=!!r},t.PointFp.prototype.getX=function(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var t=this.x.toBigInteger().multiply(this.zinv);return this.curve.reduce(t),this.curve.fromBigInteger(t)},t.PointFp.prototype.getY=function(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var t=this.y.toBigInteger().multiply(this.zinv);return this.curve.reduce(t),this.curve.fromBigInteger(t)},t.PointFp.prototype.equals=function(t){return t==this||(this.isInfinity()?t.isInfinity():t.isInfinity()?this.isInfinity():!!t.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(BigInteger.ZERO)&&t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(BigInteger.ZERO))},t.PointFp.prototype.isInfinity=function(){return null==this.x&&null==this.y||this.z.equals(BigInteger.ZERO)&&!this.y.toBigInteger().equals(BigInteger.ZERO)},t.PointFp.prototype.negate=function(){return new t.PointFp(this.curve,this.x,this.y.negate(),this.z)},t.PointFp.prototype.add=function(e){if(this.isInfinity())return e;if(e.isInfinity())return this;var n=e.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(e.z)).mod(this.curve.q),i=e.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(e.z)).mod(this.curve.q);if(BigInteger.ZERO.equals(i))return BigInteger.ZERO.equals(n)?this.twice():this.curve.getInfinity();var r=new BigInteger("3"),o=this.x.toBigInteger(),s=this.y.toBigInteger(),a=(e.x.toBigInteger(),e.y.toBigInteger(),i.square()),u=a.multiply(i),c=o.multiply(a),l=n.square().multiply(this.z),p=l.subtract(c.shiftLeft(1)).multiply(e.z).subtract(u).multiply(i).mod(this.curve.q),h=c.multiply(r).multiply(n).subtract(s.multiply(u)).subtract(l.multiply(n)).multiply(e.z).add(n.multiply(u)).mod(this.curve.q),y=u.multiply(this.z).multiply(e.z).mod(this.curve.q);return new t.PointFp(this.curve,this.curve.fromBigInteger(p),this.curve.fromBigInteger(h),y)},t.PointFp.prototype.twice=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var e=new BigInteger("3"),n=this.x.toBigInteger(),i=this.y.toBigInteger(),r=i.multiply(this.z),o=r.multiply(i).mod(this.curve.q),s=this.curve.a.toBigInteger(),a=n.square().multiply(e);BigInteger.ZERO.equals(s)||(a=a.add(this.z.square().multiply(s)));var u=(a=a.mod(this.curve.q)).square().subtract(n.shiftLeft(3).multiply(o)).shiftLeft(1).multiply(r).mod(this.curve.q),c=a.multiply(e).multiply(n).subtract(o.shiftLeft(1)).shiftLeft(2).multiply(o).subtract(a.square().multiply(a)).mod(this.curve.q),l=r.square().multiply(r).shiftLeft(3).mod(this.curve.q);return new t.PointFp(this.curve,this.curve.fromBigInteger(u),this.curve.fromBigInteger(c),l)},t.PointFp.prototype.multiply=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,n=t,i=n.multiply(new BigInteger("3")),r=this.negate(),o=this;for(e=i.bitLength()-2;e>0;--e){o=o.twice();var s=i.testBit(e);s!=n.testBit(e)&&(o=o.add(s?this:r))}return o},t.PointFp.prototype.multiplyTwo=function(t,e,n){var i;i=t.bitLength()>n.bitLength()?t.bitLength()-1:n.bitLength()-1;for(var r=this.curve.getInfinity(),o=this.add(e);i>=0;)r=r.twice(),t.testBit(i)?r=n.testBit(i)?r.add(o):r.add(this):n.testBit(i)&&(r=r.add(e)),--i;return r},t.PointFp.prototype.getEncoded=function(e){var n=this.getX().toBigInteger(),i=this.getY().toBigInteger(),r=t.integerToBytes(n,32);return e?i.isEven()?r.unshift(2):r.unshift(3):(r.unshift(4),r=r.concat(t.integerToBytes(i,32))),r},t.PointFp.decodeFrom=function(e,n){n[0];var i=n.length-1,r=n.slice(1,1+i/2),o=n.slice(1+i/2,1+i);r.unshift(0),o.unshift(0);var s=new BigInteger(r),a=new BigInteger(o);return new t.PointFp(e,e.fromBigInteger(s),e.fromBigInteger(a))},t.PointFp.prototype.add2D=function(e){if(this.isInfinity())return e;if(e.isInfinity())return this;if(this.x.equals(e.x))return this.y.equals(e.y)?this.twice():this.curve.getInfinity();var n=e.x.subtract(this.x),i=e.y.subtract(this.y).divide(n),r=i.square().subtract(this.x).subtract(e.x),o=i.multiply(this.x.subtract(r)).subtract(this.y);return new t.PointFp(this.curve,r,o)},t.PointFp.prototype.twice2D=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var e=this.curve.fromBigInteger(BigInteger.valueOf(2)),n=this.curve.fromBigInteger(BigInteger.valueOf(3)),i=this.x.square().multiply(n).add(this.curve.a).divide(this.y.multiply(e)),r=i.square().subtract(this.x.multiply(e)),o=i.multiply(this.x.subtract(r)).subtract(this.y);return new t.PointFp(this.curve,r,o)},t.PointFp.prototype.multiply2D=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,n=t,i=n.multiply(new BigInteger("3")),r=this.negate(),o=this;for(e=i.bitLength()-2;e>0;--e){o=o.twice();var s=i.testBit(e);s!=n.testBit(e)&&(o=o.add2D(s?this:r))}return o},t.PointFp.prototype.isOnCurve=function(){var t=this.getX().toBigInteger(),e=this.getY().toBigInteger(),n=this.curve.getA().toBigInteger(),i=this.curve.getB().toBigInteger(),r=this.curve.getQ(),o=e.multiply(e).mod(r),s=t.multiply(t).multiply(t).add(n.multiply(t)).add(i).mod(r);return o.equals(s)},t.PointFp.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"},t.PointFp.prototype.validate=function(){var t=this.curve.getQ();if(this.isInfinity())throw new Error("Point is at infinity.");var e=this.getX().toBigInteger(),n=this.getY().toBigInteger();if(e.compareTo(BigInteger.ONE)<0||e.compareTo(t.subtract(BigInteger.ONE))>0)throw new Error("x coordinate out of bounds");if(n.compareTo(BigInteger.ONE)<0||n.compareTo(t.subtract(BigInteger.ONE))>0)throw new Error("y coordinate out of bounds");if(!this.isOnCurve())throw new Error("Point is not on the curve.");if(this.multiply(t).isInfinity())throw new Error("Point is not a scalar multiple of G.");return!0},t.CurveFp=function(e,n,i){this.q=e,this.a=this.fromBigInteger(n),this.b=this.fromBigInteger(i),this.infinity=new t.PointFp(this,null,null),this.reducer=new Barrett(this.q)},t.CurveFp.prototype.getQ=function(){return this.q},t.CurveFp.prototype.getA=function(){return this.a},t.CurveFp.prototype.getB=function(){return this.b},t.CurveFp.prototype.equals=function(t){return t==this||this.q.equals(t.q)&&this.a.equals(t.a)&&this.b.equals(t.b)},t.CurveFp.prototype.getInfinity=function(){return this.infinity},t.CurveFp.prototype.fromBigInteger=function(e){return new t.FieldElementFp(this.q,e)},t.CurveFp.prototype.reduce=function(t){this.reducer.reduce(t)},t.CurveFp.prototype.decodePointHex=function(e){var n=parseInt(e.substr(0,2),16);switch(n){case 0:return this.infinity;case 2:case 3:var i=1&n,r=new BigInteger(s=e.substr(2,e.length-2),16);return this.decompressPoint(i,r);case 4:case 6:case 7:var o=(e.length-2)/2,s=e.substr(2,o),a=e.substr(o+2,o);return new t.PointFp(this,this.fromBigInteger(new BigInteger(s,16)),this.fromBigInteger(new BigInteger(a,16)));default:return null}},t.CurveFp.prototype.encodePointHex=function(t){if(t.isInfinity())return"00";var e=t.getX().toBigInteger().toString(16),n=t.getY().toBigInteger().toString(16),i=this.getQ().toString(16).length;for(i%2!=0&&i++;e.length<i;)e="0"+e;for(;n.length<i;)n="0"+n;return"04"+e+n},t.CurveFp.prototype.decompressPoint=function(e,n){var i=this.fromBigInteger(n),r=i.multiply(i.square().add(this.getA())).add(this.getB()).sqrt();if(null==r)throw new Error("Invalid point compression");var o=r.toBigInteger();return(o.testBit(0)?1:0)!=e&&(r=this.fromBigInteger(this.getQ().subtract(o))),new t.PointFp(this,i,r,null,!0)},t.fromHex=function(t){return new BigInteger(t,16)},t.integerToBytes=function(t,e){var n=t.toByteArrayUnsigned();if(e<n.length)n=n.slice(n.length-e);else for(;e>n.length;)n.unshift(0);return n},t.X9Parameters=function(t,e,n,i){this.curve=t,this.g=e,this.n=n,this.h=i},t.X9Parameters.prototype.getCurve=function(){return this.curve},t.X9Parameters.prototype.getG=function(){return this.g},t.X9Parameters.prototype.getN=function(){return this.n},t.X9Parameters.prototype.getH=function(){return this.h},t.secNamedCurves={secp256k1:function(){var e=t.fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F"),n=BigInteger.ZERO,i=t.fromHex("7"),r=t.fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"),o=BigInteger.ONE,s=new t.CurveFp(e,n,i),a=s.decodePointHex("0479BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8");return new t.X9Parameters(s,a,r,o)}},t.getSECCurveByName=function(e){return null==t.secNamedCurves[e]?null:t.secNamedCurves[e]()}}();var zl=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],zr=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],sl=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],sr=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11],hl=[0,1518500249,1859775393,2400959708,2840853838],hr=[1352829926,1548603684,1836072691,2053994217,0],bytesToWords=function(t){for(var e=[],n=0,i=0;n<t.length;n++,i+=8)e[i>>>5]|=t[n]<<24-i%32;return e},wordsToBytes=function(t){for(var e=[],n=0;n<32*t.length;n+=8)e.push(t[n>>>5]>>>24-n%32&255);return e},processBlock=function(t,e,n){for(var i=0;i<16;i++){var r=n+i,o=e[r];e[r]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}var s,a,u,c,l,p,h,y,d,f,_;p=s=t[0],h=a=t[1],y=u=t[2],d=c=t[3],f=l=t[4];for(i=0;i<80;i+=1)_=s+e[n+zl[i]]|0,_+=i<16?f1(a,u,c)+hl[0]:i<32?f2(a,u,c)+hl[1]:i<48?f3(a,u,c)+hl[2]:i<64?f4(a,u,c)+hl[3]:f5(a,u,c)+hl[4],_=(_=rotl(_|=0,sl[i]))+l|0,s=l,l=c,c=rotl(u,10),u=a,a=_,_=p+e[n+zr[i]]|0,_+=i<16?f5(h,y,d)+hr[0]:i<32?f4(h,y,d)+hr[1]:i<48?f3(h,y,d)+hr[2]:i<64?f2(h,y,d)+hr[3]:f1(h,y,d)+hr[4],_=(_=rotl(_|=0,sr[i]))+f|0,p=f,f=d,d=rotl(y,10),y=h,h=_;_=t[1]+u+d|0,t[1]=t[2]+c+f|0,t[2]=t[3]+l+p|0,t[3]=t[4]+s+h|0,t[4]=t[0]+a+y|0,t[0]=_};function f1(t,e,n){return t^e^n}function f2(t,e,n){return t&e|~t&n}function f3(t,e,n){return(t|~e)^n}function f4(t,e,n){return t&n|e&~n}function f5(t,e,n){return t^(e|~n)}function rotl(t,e){return t<<e|t>>>32-e}function ripemd160(t){var e=[1732584193,4023233417,2562383102,271733878,3285377520],n=bytesToWords(t),i=8*t.length,r=8*t.length;n[i>>>5]|=128<<24-i%32,n[14+(i+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);for(var o=0;o<n.length;o+=16)processBlock(e,n,o);for(o=0;o<5;o++){var s=e[o];e[o]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8)}return wordsToBytes(e)}var ychapi={};window.ychapi=ychapi,ychapi._data={buys:{},sells:{},trades:{},markets:{}},ychapi._nnum="",ychapi._sigi_num=30,ychapi._pagesize=15,ychapi._pubkey1="",ychapi._prvkey1="",ychapi._pubkey2="",ychapi._pubkey3="",ychapi._addresses={},ychapi._locktimes1={},ychapi._locktimes2={},ychapi._asset_extra_info={},ychapi._ready_init_data=!1,console.log("ychapi init1"),ychapi._zerotxid="0000000000000000000000000000000000000000000000000000000000000000",ychapi._evm_zeroaddr="0x0000000000000000000000000000000000000000",ychapi._start=null,ychapi._call_init=null,ychapi._call_login=null,ychapi._call_logout=null,ychapi._get_coin_names=null,ychapi._get_coin_info=null,ychapi._get_markets_groups_names=null,ychapi._get_market_group=null,ychapi._get_market_group_by_coinb=null,ychapi._get_markets_names_in_group=null,ychapi._get_markets_names=null,ychapi._get_market_info=null,ychapi._get_coin_balance=null,ychapi._get_coin_usd_rate=null,ychapi._get_coin_deposits=null,ychapi._get_coin_withdrawals=null,ychapi._get_coin_txouts=null,ychapi._call_register=null,ychapi._call_get_email_from_redeem=null,ychapi._call_get_registration_login=null,ychapi._call_confirm_registration_login=null,ychapi._call_confirm_registration_2fa=null,ychapi._get_user_login_keys_v1=null,ychapi._get_user_login_pubk=null,ychapi._has_user_login_prvk=null,ychapi._get_user_signing_pubk=null,ychapi._has_user_signing_prvk=null,ychapi._set_user_login_keys=null,ychapi._has_coin_holding_address=null,ychapi._get_coin_holding_address=null,ychapi._get_coin_user_locktime=null,ychapi._get_coin_server_locktime=null,ychapi._get_coin_allowed_deposit_senders=null,ychapi._call_register_deposit_evm_address=null,ychapi._call_unregister_deposit_evm_address=null,ychapi._get_user_trading_discount=null,ychapi._get_buy_fee=null,ychapi._get_sell_fee=null,ychapi._get_user_buys=null,ychapi._get_user_sells=null,ychapi._get_user_trades=null,ychapi._get_market_buys=null,ychapi._get_market_sells=null,ychapi._get_market_trades=null,ychapi._call_buy=null,ychapi._call_sell=null,ychapi._call_buy_order_cancel=null,ychapi._call_sell_order_cancel=null,ychapi._call_get_chart_data=null,ychapi._validate_address=null,ychapi._get_withdraw_rawtx=null,ychapi._call_send=null,ychapi._create_withdraw=null,ychapi._update_withdraw=null,ychapi._set_withdraw_amount=null,ychapi._has_withdraw_inputs_stage=null,ychapi._call_withdraw_inputs_stage=null,ychapi._set_withdraw_inputs_for_debit=null,ychapi._call_withdraw=null,ychapi._call_withdraw_report_txid=null,ychapi._call_withdraw_cancel=null,ychapi._get_page_size=null,ychapi._get_evm_erc20_abi=null,ychapi._get_evm_vault7u_abi=null,ychapi._sign_evm_vault7u_user1=null,ychapi._get_user_account_id=null,ychapi._get_user_account_login=null,ychapi._get_user_account_twofa=null,ychapi._get_user_rewards=null,ychapi._get_user_referral_invitation_code=null,ychapi._get_user_referral_invitation_title=null,ychapi._is_logged_in=null,ychapi._has_profile=null,ychapi._jsonBNparse=function(t,e){return"string"==typeof e&&/^\-?\d+n$/.test(e)?BigInt(e.slice(0,-1)):e},ychapi._ajaxcall=function(t,e,n,i){try{const r=ychapi._get_cookie("jwt"),o=new XMLHttpRequest;o.open(t,e,!0),o.setRequestHeader("Authorization","Bearer "+r),o.onreadystatechange=function(){4===o.readyState&&(200===o.status?i(null,o.responseText):i(o.status+": "+o.statusText))},o.onerror=function(t){i(o.status+": "+o.statusText+" "+t)},"PUT"===t&&o.setRequestHeader("Content-Type","application/json"),o.send(n)}catch(t){i(t)}},ychapi._apicall=async function(t,e){if(null!=e&&null!=e||(e=0),"digest"in t){ychapi._init_coinjs();let e=ychapi._get_user_login_prvk();"uprvk"in t&&(e=t.uprvk);const n=ychapi._str2bytes(t.digest+ychapi._nnum),i=Crypto.SHA256(n,{asBytes:!0}),r=Crypto.SHA256(i,{asBytes:!0}),o=coinjs.privkey2wif(e),s=coinjs.signHash(o,r);t.data.usig=s}let n="PUT";return"calltype"in t&&(n=t.calltype),new Promise(((i,r)=>{ychapi._ajaxcall(n,ychapi._base_uri+t.uri,JSON.stringify(t.data,((t,e)=>"bigint"==typeof e?e.toString()+"n":e)),(function(o,s){if(o)r(o);else{const o=JSON.parse(s,ychapi._jsonBNparse);"GETRAW"==n||o.ok?i(o):0==o.ok&&"nnum"in o&&""!=o.nnum&&e<1?(ychapi._nnum=o.nnum,ychapi._apicall(t,e+1).then((function(t){i(t)})).catch((function(t){r(t)}))):r(o.error)}}))}))},ychapi._start=function(t,e){ychapi._base_uri=t,ychapi._ready_init_data=!1,ychapi._callbacks=e,ychapi._timer_reauth=setTimeout((function(){}),ychapi._timer_reauth_duration),ychapi._start_ws(),ychapi._call_init()},ychapi._do_apicall_reauth=function(){""!=ychapi._get_jwt_uid()&&ychapi._apicall({calltype:"GET",uri:"/u/reauth",data:{}}).then((function(t){document.cookie="jwt="+t.access+";SameSite=Strict",ychapi._do_ws_init()})).catch((function(t){ychapi._call_logout()}))},ychapi._get_user_login_pubk=function(){return ychapi._pubkey1},ychapi._has_user_login_prvk=function(){return null!=ychapi._prvkey1&&""!=ychapi._prvkey1},ychapi._get_user_login_prvk=function(){return ychapi._prvkey1},ychapi._get_user_signing_pubk=function(){return ychapi._pubkey1},ychapi._has_user_signing_prvk=function(){return null!=ychapi._prvkey1&&""!=ychapi._prvkey1},ychapi._get_user_signing_prvk=function(){return ychapi._prvkey1},ychapi._get_server_signing_pubk=function(){return ychapi._pubkey2},ychapi._get_credit_signing_pubk=function(){return ychapi._pubkey3},ychapi._set_user_login_keys=function(t,e){ychapi._pubkey1=t,ychapi._prvkey1=e},ychapi._get_coin_user_locktime=function(t){return null==ychapi._data.profile?0:t in ychapi._locktimes1?ychapi._locktimes1[t]:0},ychapi._get_coin_server_locktime=function(t){return null==ychapi._data.profile?0:t in ychapi._locktimes2?ychapi._locktimes2[t]:0},ychapi._get_coin_allowed_deposit_senders=function(t){return null!=ychapi._data.profile&&(t in ychapi._asset_extra_info&&"senders"in ychapi._asset_extra_info[t]?ychapi._asset_extra_info[t].senders:[])},ychapi._cleanup_email=function(t){return t.startsWith("BM-")?t:t.toLowerCase()},ychapi._get_user_login_keys_v1=function(t,e){t=ychapi._cleanup_email(t);let n=Crypto.SHA256(Crypto.SHA256(t)+Crypto.SHA256(e));return[n,ychapi._priv_to_pub(n,!0)]},ychapi._priv_to_pub=function(t,e){let n=BigInteger.fromByteArrayUnsigned(Crypto.util.hexToBytes(t)),i=EllipticCurve.getSECCurveByName("secp256k1").getG().multiply(n),r=i.getX().toBigInteger(),o=i.getY().toBigInteger(),s=EllipticCurve.integerToBytes(r,32);if(s=s.concat(EllipticCurve.integerToBytes(o,32)),s.unshift(4),1==e){let t=EllipticCurve.integerToBytes(r,32);return o.isEven()?t.unshift(2):t.unshift(3),Crypto.util.bytesToHex(t)}return Crypto.util.bytesToHex(s)},ychapi._init_coinjs=function(t){coinjs.pub=[111],coinjs.priv=[239],coinjs.multisig=[196],coinjs.base32pref="",coinjs.compressed=!1,coinjs.txversion=1,coinjs.shf=0,coinjs.maxrbf=0,coinjs.txExtraTimeField=0;const e=ychapi._get_coin_info(t);if(null==e)return;if("peg_t1"!=e.type&&"txout_t1"!=e.type)return;const n=e.cfg;if(""==n.pub)return;const i=Crypto.util.hexToBytes(n.pub),r=Crypto.util.hexToBytes(n.prv),o=Crypto.util.hexToBytes(n.msig);coinjs.pub=i,coinjs.priv=r,coinjs.multisig=o,coinjs.base32pref=n.pref,coinjs.compressed=n.comp,coinjs.txversion=n.txver,coinjs.txExtraTimeField=n.txtime,coinjs.shf=n.shf,coinjs.maxrbf=n.maxrbf},ychapi._get_txouts_selection=function(t,e){let n=[],i=0n,r=0n,o=0n,s=0n;if(t.forEach((function(t,e){s+=t.free})),s<e)return console.log("ych_select_txouts, free",s," is less than amount",e),[n,-1,-1,-1];for(;i<e;){for(let s=0;s<t.length;s++){let a=t[s];if(s+1==t.length){n.push(a),a.selected=a.free,i+=a.free,r+=a.orders,o+=a.filled,t=t.slice(0,s);break}if(i+a.free>=e){n.push(a),a.selected=a.free,i+=a.free,r+=a.orders,o+=a.filled,t.splice(s,1);break}if(i>=e)break}if(i<e&&0==t.length)return console.log("ych_select_txouts, no fit",i,e),[n,-1,-1,-1]}return i>e&&n.length>0&&(txout=n[0],txout.selected-=i-e),[n,i,r,o]},ychapi._sign_txout_t1=function(t){if(""==t.txid)return[null,"Txid is empty"];if(t.nout<0)return[null,"Nout is not valid"];const e=t.coin,n=ychapi._get_coin_holding_address(e);if(""==n)return[null,"Not change address"];const i=ychapi._get_coin_info(e);if(null==i)return[null,"No coininfo"];const r=i.fee.minamount;if("txout_t1"!=i.type)return[null,"Not supported"];if(""==t.addr.rdsc)return[null,"Redeem script is not valid"];let o=t.free-t.selected,s=t.amount-o;s<r&&(s=r),s>t.amount&&(s=t.amount),o=t.amount-s;let a=t.amount-t.filled-o;a<r&&(a=r),a>t.amount-t.filled&&(a=t.amount-t.filled),o=t.amount-t.filled-a;let u={};if(u.txid=t.txid,u.nout=t.nout,u.amnt=t.amount,u.fill=t.filled,u.usea=t.selected,o>=r){const e=ychapi._sign_txout_t1_multipos(t,n,o);return 0==e.length?[null,"Fail to sign change"]:(u.sigv=o,u.siga=n,u.sigs=e,u.sigf="",[u,null])}const c=ychapi._sign_txout_t1_full(t);return 0==c.length?[null,"Fail to sign txout"]:(u.sigv=0n,u.siga="",u.sigs=[],u.sigf=c,[u,null])},ychapi._sign_txout_t1_hash=function(t,e,n){const i=t.coin;if(""==t.txid)return[null,"Txid is empty"];if(t.nout<0)return[null,"Nout is not valid"];const r=ychapi._get_coin_info(i);if(null==r)return[null,"No coininfo "+i];if("txout_t1"==r.type){if(""==t.addr.rdsc)return[null,"Redeem script is not valid"];ychapi._init_coinjs(i);const r=1;let o=coinjs.transaction();const s=coinjs.privkey2wif(ychapi._get_user_signing_prvk()),a=o.transactionSig(e,s,r,Crypto.util.hexToBytes(n)),u="",c=0n;return[{txid:t.txid,nout:t.nout,amnt:t.amount,fill:t.filled,usea:t.selected,sigf:a,sign:u,sigv:c},null]}return[null,"Not supported coin "+i]},ychapi._sign_txout_t1_full=function(t){const e=t.coin;if(""==t.txid)return console.log("Txid is empty"),[];if(t.nout<0)return console.log("Nout is not valid"),[];const n=ychapi._get_coin_info(e);if(null==n)return console.log("No coininfo",e),[];if("txout_t1"==n.type){if(""==t.addr.rdsc)return console.log("Redeem script is not valid"),[];ychapi._init_coinjs(e);let n=null;coinjs.maxrbf>0&&(n=coinjs.maxrbf-1);const i=130;let r=coinjs.transaction();r.addinput(t.txid,t.nout,Crypto.util.hexToBytes(t.addr.rdsc),n,t.amount);let o=r.transactionHash(0,i);if(2==t.addr.vers){o=r.transactionHashSegWitV0(0,t.addr.rdsc,i,Number(t.amount)).hash}const s=coinjs.privkey2wif(ychapi._get_user_signing_prvk());return r.transactionSig(0,s,i,Crypto.util.hexToBytes(o))}return console.log("Not supported",e),[]},ychapi._sign_txout_t1_multipos=function(t,e,n){const i=t.coin;if(""==t.txid)return console.log("Txid is empty"),[];if(t.nout<0)return console.log("Nout is not valid"),[];if(""==e)return console.log("Change address is empty"),[];if("bigint"!=typeof n)return console.log("Change need bigint",change),[];const r=ychapi._get_coin_info(i);if(null==r)return console.log("No coininfo",i),[];if("txout_t1"==r.type){if(""==t.addr.rdsc)return console.log("Redeem script is not valid"),[];ychapi._init_coinjs(i);let r=null;coinjs.maxrbf>0&&(r=coinjs.maxrbf-1);let o=coinjs.privkey2wif(ychapi._get_user_signing_prvk()),s=[];const a="e".repeat(64);for(let i=0;i<ychapi._sigi_num;i++){const u=131;let c=coinjs.transaction();for(let t=0;t<i;t++){const t=0,n=[];c.addinput(a,t,Crypto.util.hexToBytes(n),null,1n),c.addoutput(e,1n)}c.addinput(t.txid,t.nout,Crypto.util.hexToBytes(t.addr.rdsc),r,t.amount),c.addoutput(e,n);let l=c.transactionHash(i,u);if(2==t.addr.vers){l=c.transactionHashSegWitV0(i,t.addr.rdsc,u,Number(t.amount)).hash}const p=c.transactionSig(i,o,u,Crypto.util.hexToBytes(l));s.push(p)}return s}return console.log("Not supported",i),[]},ychapi._evm_erc20_abi=[{inputs:[{internalType:"string",name:"name_",type:"string"},{internalType:"string",name:"symbol_",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"}],name:"burn",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"}],name:"mint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}],ychapi._get_evm_erc20_abi=function(){return ychapi._evm_erc20_abi},ychapi._evm_vault7u_abi=[{inputs:[{internalType:"address",name:"tss_addr",type:"address"},{internalType:"address",name:"weth_addr",type:"address"},{internalType:"address[]",name:"add_coins",type:"address[]"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"coin",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"},{indexed:!0,internalType:"address",name:"user",type:"address"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"},{indexed:!1,internalType:"bytes32",name:"state",type:"bytes32"},{indexed:!1,internalType:"uint256",name:"irev",type:"uint256"},{indexed:!1,internalType:"uint256",name:"orev",type:"uint256"}],name:"In",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"coin",type:"address"},{indexed:!0,internalType:"address",name:"user",type:"address"},{indexed:!1,internalType:"bytes32",name:"state1",type:"bytes32"},{indexed:!1,internalType:"bytes32",name:"state2",type:"bytes32"},{indexed:!1,internalType:"uint256",name:"irev",type:"uint256"},{indexed:!1,internalType:"uint256",name:"orev",type:"uint256"},{indexed:!1,internalType:"uint256",name:"balance",type:"uint256"},{indexed:!1,internalType:"uint256",name:"sigr",type:"uint256"},{indexed:!1,internalType:"uint256",name:"sigv",type:"uint256"}],name:"Op",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"sender",type:"address"},{indexed:!0,internalType:"address",name:"user",type:"address"},{indexed:!1,internalType:"bool",name:"reg",type:"bool"}],name:"Reg",type:"event"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"}],name:"balances",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"coin",type:"address"},{components:[{internalType:"address",name:"user",type:"address"},{internalType:"uint256",name:"usea",type:"uint256"},{internalType:"bytes",name:"sig1",type:"bytes"},{internalType:"uint256",name:"sigr",type:"uint256"},{internalType:"uint256",name:"sigv",type:"uint256"}],internalType:"struct Vault7.Use[]",name:"uses",type:"tuple[]"},{components:[{internalType:"address",name:"user",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],internalType:"struct Vault7.Fill[]",name:"fills",type:"tuple[]"},{internalType:"bytes",name:"sig2",type:"bytes"},{internalType:"uint256",name:"tw",type:"uint256"}],name:"clearance1",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"coins",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"coin",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"address",name:"user",type:"address"},{internalType:"bytes",name:"sig1",type:"bytes"}],name:"deposit1",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"}],name:"irevs",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"addr",type:"address"},{internalType:"uint256",name:"min_amount",type:"uint256"},{internalType:"bool",name:"on",type:"bool"},{internalType:"bytes",name:"sig2",type:"bytes"},{internalType:"uint256",name:"tw",type:"uint256"}],name:"listCoin",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"locktime1",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"locktime2",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"minamount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"}],name:"orevs",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"user",type:"address"},{internalType:"bytes",name:"sig1",type:"bytes"},{internalType:"uint256",name:"tw",type:"uint256"}],name:"register1",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"user",type:"address"},{internalType:"bool",name:"on",type:"bool"},{internalType:"bytes",name:"sig2",type:"bytes"},{internalType:"uint256",name:"tw",type:"uint256"}],name:"register2",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"}],name:"sigr",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"},{internalType:"uint256",name:"",type:"uint256"}],name:"sigv",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"}],name:"states",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"totals",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"unregister1",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"user",type:"address"},{internalType:"bytes",name:"sig1",type:"bytes"}],name:"unregister2",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"users",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"ustate",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"coin",type:"address"},{internalType:"address",name:"user",type:"address"},{internalType:"address",name:"dest",type:"address"},{components:[{internalType:"address",name:"user",type:"address"},{internalType:"uint256",name:"usea",type:"uint256"},{internalType:"bytes",name:"sig1",type:"bytes"},{internalType:"uint256",name:"sigr",type:"uint256"},{internalType:"uint256",name:"sigv",type:"uint256"}],internalType:"struct Vault7.Use[]",name:"uses",type:"tuple[]"},{internalType:"bytes",name:"sig2",type:"bytes"},{internalType:"uint256",name:"tw",type:"uint256"}],name:"withdraw1",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"coin",type:"address"},{internalType:"address",name:"dest",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes",name:"sig2",type:"bytes"}],name:"withdraw3",outputs:[],stateMutability:"nonpayable",type:"function"},{stateMutability:"payable",type:"receive"}],ychapi._get_evm_vault7u_abi=function(){return ychapi._evm_vault7u_abi},ychapi._get_evm_vault7u_hash1=function(t,e,n,i,r){const o=_ethers.utils.arrayify(e),s=_ethers.utils.arrayify(t),a=_ethers.utils.arrayify(i),u=_ethers.utils.hexZeroPad(_ethers.utils.hexValue(n),32),c=_ethers.utils.arrayify(u),l=_ethers.utils.hexZeroPad(_ethers.utils.hexValue(r),32),p=_ethers.utils.arrayify(l),h=_ethers.utils.concat([s,o,c,a,p]),y=_ethers.utils.keccak256(h),d=_ethers.utils.arrayify(y),f=_ethers.utils.toUtf8Bytes("Ethereum Signed Message:\n32"),_=_ethers.utils.concat([f,d]);return _ethers.utils.keccak256(_)},ychapi._sign_evm_vault7u_user1=function(t,e,n,i,r){const o=ychapi._get_evm_vault7u_hash1(t,e,n,i,r),s=new _ethers.utils.SigningKey("0x"+ychapi._get_user_signing_prvk()).signDigest(o);return _ethers.utils.joinSignature(s)},ychapi._get_evm_vault7u_next_state1=function(t,e,n,i){const r=_ethers.utils.arrayify(t),o=_ethers.utils.arrayify(e),s=_ethers.utils.hexZeroPad(_ethers.utils.hexValue(n),32),a=_ethers.utils.arrayify(s),u=_ethers.utils.hexZeroPad(_ethers.utils.hexValue(i),32),c=_ethers.utils.arrayify(u),l=_ethers.utils.concat([r,o,a,c]);return _ethers.utils.keccak256(l)},ychapi._call_register=async function(t,e,n){return new Promise(((i,r)=>{const[o,s]=ychapi._get_user_login_keys_v1(t,e),a=n+t+s;ychapi._apicall({uri:"/u/register",uprvk:o,digest:a,data:{invt:n,user:t,upub:s}}).then((function(){i()})).catch((function(t){r(t)}))}))},ychapi._call_get_email_from_redeem=async function(t){return new Promise(((e,n)=>{ychapi._apicall({uri:"/u/redeem",data:{code:t}}).then((function(t){e(t.email)})).catch((function(t){n(t)}))}))},ychapi._call_get_registration_login=async function(t){return new Promise(((e,n)=>{ychapi._apicall({uri:"/u/confirmg",data:{code:t}}).then((function(t){e(t.login)})).catch((function(t){n(t)}))}))},ychapi._call_confirm_registration_login=async function(t,e,n){return new Promise(((i,r)=>{const[o,s]=ychapi._get_user_login_keys_v1(t,e),a=n+s;ychapi._apicall({uri:"/u/confirme",uprvk:o,digest:a,data:{code:n}}).then((function(t){i(t)})).catch((function(t){r(t)}))}))},ychapi._call_confirm_registration_2fa=async function(t,e,n,i){return new Promise(((r,o)=>{const[s,a]=ychapi._get_user_login_keys_v1(t,e),u=n+i+a;ychapi._apicall({uri:"/u/confirma",uprvk:s,digest:u,data:{code:n,auth:i}}).then((function(t){r(t)})).catch((function(t){o(t)}))}))},ychapi._ready_data=!1,ychapi._call_init=async function(){return new Promise(((t,e)=>{ychapi._apicall({calltype:"GET",uri:"/u/init",data:{}}).then((function(e){ychapi._on_data_call_init(e),ychapi._ready_init_data=!0,t(e)})).catch((function(t){ychapi._ready_init_data=!1,console.log("apicall err:",t),console.log("apicall err, logout"),ychapi._callbacks.on_sync_connection_error(t),e(t)}))}))},ychapi._call_login=async function(t,e,n){return new Promise(((i,r)=>{const[o,s]=ychapi._get_user_login_keys_v1(t,e),a=t+s+n;ychapi._apicall({uri:"/u/init",uprvk:o,digest:a,data:{user:t,upub:s,code:n}}).then((function(t){if(!t.access)return void r("notoken");if("unconfirmed"==t.access)return void r("unconfirmed");document.cookie="jwt="+t.access+";SameSite=Strict",window.location.hash="";""!=ychapi._get_jwt_uid()?(ychapi._set_user_login_keys(s,o),ychapi._on_data_call_init(t),i()):r("notoken")})).catch((function(t){r(t)}))}))},ychapi._call_logout=function(){document.cookie="jwt=; expires=Thu, 01 Jan 1970 00:00:01 GMT;SameSite=Strict",ychapi._set_user_login_keys("",""),ychapi._data.profile=void 0,ychapi._callbacks.on_sync_data_update("logout",{}),ychapi._do_ws_init()},ychapi._on_data_call_init=function(t){ychapi._data=t,ychapi._nnum=t.nnum;for(const t in ychapi._data.coininfos)ychapi._callbacks.on_sync_data_update("coininfo",ychapi._data.coininfos[t]);if(null!=t.profile){ychapi._pubkey1=t.profile.pubk1,ychapi._pubkey2=t.profile.pubk2,ychapi._pubkey3=t.profile.pubk3;t.profile.assets.forEach((function(t){const e=t.coin;ychapi._addresses[e]=t.address,ychapi._locktimes1[e]=t.locktime1,ychapi._locktimes2[e]=t.locktime2,null!=t.extra&&(ychapi._asset_extra_info[e]=t.extra)})),ychapi._callbacks.on_sync_data_update("login",{})}else ychapi._call_logout();ychapi._ready_data=!0,ychapi._callbacks.on_sync_data_init(),ychapi._do_ws_init()},ychapi._get_coin_names=function(){return ychapi._data.coins},ychapi._get_coin_info=function(t){return t in ychapi._data.coininfos?ychapi._data.coininfos[t]:null},ychapi._get_coin_balance=function(t){return null==ychapi._data.profile?null:t in ychapi._data.profile.balances?ychapi._data.profile.balances[t]:null},ychapi._get_coin_usd_rate=function(t){const e=ychapi._get_coin_info(t);return null==e?0:e.ext.priceext},ychapi._get_coin_deposits=function(t){return null==ychapi._data.profile?[]:t in ychapi._data.profile.deposits?ychapi._data.profile.deposits[t]:[]},ychapi._get_coin_withdrawals=function(t){return null==ychapi._data.profile?[]:t in ychapi._data.profile.withdraws?ychapi._data.profile.withdraws[t]:[]},ychapi._get_coin_txouts=function(t){if(null==ychapi._data.profile)return[];if(!(t in ychapi._data.profile.txouts))return[];const e=ychapi._data.profile.txouts[t];return JSON.parse(JSON.stringify(e,((t,e)=>"bigint"==typeof e?e.toString()+"n":e)),ychapi._jsonBNparse)},ychapi._get_markets_groups_names=function(){let t=[];return ychapi._data.groups.forEach((function(e,n){t.push(e.name)})),t},ychapi._get_market_group=function(t){for(let e in ychapi._data.groups){const n=ychapi._data.groups[e];if(n.name==t)return n}return null},ychapi._get_market_group_by_coinb=function(t){for(let e in ychapi._data.groups){const n=ychapi._data.groups[e];if(n.coinb==t)return n}return null},ychapi._get_markets_names_in_group=function(t){const e=ychapi._get_market_group(t);if(null==e)return[];let n=[];for(let t in ychapi._data.markets)n.push(ychapi._data.markets[t]);n.sort((function(t,e){return Number(t.index-e.index)}));let i=[];return n.forEach((function(t,n){t.coinb==e.coinb&&i.push(t.name)})),i},ychapi._get_markets_names=function(){let t=[];for(let e in ychapi._data.markets)t.push(ychapi._data.markets[e]);t.sort((function(t,e){return Number(t.index-e.index)}));let e=[];return t.forEach((function(t,n){e.push(t.name)})),e},ychapi._get_market_info=function(t){return t in ychapi._data.markets?ychapi._data.markets[t]:null},ychapi._get_user_account_id=function(){return null==ychapi._data.profile?"":ychapi._data.profile.uidx},ychapi._get_user_account_login=function(){return null==ychapi._data.profile?"":ychapi._data.profile.user},ychapi._get_user_account_twofa=function(){return null!=ychapi._data.profile&&ychapi._data.profile.twofa},ychapi._get_user_trading_discount=function(){return null==ychapi._data.profile?0:ychapi._data.profile.discount},ychapi._get_user_rewards=function(t){return null==ychapi._data.profile?0n:t in ychapi._data.profile.rewards?ychapi._data.profile.rewards[t]:0n},ychapi._get_user_referral_invitation_code=function(){return null==ychapi._data.profile?"":ychapi._data.profile.invt},ychapi._get_user_referral_invitation_title=function(){return null==ychapi._data.profile?"":ychapi._data.profile.title},ychapi._get_user_trades=function(t){return null==ychapi._data.profile||null==ychapi._data.profile.trades?[]:t in ychapi._data.profile.trades?ychapi._data.profile.trades[t]:[]},ychapi._get_user_buys=function(t){return null==ychapi._data.profile||null==ychapi._data.profile.buys?[]:t in ychapi._data.profile.buys?ychapi._data.profile.buys[t]:[]},ychapi._get_user_sells=function(t){return null==ychapi._data.profile||null==ychapi._data.profile.sells?[]:t in ychapi._data.profile.sells?ychapi._data.profile.sells[t]:[]},ychapi._get_market_trades=function(t){return null==ychapi._data.trades?[]:t in ychapi._data.trades?ychapi._data.trades[t]:[]},ychapi._get_market_buys=function(t){return null==ychapi._data.buys?[]:t in ychapi._data.buys?ychapi._data.buys[t]:[]},ychapi._get_market_sells=function(t){return null==ychapi._data.sells?[]:t in ychapi._data.sells?ychapi._data.sells[t]:[]},ychapi._get_buy_fee=function(t,e,n){const i=ychapi._get_user_trading_discount(),r=ychapi._get_coin_info(n).fee.buyfee*(100-i)/100;if(null==ychapi._data.markets)return r;if(!t in ychapi._data.markets)return r;const o=ychapi._data.markets[t];return o.fee.over?o.fee.buyfee:r},ychapi._get_sell_fee=function(t,e,n){const i=ychapi._get_user_trading_discount(),r=ychapi._get_coin_info(e).fee.sellfee*(100-i)/100;if(null==ychapi._data.markets)return r;if(!t in ychapi._data.markets)return r;const o=ychapi._data.markets[t];return o.fee.over?o.fee.sellfee:r},ychapi._is_logged_in=function(){const t=ychapi._get_cookie("jwt").split(".");if(3==t.length){const e=t[1].replace("-","+").replace("_","/");if("uid"in JSON.parse(window.atob(e)))return!0}return!1},ychapi._has_profile=function(){return null!=ychapi._data.profile&&null!=ychapi._data.profile},ychapi._call_send=function(t,e,n,i){return new Promise(((r,o)=>{if(!ychapi._has_user_login_prvk())return void o("no login key to sign");if(""==ychapi._get_coin_holding_address(t))return void o("Not available the change address");const s=ychapi._get_coin_info(t),a=s.fee.sendfee;if(BigInt(Math.floor(.5+Number(n)*a))!=i)return void o("Fee calculation error");const u=n+i;let c=0n,l=u;const p=ychapi._get_coin_balance(t);if(u>p.free)return void o("Not enough coins");if(p.debit>0){let t=p.debit-p.ordersindebit;if(t<0)return void o("Error debt usage is negative");t>=u?(c=u,l=0n):t>0&&(c=t,l=u-t)}let h=[];if(l>0){console.log("total_via_txouts",l);let e=ychapi._get_coin_txouts(t);ychapi._init_coinjs(t);const n=e.filter((t=>350==t.state||400==t.state||800==t.state));if(e=e.filter((t=>400==t.state)),e.sort((function(t,e){return Number(t.free-e.free)})),"txout_t1"==s.type){const[t,n,i,r]=ychapi._get_txouts_selection(e,l);if(n<0n||n<l)return void o("send: not enough available coins in txouts to use "+l);console.log("selected txouts:",t,n,i,r);for(let e=0;e<t.length;e++){const n=t[e],[i,r]=ychapi._sign_txout_t1(n);if(null!=r)return void o(r);h.push(i)}}if("evm_t1"==s.type||"erc20_t1"==s.type){const e=s.cfg.unit,i=l;for(let r=0;r<n.length;r++){const o=n[r],s="0x"+o.txid,a=o.orders+o.filled+i,u=a*e,c=[ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(t),s,u,ychapi._evm_zeroaddr,o.nout+1)];let l={};l.txid=o.txid,l.nout=o.nout,l.amnt=o.amount,l.fill=o.filled,l.usea=i,l.sigf="",l.sigv=a,l.sigs=c,h.push(l)}}}let y="";h.forEach((function(t,e){y+=t.txid+":"+t.nout,y+=t.fill.toString(),y+=t.usea.toString()}));const d=t+e+n.toString()+i.toString()+c.toString()+y+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/send",digest:d,data:{coin:t,addr:e,amount:n,fee:i,usedebit:c,usetxouts:h}}).then((function(){r()})).catch((function(t){o(t)}))}))},ychapi._call_buy=async function(t,e,n,i,r,o,s){return new Promise(((a,u)=>{if(!ychapi._has_user_login_prvk())return void u("no login key to sign");if(""==ychapi._get_coin_holding_address(n))return void u("not available the change address");const c=ychapi._get_coin_info(n),l=ychapi._get_buy_fee(t,e,n);if(r*i/BigInt(1e8)!=o)return void u("amountb calculation error");if(BigInt(Math.floor(.5+Number(o)*l))!=s)return void u("feeb calculation error");const p=o+s,h=ychapi._get_coin_balance(n);let y=0n,d=p;if(h.debit>0){let t=h.debit-h.ordersindebit;if(t<0)return void u("error debt usage is negative");t>=p?(y=p,d=0):t>0&&(y=t,d=p-t)}let f=[];if(d>0){let t=ychapi._get_coin_txouts(n);ychapi._init_coinjs(n);const e=t.filter((t=>350==t.state||400==t.state||800==t.state));if(t=t.filter((t=>400==t.state)),t.sort((function(t,e){return Number(t.free-e.free)})),"txout_t1"==c.type){const[e,n]=ychapi._get_txouts_selection(t,d);if(n<0||n<d)return void u("not enough available coins in txouts to trade "+d);for(let t=0;t<e.length;t++){const n=e[t],[i,r]=ychapi._sign_txout_t1(n);if(null!=r)return void u(r);f.push(i)}}if("evm_t1"==c.type||"erc20_t1"==c.type){const t=c.cfg.unit,i=d;for(let r=0;r<e.length;r++){const o=e[r],s="0x"+o.txid,a=o.orders+o.filled+i,u=a*t,c=[ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(n),s,u,ychapi._evm_zeroaddr,o.nout+1)],l={txid:o.txid,nout:o.nout,amnt:o.amount,fill:o.filled,usea:i,sigf:"",sigv:a,sigs:c};f.push(l)}}}let _="";f.forEach((function(t){_+=t.txid+":"+t.nout,_+=t.fill.toString(),_+=t.usea.toString()}));const g=e+n+i.toString()+r.toString()+o.toString()+"0"+s.toString()+y.toString()+_+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/buy",digest:g,data:{coina:e,coinb:n,price:i,amounta:r,amountb:o,feea:0n,feeb:s,usedebit:y,usetxouts:f}}).then((function(t){a(t)})).catch((function(t){u(t)}))}))},ychapi._call_buy_order_cancel=async function(t,e,n){return new Promise(((i,r)=>{const o=t+e+n.toString()+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/nobuy",digest:o,data:{coina:t,coinb:e,index:n}}).then((function(){i()})).catch((function(t){r(t)}))}))},ychapi._call_sell=async function(t,e,n,i,r,o,s){return new Promise(((a,u)=>{if(!ychapi._has_user_login_prvk())return void u("no login key to sign");if(""==ychapi._get_coin_holding_address(e))return void u("not available the change address");const c=ychapi._get_coin_info(e),l=ychapi._get_sell_fee(t,e,n);if(r*i/BigInt(1e8)!=o)return void u("amountb calculation error");if(BigInt(Math.floor(.5+Number(r)*l))!=s)return void u("feea calculation error");const p=r+s,h=ychapi._get_coin_balance(e);let y=0n,d=p;if(h.debit>0){let t=h.debit-h.ordersindebit;if(t<0)return void u("error debt usage is negative");t>=p?(y=p,d=0n):t>0&&(y=t,d=p-t)}let f=[];if(d>0){let t=ychapi._get_coin_txouts(e);ychapi._init_coinjs(e);const n=t.filter((t=>350==t.state||400==t.state||800==t.state));if(t=t.filter((t=>400==t.state)),t.sort((function(t,e){return Number(t.free-e.free)})),"txout_t1"==c.type){const[e,n,i,r]=ychapi._get_txouts_selection(t,d);if(n<0||n<d){const t="not enough available coins in txouts to trade "+d;return page.show_error_sell(t),void u(t)}for(let t=0;t<e.length;t++){const n=e[t],[i,r]=ychapi._sign_txout_t1(n);if(null!=r)return page.show_error_sell(r),void u(r);f.push(i)}}if("evm_t1"==c.type||"erc20_t1"==c.type){const t=c.cfg.unit,i=d;for(let r=0;r<n.length;r++){const o=n[r],s="0x"+o.txid,a=o.orders+o.filled+i,u=a*t,c=[ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(e),s,u,ychapi._evm_zeroaddr,o.nout+1)],l={txid:o.txid,nout:o.nout,amnt:o.amount,fill:o.filled,usea:i,sigf:"",sigv:a,sigs:c};f.push(l)}}}let _="";f.forEach((function(t,e){_+=t.txid+":"+t.nout,_+=t.fill.toString(),_+=t.usea.toString()}));const g=e+n+i.toString()+r.toString()+o.toString()+s.toString()+"0"+y.toString()+_+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/sell",digest:g,data:{coina:e,coinb:n,price:i,amounta:r,amountb:o,feea:s,feeb:0n,usedebit:y,usetxouts:f}}).then((function(t){a(t)})).catch((function(t){u(t)}))}))},ychapi._call_sell_order_cancel=async function(t,e,n){return new Promise(((i,r)=>{const o=t+e+n.toString()+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/nosell",digest:o,data:{coina:t,coinb:e,index:n}}).then((function(){i()})).catch((function(t){r(t)}))}))},ychapi._call_get_chart_data=async function(t,e){return new Promise(((n,i)=>{ychapi._apicall({calltype:"GETRAW",uri:"/u/chart/"+t+"/"+e,data:{}}).then((function(t){n(t)})).catch((function(t){i(t)}))}))},ychapi._is_valid_evm_address=function(t){return!!/^(0x)?[0-9a-f]{40}$/i.test(t)&&(!(!/^(0x)?[0-9a-f]{40}$/.test(t)&&!/^(0x)?[0-9A-F]{40}$/.test(t))||_ethers.utils.isAddress(t))},ychapi._validate_address=function(t,e){if(""==e)return"Address is empty";const n=ychapi._get_coin_info(t);if("txout_t1"==n.type){ychapi._init_coinjs(t);try{let t=coinjs.addressDecode(e);if(0==t)return"Address is not recognized(1)";if("other"==t.type)return"Address is not recognized(2)"}catch(t){return"Address is not recognized(3)"}}if("peg_t1"==n.type){ychapi._init_coinjs(part.coin);try{let t=coinjs.addressDecode(e);if(0==t)return"Address is not recognized(1)";if("bech32"==t.type)return"Address type bech32 is not supported";if("other"==t.type)return"Address is not recognized(2)"}catch(t){return"Address is not recognized(3)"}}return"evm_t1"!=n.type&&"erc20_t1"!=n.type||ychapi._is_valid_evm_address(e)?null:"Address is not recognized"},ychapi._has_coin_holding_address=function(t){return null!=ychapi._data.profile&&(t in ychapi._addresses&&""!=ychapi._addresses[t])},ychapi._get_coin_holding_address=function(t){return null==ychapi._data.profile?"":t in ychapi._addresses?ychapi._addresses[t]:""},ychapi._get_coin_credit_address=function(t){if("txout_t1"!=ychapi._get_coin_info(t).type)return"";if(null==ychapi._data.profile)return"";const e=ychapi._get_credit_signing_pubk();if(null==e)return"";const n=ychapi._get_server_signing_pubk();if(null==n)return"";return coinjs.pubkeys2MultisigAddressWithBackup(e,n,0,0).address},ychapi._call_register_deposit_evm_address=function(t,e,n){return new Promise(((i,r)=>{const o="register1",s=t+o+ychapi._get_coin_holding_address(t)+e.toString()+n+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/address",digest:s,data:{coin:t,call:o,user:ychapi._get_coin_holding_address(t),blck:e,sender:n}}).then((function(t){i()})).catch((function(t){r(t)}))}))},ychapi._call_unregister_deposit_evm_address=function(t,e,n){return new Promise(((i,r)=>{const o="unregister2",s=part.coin+o+ychapi._get_coin_holding_address(part.coin)+e.toString()+account_addr+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/address",digest:s,data:{coin:t,call:o,user:ychapi._get_coin_holding_address(t),blck:e,sender:n}}).then((function(t){i()})).catch((function(t){r(t)}))}))},ychapi._create_withdraw=function(t,e){let n={};n.coin=t,n.scope=e,n.sendfee=0n,n.datatag=0n,n.mode="reduce",n.last_error=null;return"txout_t1"==ychapi._get_coin_info(t).type&&(n.datatag=1n),n.op1=ychapi._create_withdraw_op(),n.op2=ychapi._create_withdraw_op(),n.op3=ychapi._create_withdraw_op(),n.get_available_amount=function(){let t=0n;return n.op1.txouts.forEach((function(e){t+=e.free})),t},n.get_sendfee=function(){return n.sendfee},n.get_output_datatag_amount=function(){return 0n==n.op2.amount_out?0n:n.datatag},n.set_txouts_user=function(t){t.txouts_user=ychapi._get_coin_txouts(n.coin),t.txouts_user=t.txouts_user.filter((t=>400==t.state&&"allocated"!=n.scope||500==t.state&&"allocated"==n.scope)),t.txouts_user.sort((function(t,e){return Number(e.free-t.free)})),t.txouts=t.txouts_user},n.set_txouts_debit=function(t){if(t.txouts_debit=[],"allocated"==n.scope)return;const e=ychapi._get_coin_balance(n.coin);if(null==e)return;if(e.debit<=0)return;const i=ychapi._get_coin_info(n.coin);if("peg_t1"!=i.type&&"evm_t1"!=i.type&&"txout_t1"!=i.type&&"erc20_t1"!=i.type)return;0n!=e.debit-e.ordersindebit&&(t.txouts_debit=[ychapi._create_virtual_debit_txout(n.coin)],t.txouts=t.txouts.concat(t.txouts_debit))},n.select_txouts2=function(){if("reduce"==n.mode){let t=0n;n.op2.txouts.forEach((function(e){t+=e.free})),t<n.op2.amount_inp&&(n.op2.amount_inp=t)}let t=n.op2.select2(n.op2.amount_inp);return null!=t?t:("reduce"==n.mode?n.op2.reduce(n.get_output_datatag_amount()):n.op2.change-=n.get_output_datatag_amount(),null)},n.stabilize_op=function(t){n.trace("stabilize_op",t);let e=0n;const i=ychapi._get_coin_info(n.coin);"txout_t1"==i.type&&(e=i.fee.minamount);let r=t.stabilize(i,e);return n.trace("stabilize_op end",t),r},n.trace=function(t,e){},n},ychapi._update_withdraw=function(t){return t.set_txouts_user(t.op1),t.set_txouts_debit(t.op1),t.op1.make_id2idx(),t.set_txouts_user(t.op2),t.set_txouts_debit(t.op2),t.op2.make_id2idx(),err=t.last_error=ychapi._compute_withdraw_datas(t),err},ychapi._set_withdraw_amount=function(t,e,n){t.op1.amount_inp=e,t.op2.amount_inp=e;const i=Number(t.op1.amount_inp)/1e8,r=ychapi._get_coin_info(t.coin);return null==r?"Coin is not supported":(t.sendfee=BigInt(Math.floor(.5+i*r.fee.withfee*1e8)),"allocated"==t.scope&&(t.sendfee=0n),t.mode=n,"manual"==t.mode&&(t.op2.reduce_mode=!1,t.op3.reduce_mode=!0),"reduce"==t.mode&&(t.op2.reduce_mode=!0,t.op3.reduce_mode=!0),err=t.last_error=ychapi._compute_withdraw_datas(t),err)},ychapi._set_withdraw_inputs_for_debit=function(t,e){t.set_txouts_user(t.op3),t.op3.txouts_debit=e,t.op3.txouts=t.op3.txouts.concat(t.op3.txouts_debit),t.op3.make_id2idx();let n=t.op3.select3(t.op2.amount_out);return null!=n?n:(t.op3.change>0n?t.op3.change-=t.get_output_datatag_amount():t.op3.reduce(t.get_output_datatag_amount()),n=t.stabilize_op(t.op3),null!=n?n:null)},ychapi._compute_withdraw_datas=function(t){let e=t.last_error=t.op1.select1(t.get_sendfee(),t.op2);if(null!=e)return e;if(e=t.last_error=t.select_txouts2(),null!=e)return e;if(e=t.last_error=t.stabilize_op(t.op2),null!=e)return e;if(e=t.last_error=ychapi._validate_address(t.coin,ychapi._get_coin_holding_address(t.coin)),null!=e)return e;const n=ychapi._get_coin_info(t.coin);if(null==n)return"Coin is not supported";if("txout_t1"==n.type){const n=ychapi._get_coin_credit_address(t.coin);if(""==n)return"Credit address is not available";if(e=t.last_error=ychapi._validate_address(t.coin,n),null!=e)return e}return e=t.last_error=ychapi._validate_withdraw_inputs_outputs(t),null!=e?e:null},ychapi._build_txout_t1_tx=function(t,e,n){if("txout_t1"!=ychapi._get_coin_info(t).type)return null;ychapi._init_coinjs(t);let i=null;coinjs.maxrbf>0&&(i=coinjs.maxrbf-1);let r=coinjs.transaction();for(let t=0;t<e.selected.length;t++){let n=e.selected[t],o=coinjs.pubkeys2MultisigAddressWithBackup(n.addr.pub1,n.addr.pub2,n.addr.lck1,n.addr.lck2),s=i;2==n.hold&&(s=n.nseq),r.addinput(n.txid,n.nout,Crypto.util.hexToBytes(o.redeemScript),s,n.amount)}e.amount_out>0n&&r.addoutput(n,e.amount_out),e.change>0n&&r.addoutput(ychapi._get_coin_holding_address(t),e.change),e.credit>0n&&r.addoutput(ychapi._get_coin_credit_address(t),e.credit);let o=[];e.selected.forEach((function(t){let e=Crypto.util.hexToBytes(t.txid).reverse();for(let t=0;t<e.length;t++)o.push(e[t]);let n=coinjs.numToBytes(t.nout);for(let t=0;t<n.length;t++)o.push(n[t])})),o.push("L".charCodeAt(0));for(let t=0;t<n.length;t++)o.push(n.charCodeAt(t));let s=coinjs.numToBytes(Number(e.amount_out));for(let t=0;t<s.length;t++)o.push(s[t]);var a=Crypto.SHA256(Crypto.SHA256(o,{asBytes:!0}),{asBytes:!0});let u="XCH:0:"+Crypto.util.bytesToHex(a.reverse());return r.adddata(Crypto.util.bytesToHex(ychapi._str2bytes(u)),1),r},ychapi._get_withdraw_rawtx=function(t){const e=ychapi._build_txout_t1_tx(t.coin,t.op2,t.addr_send);return null==e?null:e.serialize()},ychapi._validate_withdraw_inputs_outputs=function(t){let e=0n;t.op2.selected.forEach((function(t){e+=t.amount}));let n=t.op2.amount_out+t.op2.change+t.op2.credit+t.get_output_datatag_amount()+t.op2.netfee;return e!=n?"Can not configure inputs(6), change the quantity":null},ychapi._create_virtual_debit_txout=function(t){let e=0n,n=0n;const i=ychapi._get_coin_balance(t);null!=i&&(e=i.debit,n=i.ordersindebit);let r={gidx:1,cidx:1,coin:t,hold:2,state:500,addr:{vers:1,host:"",addr:ychapi._get_coin_holding_address(t),pub1:ychapi._get_credit_signing_pubk(),pub2:ychapi._get_server_signing_pubk(),lck1:0,lck2:0,pksc:"",rdsc:"00"},txid:ychapi._zerotxid,nout:0,free:e-n,orders:0n,amount:e-n,filled:0n,selected:0n};return"peg_t1"==ychapi._get_coin_info(t).type&&(r.amount=e,r.orders=0n,r.filled=n),r},ychapi._has_withdraw_inputs_stage=function(t){return ychapi._has_withdraw_op2_inputs_stage(t.coin,t.op2)},ychapi._has_withdraw_op2_inputs_stage=function(t,e){if("txout_t1"!=ychapi._get_coin_info(t).type)return!1;for(let t=0;t<e.selected.length;t++){if(e.selected[t].txid==ychapi._zerotxid)return!0}return!1},ychapi._prepare_withdraw_call_payload=function(t,e,n,i,r){const o=ychapi._get_coin_info(t);ychapi._init_coinjs(t);const s=Math.floor((new Date).getTime()/1e3)+o.cfg.tw,a=BigInt(s);let u=[],c=[],l="",p="";if("txout_t1"==o.type){for(let t=0;t<i.selected.length;t++){const e=i.selected[t];l+=e.txid+":"+e.nout,l+=e.filled.toString(),l+=e.selected.toString();const[n,r]=ychapi._sign_txout_t1(e);if(null!=r)return[null,null,r];u.push(n)}const n=ychapi._build_txout_t1_tx(t,r,e);console.log("op2 tx:",n);for(let t=0;t<r.selected.length;t++){const e=r.selected[t];p+=e.txid+":"+e.nout,p+=e.filled.toString(),p+=e.selected.toString();const i=1;let o=n.transactionHash(t,i);if(2==e.addr.vers){o=n.transactionHashSegWitV0(t,e.addr.rdsc,i,Number(e.amount)).hash}const[s,a]=ychapi._sign_txout_t1_hash(e,t,o);if(null!=a)return[null,null,a];c.push(s)}}if("peg_t1"==o.type)for(let t=0;t<r.selected.length;t++){const e=r.selected[t];p+=e.txid+":"+e.nout,p+=e.filled.toString(),p+=e.selected.toString();const n="",i="",o=0n,s={txid:e.txid,nout:e.nout,amnt:e.amount,fill:e.filled,usea:e.selected,sigf:n,sign:i,sigv:o};c.push(s)}if("evm_t1"==o.type||"erc20_t1"==o.type){const n=o.cfg.unit;for(let e=0;e<i.selected.length;e++){const r=i.selected[e];l+=r.txid+":"+r.nout,l+=r.filled.toString(),l+=r.selected.toString();const o="0x"+r.txid,s=r.orders+r.filled+r.selected,a=s*n,c=[ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(t),o,a,ychapi._evm_zeroaddr,r.nout+1)],p={txid:r.txid,nout:r.nout,amnt:r.amount,fill:r.filled,usea:r.selected,sigf:"",sigv:s,sigs:c};u.push(p)}let h=0,y=0;if(r.selected.forEach((function(t,e){t.txid==ychapi._zerotxid?y++:h++})),h>1){return[null,null,"More than one state: unfinished chain operations, try later"]}if(y>1){return[null,null,"More than one debit, error"]}r.selected.forEach((function(i,r){p+=i.txid+":"+i.nout,p+=i.filled.toString(),p+=i.selected.toString();let o="",u="",l=0n;if(i.txid==ychapi._zerotxid);else{l=i.selected;const r=i.selected*n,c="0x"+i.txid;o=ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(t),c,r,e,s);const p=(0,ychapi._get_evm_vault7u_next_state1)(c,e,r,a),h=(i.orders+i.filled)*n;u=ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(t),p,h,ychapi._evm_zeroaddr,i.nout+1)}const h={txid:i.txid,nout:i.nout,amnt:i.amount,fill:i.filled,usea:i.selected,sigf:o,sign:u,sigv:l,sigs:[]};c.push(h)}))}const h=ychapi._get_coin_holding_address(t),y=ychapi._get_coin_credit_address(t);return[t+e+y+h+r.amount_out.toString()+r.debit.toString()+r.credit.toString()+r.change.toString()+r.netfee.toString()+n.toString()+l+p+ychapi._get_user_login_pubk(),{coin:t,addr_send:e,addr_credit:y,addr_change:h,value_send:r.amount_out,value_debit:r.debit,value_credit:r.credit,value_change:r.change,value_netfee:r.netfee,value_sendfee:n,usetxouts1:u,usetxouts2:c,twin:a},null]},ychapi._call_withdraw_inputs_stage=function(t){return new Promise(((e,n)=>{let i=!1;for(let e=0;e<t.op2.selected.length;e++){if(t.op2.selected[e].txid==ychapi._zerotxid){i=!0;break}}if(!i)throw new Error("No debit");if("txout_t1"!=ychapi._get_coin_info(t.coin).type)throw new Error("Invalid coin type");const[r,o,s]=ychapi._prepare_withdraw_call_payload(t.coin,t.addr_send,t.get_sendfee(),t.op1,t.op2);if(null!=s)throw s;ychapi._apicall({uri:"/u/withdraw",digest:r,data:o}).then((function(t){if(!("step"in t))throw new Error("Unexpected response without step");if("txouts"!=t.step)throw new Error("Unexpected response without txouts step: "+t.step);e(t.txouts)})).catch((function(t){n(t)}))}))},ychapi._call_withdraw=function(t,e,n,i,r){return new Promise(((o,s)=>{if(ychapi._has_withdraw_op2_inputs_stage(t,r))return void s("Debit is not filled");const[a,u,c]=ychapi._prepare_withdraw_call_payload(t,e,n,i,r);null==c?ychapi._apicall({uri:"/u/withdraw",digest:a,data:u}).then((function(t){o(t)})).catch((function(t){s(t)})):s(c)}))},ychapi._call_withdraw_report_txid=function(t,e,n){return new Promise(((i,r)=>{ychapi._apicall({uri:"/u/withdraw_evm_txid",data:{coin:t,gidx:e,txid:n}}).then((function(t){i()})).catch((function(t){r(t)}))}))},ychapi._call_withdraw_cancel=function(t,e){return new Promise(((n,i)=>{const r=t+e+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/nowithdraw",digest:r,data:{coin:t,gidx:e}}).then((function(t){n()})).catch((function(t){i(t)}))}))},ychapi._create_withdraw_op=function(){let t={reduce_mode:!1,amount_inp:0n,amount_out:0n,txouts:[],txouts_user:[],txouts_debit:[],txout_id_to_idx:{},selected:[],unselected:[],netfee:0n,debit:0n,change:0n,credit:0n,num_inps:0,num_outs:0,rawtx:"",select1:function(e,n){if(t.selected=[],t.txouts.forEach((function(t){t.selected=0n})),1==t.txouts_debit.length){let n=t.txouts_debit[0];if(n.free>0n){let i=n.free;i>e&&(i=e),n.selected=i,t.selected.push(n),e-=i}}if(e>0n){let n=[...t.txouts_user];n.sort((function(t,e){return Number(t.free-e.free)}));{let t=0n;if(n.forEach((function(e,n){t+=e.free})),t<e)return console.log("txouts_free < amount",t,e),"Not enough available for withdraw"}let i=0n;for(;i<e;)for(let r=0;r<n.length;r++){let o=n[r];if(r+1==n.length){t.selected.push(o);let s=o.free;i+s>e&&(s=e-i),o.selected=s,i+=o.free,n=n.slice(0,r);break}if(i+o.free>=e){t.selected.push(o);let s=o.free;i+s>e&&(s=e-i),o.selected=s,i+=o.free,n.splice(r,1);break}if(i>=e)break}}return t.make_unselected(),t.use2credit(n),null},make_id2idx:function(){t.txout_id_to_idx={},t.txouts.forEach((function(e,n){const i=e.txid+":"+e.nout;t.txout_id_to_idx[i]=n}))},make_unselected:function(){let e={};t.selected.forEach((function(n){let i=n.txid+":"+n.nout;e[i]=!0,t.credit+=n.filled;const r=n.amount-n.selected-n.filled;t.change+=r})),t.unselected=[],t.txouts.forEach((function(n){n.txid+":"+n.nout in e||t.unselected.push(n)}))},use2credit:function(e){return t.selected.forEach((function(t,n){const i=t.txid+":"+t.nout;if(!(i in e.txout_id_to_idx))return;const r=e.txout_id_to_idx[i];let o=e.txouts[r];o.txid==ychapi._zerotxid?(o.free=t.free-t.selected,o.amount=t.amount-t.selected):(o.free=t.free-t.selected,o.filled=t.filled+t.selected)})),null},select2:function(e){t.selected=[],t.amount_inp=e,t.amount_out=e,t.debit=0n,t.credit=0n,t.change=0n,t.netfee=0n,t.txouts.forEach((function(t){t.selected=0n}));let n=[...t.txouts_user];n.sort((function(t,e){return Number(t.free-e.free)}));let i=0n,r=e,o=0n;n.forEach((function(t){o+=t.free})),r>o&&(i=r-o,r=o);let s=!1;if(i>0n){let e=i;if(1==t.txouts_debit.length){let n=t.txouts_debit[0];if(n.free>0n){let i=n.free;i>e&&(i=e),n.selected=i,t.selected.push(n),e-=i,s=!0}}if(e>0n)return"Not enough available for withdraw"}let a=r,u=0n;for(;u<a;){for(let e=0;e<n.length;e++){let i=n[e];if(e+1==n.length){t.selected.push(i);let r=i.free;u+r>a&&(r=a-u),i.selected=r,u+=i.free,n=n.slice(0,e);break}if(u+i.free>=a){t.selected.push(i);let r=i.free;u+r>a&&(r=a-u),i.selected=r,u+=i.free,n.splice(e,1);break}if(u>=a)break}if(0==n.length)break}return u<a?"Not enough available for withdraw":(t.make_unselected(),null)},select3:function(e){t.selected=[],t.amount_inp=e,t.amount_out=e,t.debit=0n,t.credit=0n,t.change=0n,t.netfee=0n,t.txouts.forEach((function(t){t.selected=0n}));let n=[...t.txouts_user];n.sort((function(t,e){return Number(t.free-e.free)}));let i=0n,r=e,o=0n;n.forEach((function(t){o+=t.free})),r>o&&(i=r-o,r=o);let s=r,a=0n;for(;a<s;){for(let e=0;e<n.length;e++){let i=n[e];if(e+1==n.length){t.selected.push(i);let r=i.free;a+r>s&&(r=s-a),i.selected=r,a+=i.free,n=n.slice(0,e);break}if(a+i.free>=s){t.selected.push(i);let r=i.free;a+r>s&&(r=s-a),i.selected=r,a+=i.free,n.splice(e,1);break}if(a>=s)break}if(0==n.length)break}if(a<s)return"Not enough available for withdraw";for(n=[...t.txouts_debit],n.sort((function(t,e){return Number(t.free-e.free)})),s=i,a=0n;a<s;){for(let e=0;e<n.length;e++){let i=n[e];if(e+1==n.length){t.selected.push(i);let r=i.free;a+r>s&&(r=s-a),i.selected=r,a+=i.free,n=n.slice(0,e);break}if(a+i.free>=s){t.selected.push(i);let r=i.free;a+r>s&&(r=s-a),i.selected=r,a+=i.free,n.splice(e,1);break}if(a>=s)break}if(0==n.length)break}return a<s?"Not enough available for withdraw":(t.make_unselected(),null)},add_more:function(e){let n=[],i=null;t.unselected.forEach((function(t){t.txid!=ychapi._zerotxid?n.push(t):i=t}));let r=[],o=0n;for(n.sort((function(t,e){return Number(t.amount-t.filled-(e.amount-e.filled))}));o<e;){for(let i=0;i<n.length;i++){let s=n[i],a=s.amount-s.filled;if(i+1==n.length){t.selected.push(s),r.push(s),s.selected=0n,o+=a,n=n.slice(0,i);break}if(o+a>=e){t.selected.push(s),r.push(s),s.selected=0n,o+=a,n.splice(i,1);break}if(o>=e)break}if(0==n.length)break}if(o<e&&null!=i){let e=i,n=e.amount-e.filled;t.selected.push(i),r.push(i),i.selected=0n,o+=n}if(o<e)return"Not enough available to select";let s={};return t.selected.forEach((function(t){let e=t.txid+":"+t.nout;s[e]=!0})),r.forEach((function(e){t.credit+=e.filled;const n=e.amount-e.selected-e.filled;t.change+=n})),t.unselected=[],t.txouts.forEach((function(e){e.txid+":"+e.nout in s||t.unselected.push(e)})),null},reduce:function(e){t.amount_out-=e;let n=t.selected;n.sort((function(t,e){return Number(t.selected-e.selected)}));for(let t=0;t<n.length;t++){let i=n[t],r=e;if(r>i.selected&&(r=i.selected),i.selected-=r,0n==(e-=r))break}},stabilize_changes:function(e){if(0n==e)return!0;if((0n==t.credit||t.credit>=e)&&(0n==t.change||t.change>=e))return!0;const n=t.change+t.credit;if(t.credit>0n&&e<=n&&n<e+e)return t.debit=t.change,t.credit=n,t.change=0n,!0;if(t.credit>0n&&t.credit<e&&n>=e+e){let n=e-t.credit;return t.debit+=n,t.credit+=n,t.change-=n,!0}return t.change>0n&&t.change<e&&n>=e+e&&(t.debit+=t.change,t.credit+=t.change,t.change=0n,!0)},stabilize_change:function(e,n){if(t.stabilize_changes(e))return null;let i=e-(t.change+t.credit),r=0n;if(t.unselected.forEach((function(t){r+=t.amount-t.filled})),i<=r){let n=t.add_more(i);if(null!=n)return n;if(t.stabilize_changes(e))return null}else if(n&&t.amount_out>i){t.reduce(i),t.change+=i;if(t.stabilize_changes(e))return null}return"Can not configure inputs(1), change the quantity"},compute_netfee:function(e){if(0n!=t.amount_inp)if("peg_t1"!=e.type)if("txout_t1"!=e.type)t.netfee=0n;else{const n=e.fee.txbytefee;t.num_inps=t.selected.length,t.num_outs=1,t.change>0n&&t.num_outs++,t.credit>0n&&t.num_outs++,t.num_outs++;let i=386*t.num_inps+34*(t.num_outs-1)+80;e.fee.txbyteround>1&&(i=Math.ceil(i/e.fee.txbyteround)*e.fee.txbyteround),t.netfee=BigInt(Math.floor(i*n*1e8+.5));const r=e.fee.mempoolminfee,o=BigInt(Math.floor(1e8*r+.5));t.netfee<o&&(t.netfee=o)}else t.netfee=10000000n;else t.netfee=0n},stabilize_netfee:function(e,n){let i=0n;"txout_t1"==e.type&&(i=e.fee.minamount);let r=0n,o=0n,s=0n;for(let a=0;a<10;a++){if(t.change+=r,t.credit+=o,t.debit+=s,r=0n,o=0n,s=0n,null!=t.stabilize_change(i,n))break;t.compute_netfee(e);let a=t.netfee,u=a;if(t.debit>0n&&t.credit>0n){let e=t.credit;if(e>t.debit&&(e=t.debit),e>u&&(e=u),t.credit-e>0n&&t.credit-e<i&&(e=t.credit-i),u-=e,o+=e,t.credit-=e,s+=e,t.debit-=e,0n==u)return null}if(t.change>0n&&t.change>=u){if(r+=u,t.change-=u,u=0n,null!=t.stabilize_change(i,n))break;if(t.compute_netfee(e),a!=t.netfee)continue;return null}t.change>0n&&t.change<u&&(r+=t.change,u-=t.change,t.change=0n);let c=0n;if(t.unselected.forEach((function(t,e){c+=t.amount-t.filled})),u<=c){if(t.add_more(u),r+=u,t.change-=u,u=0n,!t.stabilize_changes(i))break;if(t.compute_netfee(e),a!=t.netfee)continue;return null}if(n&&t.amount_out>u){if(t.reduce(u),u=0n,!t.stabilize_changes(i))break;if(t.compute_netfee(e),a!=t.netfee)continue;return null}}return"Can not configure inputs(3), change the quantity"},stabilize:function(e,n){let i=t.stabilize_change(n,t.reduce_mode);return null!=i?i:(i=t.stabilize_netfee(e,t.reduce_mode),null!=i?i:null)}};return t},ychapi._ready_wsdata=!1,ychapi._timer_reauth_duration=3e5,ychapi._ws_callbacks={},ychapi._start_ws=function(){ychapi._ready_wsdata=!1;let t="ws:";"https:"==window.location.protocol&&(t="wss:");let e=t+"//"+window.location.hostname+":"+window.location.port+"/ws";""!=ychapi._base_uri&&(e=ychapi._base_uri+"/ws"),console.log("Use sync connection: "+e),ychapi._websocket=new ReconnectingWebSocket(e),ychapi._websocket.onopen=ychapi._on_ws_onopen,ychapi._websocket.onclose=ychapi._on_ws_onclose,ychapi._websocket.onmessage=ychapi._on_ws_onmessage},ychapi._on_ws_onclose=function(t){ychapi._ready_wsdata=!1,ychapi._callbacks.on_sync_connection_lost()},ychapi._on_ws_onopen=function(t){ychapi._ready_wsdata=!0,ychapi._do_ws_init()},ychapi._do_ws_init=function(){if(ychapi._websocket.readyState!=WebSocket.OPEN)return;const t={type:"init",jwt:ychapi._get_cookie("jwt")};ychapi._websocket.send(JSON.stringify(t)),ychapi._ready_wsdata=!0,ychapi._callbacks.on_sync_connecting(),ychapi._ready_wsdata&&ychapi._ready_data&&ychapi._callbacks.on_sync_ready(),clearTimeout(ychapi._timer_reauth),ychapi._timer_reauth=setTimeout(ychapi._do_apicall_reauth,ychapi._timer_reauth_duration)},ychapi._on_ws_onmessage=function(t){if("message"==t.type){let e={};t.data.split("\n").forEach((function(t,n){try{e=JSON.parse(t,ychapi._jsonBNparse)}catch(t){return}ychapi._on_ws_message(e)}))}else console.log("Received ws event, not a message: ",t)},ychapi._on_ws_message=function(t){"type"in t?(t.type in ychapi._ws_callbacks?ychapi._ws_callbacks[t.type](t):console.log("Received unknown ws event, message: ",t),ychapi._callbacks.on_sync_message(t)):console.log("Received unknown ws event, message: ",t)},ychapi._ws_callbacks.nnum=function(t){const e=t.objects[0];ychapi._nnum=e},ychapi._ws_callbacks.coininfo=function(t){const e=t.objects[0];null==ychapi._data.coininfos&&(ychapi._data.coininfos={}),ychapi._data.coininfos[e.coin]=e,ychapi._callbacks.on_sync_data_update("coininfo",e)},ychapi._ws_callbacks.market=function(t){const e=t.objects[0];ychapi._data.markets[e.name]=e,ychapi._callbacks.on_sync_data_update("market",e)},ychapi._ws_callbacks.markettradesupdate=function(t){const e=t.objects[0],n=e.coina+"-"+e.coinb;ychapi._data.trades[n]=e.page,ychapi._callbacks.on_sync_data_update("trades",n,e.coina,e.coinb,e.page)},ychapi._ws_callbacks.usertradesupdate=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[0],n=e.coina+"-"+e.coinb;ychapi._data.profile.trades[n]=e.page,ychapi._callbacks.on_sync_data_update("user_trades",n,e.coina,e.coinb,e.page)},ychapi._ws_callbacks.depositaddress=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[0],n=e.coin;if(ychapi._addresses[n]=e.addr,ychapi._locktimes1[n]=e.lck1,ychapi._locktimes2[n]=e.lck2,n in ychapi._data.profile.balances){const t=ychapi._data.profile.balances[n];ychapi._callbacks.on_sync_data_update("balance",t)}},ychapi._ws_callbacks.addressesupdate1=function(t){const e=t.objects[0],n=e.coin,i=e.list;n in ychapi._asset_extra_info||(ychapi._asset_extra_info[n]={},ychapi._asset_extra_info[n].senders=[]),ychapi._asset_extra_info[n].senders=i},ychapi._ws_callbacks.adddeposit=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[1],n=e.coin;let i=ychapi._data.profile.deposits[n],r=!0;i.forEach((function(t,n){t.index>=e.index&&(r=!1)})),r&&(i.unshift(e),i=i.slice(0,ychapi._get_page_size()),ychapi._data.profile.deposits[n]=i)},ychapi._ws_callbacks.regdeposit=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[1],n=e.coin;let i=ychapi._data.profile.deposits[n];i.forEach((function(t,n){e.index==t.index&&(i[n]=e,t=e)}))},ychapi._ws_callbacks.addwithdraw=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[1],n=e.coin;let i=ychapi._data.profile.withdraws[n],r=!0;i.forEach((function(t,n){t.uidx>=e.uidx&&(r=!1)})),r&&(i.unshift(e),i=i.slice(0,ychapi._get_page_size()),ychapi._data.profile.withdraws[e.coin]=i)},ychapi._ws_callbacks.regwithdraw=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[1],n=e.coin;let i=ychapi._data.profile.withdraws[n];i.forEach((function(t,n){e.uidx==t.uidx&&(i[n]=e,t=e)}))},ychapi._ws_callbacks.balances=function(t){t.objects[0].forEach((function(t){ychapi._data.profile.balances[t.coin]=t,ychapi._callbacks.on_sync_data_update("balance",t)}))},ychapi._ws_callbacks.accountchange=function(t){},ychapi._ws_callbacks.newcandle=function(t){},ychapi._ws_callbacks.updatecandle=function(t){},ychapi._ws_callbacks.txoutsupdate=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[0],n=t.objects[1];ychapi._data.profile.txouts[e]=n,ychapi._callbacks.on_sync_data_update("txouts",e,n)},ychapi._ws_callbacks.buysupdate=function(t){const e=t.objects[0],n=e.coina+"-"+e.coinb;ychapi._data.buys[n]=e.buyspage,ychapi._callbacks.on_sync_data_update("buys",n,e.coina,e.coinb,e.buyspage)},ychapi._ws_callbacks.sellsupdate=function(t){const e=t.objects[0],n=e.coina+"-"+e.coinb;ychapi._data.sells[n]=e.sellspage,ychapi._callbacks.on_sync_data_update("sells",n,e.coina,e.coinb,e.sellspage)},ychapi._ws_callbacks.userbuysupdate=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[0],n=e.coina+"-"+e.coinb;ychapi._data.profile.buys[n]=e.buyspage,ychapi._callbacks.on_sync_data_update("user_buys",n,e.coina,e.coinb,e.buyspage)},ychapi._ws_callbacks.usersellsupdate=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[0],n=e.coina+"-"+e.coinb;ychapi._data.profile.sells[n]=e.sellspage,ychapi._callbacks.on_sync_data_update("user_sells",n,e.coina,e.coinb,e.sellspage)},ychapi._get_cookie=function(t){const e=t+"=",n=decodeURIComponent(document.cookie).split(";");for(let t=0;t<n.length;t++){let i=n[t];for(;" "==i.charAt(0);)i=i.substring(1);if(0==i.indexOf(e))return i.substring(e.length,i.length)}return""},ychapi._get_jwt_uid=function(){const t=ychapi._get_cookie("jwt").split(".");if(3==t.length){const e=t[1].replace("-","+").replace("_","/");return JSON.parse(window.atob(e)).uid}return""},ychapi._str2bytes=function(t){let e=[];for(let n=0;n<t.length;n++){let i=t.charCodeAt(n);i<128?e.push(i):i<2048?e.push(192|i>>6,128|63&i):i<55296||i>=57344?e.push(224|i>>12,128|i>>6&63,128|63&i):(n++,i=65536+((1023&i)<<10|1023&t.charCodeAt(n)),e.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|63&i))}return e},ychapi._get_page_size=function(){return ychapi._pagesize};
1
+ var coinjs=window.coinjs=function(){};coinjs.bech32={charset:"qpzry9x8gf2tvdw0s3jn54khce6mua7l",version:0,hrp:"bc"},coinjs.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)},coinjs.hash256=function(t){return Crypto.SHA256(Crypto.SHA256(t,{asBytes:!0}),{asBytes:!0})},coinjs.arrayEquals=function(t,e){return Array.isArray(t)&&Array.isArray(e)&&t.length===e.length&&t.every(((t,i)=>t===e[i]))},coinjs.bech32_polymod=function(t){let e=1;const i=[996825010,642813549,513874426,1027748829,705979059];for(let r=0;r<t.length;++r){let o=e>>25;e=(33554431&e)<<5^t[r];for(let t=0;t<5;++t)o>>t&1&&(e^=i[t])}return e},coinjs.bech32_hrpExpand=function(t){var e,i=[];for(e=0;e<t.length;++e)i.push(t.charCodeAt(e)>>5);for(i.push(0),e=0;e<t.length;++e)i.push(31&t.charCodeAt(e));return i},coinjs.bech32_verifyChecksum=function(t,e){return 1===coinjs.bech32_polymod(coinjs.bech32_hrpExpand(t).concat(e))},coinjs.bech32_decode=function(t){var e,i=!1,r=!1;for(e=0;e<t.length;++e){if(t.charCodeAt(e)<33||t.charCodeAt(e)>126)return null;t.charCodeAt(e)>=97&&t.charCodeAt(e)<=122&&(i=!0),t.charCodeAt(e)>=65&&t.charCodeAt(e)<=90&&(r=!0)}if(i&&r)return null;var o=(t=t.toLowerCase()).lastIndexOf("1");if(o<1||o+7>t.length||t.length>90)return null;var a=t.substring(0,o),c=[];for(e=o+1;e<t.length;++e){var l=coinjs.bech32.charset.indexOf(t.charAt(e));if(-1===l)return null;c.push(l)}return coinjs.bech32_verifyChecksum(a,c)?{hrp:a,data:c.slice(0,c.length-6)}:null},coinjs.bech32_convert=function(t,e,i,r){for(var o=0,a=0,c=(1<<i)-1,l=[],p=0;p<t.length;++p)for(o=o<<e|t[p],a+=e;a>=i;)a-=i,l.push(o>>a&c);if(r)a>0&&l.push(o<<i-a&c);else{if(a>=e)throw new Error("Excess padding");if(o<<i-a&c)throw new Error("Non-zero padding")}return l},coinjs.bech32redeemscript=function(t){var e=coinjs.bech32_decode(t);return!!e&&(e.data.shift(),Crypto.util.bytesToHex(coinjs.bech32_convert(e.data,5,8,!1)))};var dbits,CHARSET="qpzry9x8gf2tvdw0s3jn54khce6mua7l",CHARSET_INVERSE_INDEX={q:0,p:1,z:2,r:3,y:4,9:5,x:6,8:7,g:8,f:9,2:10,t:11,v:12,d:13,w:14,0:15,s:16,3:17,j:18,n:19,5:20,4:21,k:22,h:23,c:24,e:25,6:26,m:27,u:28,a:29,7:30,l:31},convertBits=function(t,e,i){let r=Math.ceil(t.length*e/i),o=(1<<i)-1,a=[];for(let t=0;t<r;++t)a.push(0);let c=0,l=0,p=0;for(let r=0;r<t.length;++r){for(l=l<<e|t[r],p+=e;p>=i;)p-=i,a[c]=l>>p&o,++c}return p>0&&(a[c]=l<<i-p&o,++c),a},base32polymod=function(t){let e=[0x98f2bc8e61n,0x79b76d99e2n,0xf33e5fb3c4n,0xae2eabe2a8n,0x1e4f43e470n],i=1n;for(let r=0;r<t.length;++r){let o=t[r],a=i>>35n;i=(0x07ffffffffn&i)<<5n^BigInt(o);for(let t=0;t<e.length;++t)1n==(a>>BigInt(t)&1n)&&(i^=BigInt(e[t]))}return 1n^i},decodeBase32AsBytes=function(t){let e=[];for(let i=0;i<t.length;++i){let r=t[i];e.push(CHARSET_INVERSE_INDEX[r])}e=e.slice(0,e.length-8);let i=convertBits(e,5,8);return i=i.slice(0,i.length-1),encodeBytesToBase32(i)==t&&i},encodeBytesToBase32=function(t){let e=convertBits(t,8,5),i=function(t){let e=[];for(let i=0;i<t.length;++i)e.push(31&t[i].charCodeAt(0));return e}(coinjs.base32pref);i.push(0),i.push(...e),i.push(0,0,0,0,0,0,0,0);e.push(...function(t){let e=[0,0,0,0,0,0,0,0];for(let i=0;i<8;++i)e[7-i]=Number(31n&t),t>>=5n;return e}(base32polymod(i)));let r="";for(let t=0;t<e.length;++t){let i=e[t];r+=CHARSET[i]}return r};coinjs.signHash=function(t,e){const i=EllipticCurve.getSECCurveByName("secp256k1"),r=coinjs.wif2privkey(t),o=BigInteger.fromByteArrayUnsigned(Crypto.util.hexToBytes(r.privkey)),a=i.getN(),c=BigInteger.fromByteArrayUnsigned(e);let l=0,p=null,h=null;do{const r=coinjs.deterministicK(t,e,l);h=i.getG().multiply(r).getX().toBigInteger().mod(a),p=r.modInverse(a).multiply(c.add(o.multiply(h))).mod(a),l++}while(h.compareTo(BigInteger.ZERO)<=0||p.compareTo(BigInteger.ZERO)<=0);const y=a.shiftRight(1);p.compareTo(y)>0&&(p=a.subtract(p));let d=function serializeSig(t,e){const i=t.toByteArraySigned(),r=e.toByteArraySigned();let o=[];return o.push(2),o.push(i.length),o=o.concat(i),o.push(2),o.push(r.length),o=o.concat(r),o.unshift(o.length),o.unshift(48),o}(h,p);return d.push(parseInt(1,10)),Crypto.util.bytesToHex(d)},coinjs.script=function(t){var e={};return t?"string"==typeof t?e.buffer=Crypto.util.hexToBytes(t):coinjs.isArray(t)?e.buffer=t:t instanceof coinjs.script?e.buffer=t.buffer:e.buffer=t:e.buffer=[],e.parse=function(){var t=this;e.chunks=[];var i=0;function readChunk(e){t.chunks.push(t.buffer.slice(i,i+e)),i+=e}for(;i<this.buffer.length;){var r=this.buffer[i++];if(r>=240&&(r=r<<8|this.buffer[i++]),r>0&&r<76?readChunk(r):76==r?readChunk(this.buffer[i++]):77==r?readChunk(this.buffer[i++]<<8|this.buffer[i++]):78==r?readChunk(this.buffer[i++]<<24|this.buffer[i++]<<16|this.buffer[i++]<<8|this.buffer[i++]):this.chunks.push(r),i<0)break}return!0},e.spendToScript=function(t){var e=coinjs.addressDecode(t),i=coinjs.script();return"bech32"==e.type?(i.writeOp(0),i.writeBytes(Crypto.util.hexToBytes(e.redeemscript))):coinjs.arrayEquals(e.version,coinjs.multisig)||"multisig"==e.type?(i.writeOp(169),i.writeBytes(e.bytes),i.writeOp(135)):(i.writeOp(118),i.writeOp(169),i.writeBytes(e.bytes),i.writeOp(136),i.writeOp(172)),i},e.pubkeyHash=function(t){var e=coinjs.addressDecode(t),i=coinjs.script();return i.writeOp(118),i.writeOp(169),i.writeBytes(e.bytes),i.writeOp(136),i.writeOp(172),i},e.writeOp=function(t){return this.buffer.push(t),this.chunks.push(t),!0},e.writeBytes=function(t){return t.length<76?this.buffer.push(t.length):t.length<=255?(this.buffer.push(76),this.buffer.push(t.length)):t.length<=65535?(this.buffer.push(77),this.buffer.push(255&t.length),this.buffer.push(t.length>>>8&255)):(this.buffer.push(78),this.buffer.push(255&t.length),this.buffer.push(t.length>>>8&255),this.buffer.push(t.length>>>16&255),this.buffer.push(t.length>>>24&255)),this.buffer=this.buffer.concat(t),this.chunks.push(t),!0},e.parse(),e},coinjs.transaction=function(){var t={};return t.version=coinjs.txversion,t.lock_time=0,t.ins=[],t.outs=[],t.witness=[],t.timestamp=null,t.block=null,t.nTime=0,t.addinput=function(e,i,r,o,a){var c={};return c.outpoint={hash:e,index:i},c.script=coinjs.script(r||[]),c.sequence=o||(0==t.lock_time?4294967295:0),c.value="bigint"==typeof a?new BigInteger(a.toString()):a?new BigInteger(""+Math.round(1*a*1e8),10):null,this.ins.push(c)},t.addoutput=function(t,e){var i={};i.value="bigint"==typeof e?new BigInteger(e.toString()):new BigInteger(""+Math.round(1*e*1e8),10);var r=coinjs.script();return i.script=r.spendToScript(t),this.outs.push(i)},t.adddata=function(t,e){if(t.match(/^[a-f0-9]+$/gi)&&t.length<160&&t.length%2==0){var i=coinjs.script();return i.writeOp(106),i.writeBytes(Crypto.util.hexToBytes(t)),o={},o.value=e,o.script=i,this.outs.push(o)}return!1},t.transactionHash=function(t,e){var i=coinjs.clone(this),r=e||1;64==coinjs.shf&&(r|=64);for(var o=0;o<i.ins.length;o++)t!=o&&(i.ins[o].script=coinjs.script());var a=this.extractScriptKey(t);if(i.ins[t].script=coinjs.script(a.script),i.ins&&i.ins[t]){var c=224&r,l=31&r;if(1==l);else if(2==l){i.outs=[];for(o=0;o<i.ins.length;o++)t!=o&&(i.ins[o].sequence=0)}else if(3==l){i.outs.length=t+1;for(o=0;o<t;o++)i.outs[o].value=-1,i.outs[o].script.buffer=[];for(o=0;o<i.ins.length;o++)t!=o&&(i.ins[o].sequence=0)}var p,h=i.ins[t];if(128&c&&(i.ins=[i.ins[t]]),64&c){let e=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];p=(p=[]).concat(coinjs.numToBytes(parseInt(i.version),4)),p=128&c?p.concat(e):p.concat(coinjs.hash256(i.getPrevouts())),p=(p=(p=(p=(p=(p=(p=128&c||3==l||2==l?p.concat(e):p.concat(coinjs.hash256(i.getSequences()))).concat(Crypto.util.hexToBytes(h.outpoint.hash).reverse())).concat(coinjs.numToBytes(parseInt(h.outpoint.index),4))).concat(coinjs.numToVarInt(h.script.buffer.length))).concat(h.script.buffer)).concat(coinjs.numToBytes(h.value,8))).concat(coinjs.numToBytes(parseInt(h.sequence),4)),p=(p=(p=3!=l&&2!=l?p.concat(coinjs.hash256(i.getOutputs())):3==l?p.concat(coinjs.hash256(i.getOutput(t))):p.concat(e)).concat(coinjs.numToBytes(parseInt(this.lock_time),4))).concat(coinjs.numToBytes(parseInt(r),4))}else p=(p=Crypto.util.hexToBytes(i.serialize())).concat(coinjs.numToBytes(parseInt(r),4));var y=Crypto.SHA256(p,{asBytes:!0});return Crypto.util.bytesToHex(Crypto.SHA256(y,{asBytes:!0}))}return!1},t.transactionHashSegWitV0=function(t,e,i,r){var o=[],a=coinjs.script(Crypto.util.hexToBytes(e));o=(o=o.concat(coinjs.numToVarInt(a.buffer.length))).concat(a.buffer);var c=coinjs.numToBytes(r,8),l=coinjs.numToBytes(0,32),p=coinjs.numToBytes(parseInt(this.version),4),h=[];if(!(i>=80))for(var y=0;y<this.ins.length;y++)h=(h=h.concat(Crypto.util.hexToBytes(this.ins[y].outpoint.hash).reverse())).concat(coinjs.numToBytes(this.ins[y].outpoint.index,4));var d=h.length>=1?Crypto.SHA256(Crypto.SHA256(h,{asBytes:!0}),{asBytes:!0}):l;h=[];if(!(i>=80)&&2!=i&&3!=i)for(y=0;y<this.ins.length;y++)h=h.concat(coinjs.numToBytes(this.ins[y].sequence,4));var f=h.length>=1?Crypto.SHA256(Crypto.SHA256(h,{asBytes:!0}),{asBytes:!0}):l,_=Crypto.util.hexToBytes(this.ins[t].outpoint.hash).reverse();_=_.concat(coinjs.numToBytes(this.ins[t].outpoint.index,4));var g=coinjs.numToBytes(this.ins[t].sequence,4),m=l;h=[];if(2!=i&&3!=i){for(y=0;y<this.outs.length;y++)h=(h=(h=h.concat(coinjs.numToBytes(this.outs[y].value,8))).concat(coinjs.numToVarInt(this.outs[y].script.buffer.length))).concat(this.outs[y].script.buffer);m=Crypto.SHA256(Crypto.SHA256(h,{asBytes:!0}),{asBytes:!0})}else 2==i&&t<this.outs.length&&(h=(h=(h=h.concat(coinjs.numToBytes(this.outs[t].value,8))).concat(coinjs.numToVarInt(this.outs[y].script.buffer.length))).concat(this.outs[t].script.buffer),m=Crypto.SHA256(Crypto.SHA256(h,{asBytes:!0}),{asBytes:!0}));var b=coinjs.numToBytes(this.lock_time,4),v=coinjs.numToBytes(i,4),w=[];w=(w=(w=(w=(w=(w=(w=(w=(w=(w=w.concat(p)).concat(d)).concat(f)).concat(_)).concat(o)).concat(c)).concat(g)).concat(m)).concat(b)).concat(v);var T=Crypto.SHA256(w,{asBytes:!0});return{result:1,hash:Crypto.util.bytesToHex(Crypto.SHA256(T,{asBytes:!0})),response:"hash generated"}},t.getPrevouts=function(){for(var t=[],e=0;e<this.ins.length;e++){var i=this.ins[e];t=(t=t.concat(Crypto.util.hexToBytes(i.outpoint.hash).reverse())).concat(coinjs.numToBytes(parseInt(i.outpoint.index),4))}return t},t.getSequences=function(){for(var t=[],e=0;e<this.ins.length;e++){var i=this.ins[e];t=t.concat(coinjs.numToBytes(parseInt(i.sequence),4))}return t},t.getOutputs=function(){for(var t=[],e=0;e<this.outs.length;e++){var i=this.outs[e];t=t.concat(coinjs.numToBytes(i.value,8));var r=i.script.buffer;t=(t=t.concat(coinjs.numToVarInt(r.length))).concat(r)}return t},t.getOutput=function(t){for(var e=[],i=0;i<this.outs.length;i++)if(i==t){var r=this.outs[i];e=e.concat(coinjs.numToBytes(r.value,8));var o=r.script.buffer;e=(e=e.concat(coinjs.numToVarInt(o.length))).concat(o)}return e},t.extractScriptKey=function(t){if(this.ins[t]){if(5==this.ins[t].script.chunks.length&&172==this.ins[t].script.chunks[4]&&coinjs.isArray(this.ins[t].script.chunks[2]))return{type:"scriptpubkey",signed:"false",signatures:0,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)};if(2==this.ins[t].script.chunks.length&&48==this.ins[t].script.chunks[0][0]&&5==this.ins[t].script.chunks[1].length&&177==this.ins[t].script.chunks[1][1])return{type:"hodl",signed:"true",signatures:1,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)};if(2==this.ins[t].script.chunks.length&&48==this.ins[t].script.chunks[0][0])return{type:"scriptpubkey",signed:"true",signatures:1,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)};if(5==this.ins[t].script.chunks.length&&177==this.ins[t].script.chunks[1])return{type:"hodl",signed:"false",signatures:0,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)};if(this.ins[t].script.chunks.length<=3&&this.ins[t].script.chunks.length>0&&22==this.ins[t].script.chunks[0].length&&0==this.ins[t].script.chunks[0][0]){var e=this.witness[t]&&2==this.witness[t].length?"true":"false";return{type:"segwit",signed:e,signatures:"true"==e?1:0,script:Crypto.util.bytesToHex(this.ins[t].script.chunks[0])}}return 0==this.ins[t].script.chunks[0]&&174==this.ins[t].script.chunks[this.ins[t].script.chunks.length-1][this.ins[t].script.chunks[this.ins[t].script.chunks.length-1].length-1]?{type:"multisig",signed:"true",signatures:this.ins[t].script.chunks.length-2,script:Crypto.util.bytesToHex(this.ins[t].script.chunks[this.ins[t].script.chunks.length-1])}:this.ins[t].script.chunks[0]>=80&&174==this.ins[t].script.chunks[this.ins[t].script.chunks.length-1]?{type:"multisig",signed:"false",signatures:0,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)}:0==this.ins[t].script.chunks.length?{type:"empty",signed:"false",signatures:0,script:""}:{type:"unknown",signed:"false",signatures:0,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)}}return!1},t.transactionSig=function(t,e,i,r){var o=i||1;64==coinjs.shf&&(o|=64);var a=r||Crypto.util.hexToBytes(this.transactionHash(t,o));if(a){var c=EllipticCurve.getSECCurveByName("secp256k1"),l=coinjs.wif2privkey(e),p=BigInteger.fromByteArrayUnsigned(Crypto.util.hexToBytes(l.privkey)),h=c.getN(),y=BigInteger.fromByteArrayUnsigned(a),d=0;do{var f=coinjs.deterministicK(e,a,d),_=c.getG().multiply(f).getX().toBigInteger().mod(h),g=f.modInverse(h).multiply(y.add(p.multiply(_))).mod(h);d++}while(_.compareTo(BigInteger.ZERO)<=0||g.compareTo(BigInteger.ZERO)<=0);var m=h.shiftRight(1);g.compareTo(m)>0&&(g=h.subtract(g));var b=function serializeSig(t,e){var i=t.toByteArraySigned(),r=e.toByteArraySigned(),o=[];return o.push(2),o.push(i.length),(o=o.concat(i)).push(2),o.push(r.length),(o=o.concat(r)).unshift(o.length),o.unshift(48),o}(_,g);return b.push(parseInt(o,10)),Crypto.util.bytesToHex(b)}return!1},t.serialize=function(){var t=[];t=t.concat(coinjs.numToBytes(parseInt(this.version),4)),this.witness.length>=1&&(t=t.concat([0,1])),coinjs.txExtraTimeField&&(t=t.concat(coinjs.numToBytes(parseInt(this.nTime),4))),t=t.concat(coinjs.numToVarInt(this.ins.length));for(var e=0;e<this.ins.length;e++){var i=this.ins[e];t=(t=t.concat(Crypto.util.hexToBytes(i.outpoint.hash).reverse())).concat(coinjs.numToBytes(parseInt(i.outpoint.index),4));var r=i.script.buffer;t=(t=(t=t.concat(coinjs.numToVarInt(r.length))).concat(r)).concat(coinjs.numToBytes(parseInt(i.sequence),4))}t=t.concat(coinjs.numToVarInt(this.outs.length));for(e=0;e<this.outs.length;e++){var o=this.outs[e];t=t.concat(coinjs.numToBytes(o.value,8));r=o.script.buffer;t=(t=t.concat(coinjs.numToVarInt(r.length))).concat(r)}if(this.witness.length>=1)for(e=0;e<this.witness.length;e++){t=t.concat(coinjs.numToVarInt(this.witness[e].length));for(var a=0;a<this.witness[e].length;a++)t=(t=t.concat(coinjs.numToVarInt(Crypto.util.hexToBytes(this.witness[e][a]).length))).concat(Crypto.util.hexToBytes(this.witness[e][a]))}return t=t.concat(coinjs.numToBytes(parseInt(this.lock_time),4)),Crypto.util.bytesToHex(t)},t.deserialize=function(t){"string"==typeof t&&(t=Crypto.util.hexToBytes(t));var e=0,i=!1,readAsInt=function(i){return 0==i?0:(e++,t[e-1]+256*readAsInt(i-1))},readVarInt=function(){return e++,t[e-1]<253?t[e-1]:readAsInt(t[e-1]-251)},readBytes=function(i){return e+=i,t.slice(e-i,e)},readVarString=function(){var t=readVarInt();return readBytes(t)},r=new coinjs.transaction;r.version=readAsInt(4),coinjs.txExtraTimeField&&(r.nTime=readAsInt(4)),0==t[e]&&1==t[e+1]&&(i=!0,r.witness=[],e+=2);for(var o=readVarInt(),a=0;a<o;a++)r.ins.push({outpoint:{hash:Crypto.util.bytesToHex(readBytes(32).reverse()),index:readAsInt(4)},script:coinjs.script(readVarString()),sequence:readAsInt(4)});var c=readVarInt();for(a=0;a<c;a++)r.outs.push({value:coinjs.bytesToNum(readBytes(8)),script:coinjs.script(readVarString())});if(1==i)for(a=0;a<o;++a)for(var l=readVarInt(),p=0;p<l;p++){var h=readVarInt();e+=h,coinjs.isArray(r.witness[a])||(r.witness[a]=[]),r.witness[a].push(Crypto.util.bytesToHex(t.slice(e-h,e)))}return r.lock_time=readAsInt(4),r},t.size=function(){return(this.serialize().length/2).toFixed(0)},t},coinjs.deterministicK=function(t,e,i){i=i||0;var r=coinjs.wif2privkey(t),o=Crypto.util.hexToBytes(r.privkey),a=EllipticCurve.getSECCurveByName("secp256k1").getN(),c=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],l=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];l=Crypto.HMAC(Crypto.SHA256,c.concat([0]).concat(o).concat(e),l,{asBytes:!0}),c=Crypto.HMAC(Crypto.SHA256,c,l,{asBytes:!0}),l=Crypto.HMAC(Crypto.SHA256,c.concat([1]).concat(o).concat(e),l,{asBytes:!0}),c=Crypto.HMAC(Crypto.SHA256,c,l,{asBytes:!0});var p=[];p=c=Crypto.HMAC(Crypto.SHA256,c,l,{asBytes:!0});for(var h=BigInteger.fromByteArrayUnsigned(p),y=0;h.compareTo(a)>=0||h.compareTo(BigInteger.ZERO)<=0||y<i;)l=Crypto.HMAC(Crypto.SHA256,c.concat([0]),l,{asBytes:!0}),c=Crypto.HMAC(Crypto.SHA256,c,l,{asBytes:!0}),p=c=Crypto.HMAC(Crypto.SHA256,c,l,{asBytes:!0}),h=BigInteger.fromByteArrayUnsigned(p),y++;return h},coinjs.countObject=function(t){var e,i=0;for(e in t)t.hasOwnProperty(e)&&i++;return i},coinjs.clone=function(t){if(null==t||"object"!=typeof t)return t;var e=new t.constructor;for(var i in t)t.hasOwnProperty(i)&&(e[i]=coinjs.clone(t[i]));return e},coinjs.numToBytes=function(t,e){return void 0===e&&(e=8),0==e?[]:-1==t?Crypto.util.hexToBytes("ffffffffffffffff"):[t%256].concat(coinjs.numToBytes(Math.floor(t/256),e-1))},coinjs.numToByteArray=function(t){return t<=256?[t]:[t%256].concat(coinjs.numToByteArray(Math.floor(t/256)))},coinjs.numToVarInt=function(t){return t<253?[t]:t<65536?[253].concat(coinjs.numToBytes(t,2)):t<4294967296?[254].concat(coinjs.numToBytes(t,4)):[255].concat(coinjs.numToBytes(t,8))},coinjs.bytesToNum=function(t){return 0==t.length?0:t[0]+256*coinjs.bytesToNum(t.slice(1))},coinjs.addressDecodeWithBase32Prefix=function(t,e){if(!t.startsWith(e+":"))return!1;const i=decodeBase32AsBytes(t.slice(e.length+1));if(0==i)return!1;const r=i,o={};return 0==i[0]?(o.type="standard",o.bytes=r.slice(1),o.version=[r[0]]):8==i[0]?(o.type="multisig",o.bytes=r.slice(1),o.version=[r[0]]):(o.type="other",o.bytes=r.slice(1),o.version=[r[0]]),o},coinjs.addressDecodeStd=function(t){const e=coinjs.base58decode(t),i=e.slice(0,e.length-4),r=e.slice(e.length-4);if(Crypto.SHA256(Crypto.SHA256(i,{asBytes:!0}),{asBytes:!0}).slice(0,4)+""==r+""){const t={};return coinjs.arrayEquals(i.slice(0,coinjs.pub.length),coinjs.pub)?(t.type="standard",t.bytes=i.slice(coinjs.pub.length),t.version=i.slice(0,coinjs.pub.length)):coinjs.arrayEquals(i.slice(0,coinjs.multisig.length),coinjs.multisig)?(t.type="multisig",t.bytes=i.slice(coinjs.multisig.length),t.version=i.slice(0,coinjs.multisig.length)):coinjs.arrayEquals(i.slice(0,coinjs.priv.length),coinjs.priv)?(t.type="wifkey",t.bytes=i.slice(coinjs.priv.length),t.version=i.slice(0,coinjs.priv.length)):(t.type="other",t.bytes=i.slice(1),t.version=[i[0]]),t}return!1},coinjs.addressDecode=function(t){try{return""!=coinjs.base32pref&&t.startsWith(coinjs.base32pref+":")?coinjs.addressDecodeWithBase32Prefix(t,coinjs.base32pref):coinjs.addressDecodeStd(t)}catch(e){return bech32rs=coinjs.bech32redeemscript(t),!!bech32rs&&{type:"bech32",redeemscript:bech32rs}}},coinjs.base58encode=function(t){for(var e="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",i=BigInteger.valueOf(58),r=BigInteger.fromByteArrayUnsigned(t),o=[];r.compareTo(i)>=0;){var a=r.mod(i);o.unshift(e[a.intValue()]),r=r.subtract(a).divide(i)}o.unshift(e[r.intValue()]);for(var c=0;c<t.length&&0==t[c];c++)o.unshift(e[0]);return o.join("")},coinjs.base58decode=function(t){for(var e=BigInteger.valueOf(58),i=BigInteger.valueOf(0),r=0,o=t.length-1;o>=0;o--){var a="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".indexOf(t[o]);if(a<0)throw"Invalid character";i=i.add(BigInteger.valueOf(a).multiply(e.pow(t.length-1-o))),"1"==t[o]?r++:r=0}for(var c=i.toByteArrayUnsigned();r-- >0;)c.unshift(0);return c},coinjs.privkey2wif=function(t){var e=Crypto.util.hexToBytes(t);1==coinjs.compressed&&e.push(1),e.unshift(...coinjs.priv);var i=Crypto.SHA256(Crypto.SHA256(e,{asBytes:!0}),{asBytes:!0}).slice(0,4);return coinjs.base58encode(e.concat(i))},coinjs.wif2privkey=function(t){var e=!1,i=coinjs.base58decode(t),r=i.slice(0,i.length-4);return(r=r.slice(1,r.length)).length>=33&&1==r[r.length-1]&&(r=r.slice(0,r.length-1),e=!0),{privkey:Crypto.util.bytesToHex(r),compressed:e}},coinjs.pubkeys2MultisigAddressWithBackup=function(t,e,i,r){var o=coinjs.script();0==i&&0==r?(o.writeOp(82),o.writeBytes(Crypto.util.hexToBytes(t)),o.writeBytes(Crypto.util.hexToBytes(e)),o.writeOp(82),o.writeOp(174)):(o.writeOp(99),o.writeOp(82),o.writeBytes(Crypto.util.hexToBytes(t)),o.writeBytes(Crypto.util.hexToBytes(e)),o.writeOp(82),o.writeOp(174),o.writeOp(103),o.writeOp(99),o.writeBytes(coinjs.numToByteArray(i)),o.writeOp(177),o.writeOp(117),o.writeBytes(Crypto.util.hexToBytes(t)),o.writeOp(172),o.writeOp(103),o.writeBytes(coinjs.numToByteArray(r)),o.writeOp(177),o.writeOp(117),o.writeBytes(Crypto.util.hexToBytes(e)),o.writeOp(172),o.writeOp(104),o.writeOp(104));let a=ripemd160(Crypto.SHA256(o.buffer,{asBytes:!0}),{asBytes:!0});if(""!=coinjs.base32pref){let t=8+(a.length-20)/4;a.unshift(t);let e=Crypto.util.bytesToHex(o.buffer);return{address:coinjs.base32pref+":"+encodeBytesToBase32(a),redeemScript:e}}a.unshift(...coinjs.multisig);let c=a;c=Crypto.SHA256(Crypto.SHA256(c,{asBytes:!0}),{asBytes:!0});let l=c.slice(0,4),p=Crypto.util.bytesToHex(o.buffer);return{address:coinjs.base58encode(a.concat(l)),redeemScript:p}},coinjs.pubkeydecompress=function(t){if("string"==typeof t&&t.match(/^[a-f0-9]+$/i)){var e=EllipticCurve.getSECCurveByName("secp256k1");try{var i=e.curve.decodePointHex(t),r=i.getX().toBigInteger(),o=i.getY().toBigInteger(),a=EllipticCurve.integerToBytes(r,32);return(a=a.concat(EllipticCurve.integerToBytes(o,32))).unshift(4),Crypto.util.bytesToHex(a)}catch(t){return!1}}return!1},coinjs.pubkey2address=function(t,e){var i=ripemd160(Crypto.SHA256(Crypto.util.hexToBytes(t),{asBytes:!0}));i.unshift(e||coinjs.pub);var r=Crypto.SHA256(Crypto.SHA256(i,{asBytes:!0}),{asBytes:!0}).slice(0,4);return coinjs.base58encode(i.concat(r))},coinjs.verifySignature=function(t,e,i){var r,o,a;if(coinjs.isArray(e)){var c=function parseSig(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var r=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:BigInteger.fromByteArrayUnsigned(i),s:BigInteger.fromByteArrayUnsigned(r)}}(e);r=c.r,o=c.s}else{if("object"!=typeof e||!e.r||!e.s)throw"Invalid value for signature";r=e.r,o=e.s}if(!coinjs.isArray(i))throw"Invalid format for pubkey value, must be byte array";var l=EllipticCurve.getSECCurveByName("secp256k1");a=EllipticCurve.PointFp.decodeFrom(l.getCurve(),i);var p=BigInteger.fromByteArrayUnsigned(t);return coinjs.verifySignatureRaw(p,r,o,a)},coinjs.verifySignatureRaw=function(t,e,i,r){var o=EllipticCurve.getSECCurveByName("secp256k1"),a=o.getN(),c=o.getG();if(e.compareTo(BigInteger.ONE)<0||e.compareTo(a)>=0)return!1;if(i.compareTo(BigInteger.ONE)<0||i.compareTo(a)>=0)return!1;var l=i.modInverse(a),p=t.multiply(l).mod(a),h=e.multiply(l).mod(a);return c.multiply(p).add(r.multiply(h)).getX().toBigInteger().mod(a).equals(e)},coinjs.hd=function(t){var e={parse:function(){var i=[];if("string"==typeof t){var r=coinjs.base58decode(t);if(82==r.length){var o=r.slice(78,82),a=Crypto.SHA256(Crypto.SHA256(r.slice(0,78),{asBytes:!0}),{asBytes:!0});o[0]==a[0]&&o[1]==a[1]&&o[2]==a[2]&&o[3]==a[3]&&(i=r.slice(0,78))}}if(i&&i.length>0){e.version=coinjs.uint(i.slice(0,4),4),e.depth=coinjs.uint(i.slice(4,5),1),e.parent_fingerprint=i.slice(5,9),e.child_index=coinjs.uint(i.slice(9,13),4),e.chain_code=i.slice(13,45),e.key_bytes=i.slice(45,78);var c=coinjs.compressed;if(coinjs.compressed=!0,0==e.key_bytes[0]){e.type="private";var l=e.key_bytes.slice(1,33),p=Crypto.util.bytesToHex(l),h=coinjs.newPubkey(p);e.keys={privkey:p,pubkey:h,address:coinjs.pubkey2address(h),wif:coinjs.privkey2wif(p)}}else if(2==e.key_bytes[0]||3==e.key_bytes[0]){e.type="public";var y=Crypto.util.bytesToHex(e.key_bytes);e.keys={pubkey:y,address:coinjs.pubkey2address(y)}}else e.type="invalid";e.keys_extended=e.extend(),coinjs.compressed=c}return e},extend:function(){return coinjs.hd().make({depth:1*this.depth+1,parent_fingerprint:this.parent_fingerprint,child_index:this.child_index,chain_code:this.chain_code,privkey:this.keys.privkey,pubkey:this.keys.pubkey})},derive_path:function(t){if("m"==t||"M"==t||"m'"==t||"M'"==t)return this;var e=t.split("/"),i=coinjs.clone(this);for(var r in e)if((0!=r||"m"==o)&&"remove"!=r){var o=e[r],a=o.length>1&&"'"==o[o.length-1],c=2147483647&parseInt(a?o.slice(0,o.length-1):o);a&&(c+=2147483648);var l=(i=i.derive(c)).keys_extended.privkey&&""!=i.keys_extended.privkey?i.keys_extended.privkey:i.keys_extended.pubkey;i=coinjs.hd(l)}return i},derive:function(t){t=t||0;var i,r,o,a,c=Crypto.util.hexToBytes(this.keys.pubkey).concat(coinjs.numToBytes(t,4).reverse()),l=new jsSHA(Crypto.util.bytesToHex(c),"HEX").getHMAC(Crypto.util.bytesToHex(e.chain_code),"HEX","SHA-512","HEX"),p=new BigInteger(l.slice(0,64),16),h=Crypto.util.hexToBytes(l.slice(64,128)),y=EllipticCurve.getSECCurveByName("secp256k1");y.getCurve();if((a=coinjs.clone(this)).chain_code=h,a.child_index=t,"private"==this.type)i=p.add(new BigInteger([0].concat(Crypto.util.hexToBytes(this.keys.privkey)))).mod(y.getN()),r=Crypto.util.bytesToHex(i.toByteArrayUnsigned()),o=coinjs.newPubkey(r),a.keys={privkey:r,pubkey:o,wif:coinjs.privkey2wif(r),address:coinjs.pubkey2address(o)};else if("public"==this.type){q=y.curve.decodePointHex(this.keys.pubkey);var d=y.getG().multiply(p).add(q),f=d.getX().toBigInteger(),_=d.getY().toBigInteger(),g=EllipticCurve.integerToBytes(f,32);_.isEven()?g.unshift(2):g.unshift(3),o=Crypto.util.bytesToHex(g),a.keys={pubkey:o,address:coinjs.pubkey2address(o)}}return a.parent_fingerprint=ripemd160(Crypto.SHA256(Crypto.util.hexToBytes(e.keys.pubkey),{asBytes:!0}),{asBytes:!0}).slice(0,4),a.keys_extended=a.extend(),a},master:function(t){var e=t?Crypto.SHA256(t):coinjs.newPrivkey(),i=new jsSHA(e,"HEX").getHMAC("Bitcoin seed","TEXT","SHA-512","HEX"),r=(Crypto.util.hexToBytes(i.slice(0,64)),Crypto.util.hexToBytes(i.slice(64,128)));return coinjs.hd().make({depth:0,parent_fingerprint:[0,0,0,0],child_index:0,chain_code:r,privkey:i.slice(0,64),pubkey:coinjs.newPubkey(i.slice(0,64))})},make:function(t){var e=[];e.push(1*t.depth),e=(e=(e=e.concat(t.parent_fingerprint)).concat(coinjs.numToBytes(t.child_index,4).reverse())).concat(t.chain_code);var i={};if(t.privkey){var r=coinjs.numToBytes(coinjs.hdkey.prv,4).reverse();(r=r.concat(e)).push(0),r=r.concat(Crypto.util.hexToBytes(t.privkey));var o=Crypto.SHA256(Crypto.SHA256(r,{asBytes:!0}),{asBytes:!0}).slice(0,4),a=r.concat(o);i.privkey=coinjs.base58encode(a)}if(t.pubkey){var c=coinjs.numToBytes(coinjs.hdkey.pub,4).reverse();c=(c=c.concat(e)).concat(Crypto.util.hexToBytes(t.pubkey));o=Crypto.SHA256(Crypto.SHA256(c,{asBytes:!0}),{asBytes:!0}).slice(0,4),a=c.concat(o);i.pubkey=coinjs.base58encode(a)}return i}};return e.parse()},coinjs.hdkey={prv:76066276,pub:76067358},coinjs.newPubkey=function(t){var e=BigInteger.fromByteArrayUnsigned(Crypto.util.hexToBytes(t)),i=EllipticCurve.getSECCurveByName("secp256k1").getG().multiply(e),r=i.getX().toBigInteger(),o=i.getY().toBigInteger(),a=EllipticCurve.integerToBytes(r,32);if((a=a.concat(EllipticCurve.integerToBytes(o,32))).unshift(4),1==coinjs.compressed){var c=EllipticCurve.integerToBytes(r,32);return o.isEven()?c.unshift(2):c.unshift(3),Crypto.util.bytesToHex(c)}return Crypto.util.bytesToHex(a)},coinjs.uint=function(t,e){if(t.length<e)throw new Error("not enough data");for(var i=0,r=0;r<e;r++)i*=256,i+=t[r];return i};var canary=0xdeadbeefcafe,j_lm=15715070==(16777215&canary);function BigInteger(t,e,i){if(!(this instanceof BigInteger))return new BigInteger(t,e,i);null!=t&&("number"==typeof t?this.fromNumber(t,e,i):null==e&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,e))}var proto=BigInteger.prototype;function nbi(){return new BigInteger(null)}function am1(t,e,i,r,o,a){for(;--a>=0;){var c=e*this[t++]+i[r]+o;o=Math.floor(c/67108864),i[r++]=67108863&c}return o}function am2(t,e,i,r,o,a){for(var c=32767&e,l=e>>15;--a>=0;){var p=32767&this[t],h=this[t++]>>15,y=l*p+h*c;o=((p=c*p+((32767&y)<<15)+i[r]+(1073741823&o))>>>30)+(y>>>15)+l*h+(o>>>30),i[r++]=1073741823&p}return o}function am3(t,e,i,r,o,a){for(var c=16383&e,l=e>>14;--a>=0;){var p=16383&this[t],h=this[t++]>>14,y=l*p+h*c;o=((p=c*p+((16383&y)<<14)+i[r]+o)>>28)+(y>>14)+l*h,i[r++]=268435455&p}return o}BigInteger.prototype.am=am1,dbits=26,BigInteger.prototype.DB=dbits,BigInteger.prototype.DM=(1<<dbits)-1;var DV=BigInteger.prototype.DV=1<<dbits,BI_FP=52;BigInteger.prototype.FV=Math.pow(2,BI_FP),BigInteger.prototype.F1=BI_FP-dbits,BigInteger.prototype.F2=2*dbits-BI_FP;var rr,vv,BI_RM="0123456789abcdefghijklmnopqrstuvwxyz",BI_RC=new Array;for(rr="0".charCodeAt(0),vv=0;vv<=9;++vv)BI_RC[rr++]=vv;for(rr="a".charCodeAt(0),vv=10;vv<36;++vv)BI_RC[rr++]=vv;for(rr="A".charCodeAt(0),vv=10;vv<36;++vv)BI_RC[rr++]=vv;function int2char(t){return BI_RM.charAt(t)}function intAt(t,e){var i=BI_RC[t.charCodeAt(e)];return null==i?-1:i}function bnpCopyTo(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s}function bnpFromInt(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+DV:this.t=0}function nbv(t){var e=nbi();return e.fromInt(t),e}function bnpFromString(t,e){var i,r=this;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void r.fromRadix(t,e);i=2}r.t=0,r.s=0;for(var o=t.length,a=!1,c=0;--o>=0;){var l=8==i?255&t[o]:intAt(t,o);l<0?"-"==t.charAt(o)&&(a=!0):(a=!1,0==c?r[r.t++]=l:c+i>r.DB?(r[r.t-1]|=(l&(1<<r.DB-c)-1)<<c,r[r.t++]=l>>r.DB-c):r[r.t-1]|=l<<c,(c+=i)>=r.DB&&(c-=r.DB))}8==i&&0!=(128&t[0])&&(r.s=-1,c>0&&(r[r.t-1]|=(1<<r.DB-c)-1<<c)),r.clamp(),a&&BigInteger.ZERO.subTo(r,r)}function bnpClamp(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t}function bnToString(t){var e,i=this;if(i.s<0)return"-"+i.negate().toString(t);if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return i.toRadix(t);e=2}var r,o=(1<<e)-1,a=!1,c="",l=i.t,p=i.DB-l*i.DB%e;if(l-- >0)for(p<i.DB&&(r=i[l]>>p)>0&&(a=!0,c=int2char(r));l>=0;)p<e?(r=(i[l]&(1<<p)-1)<<e-p,r|=i[--l]>>(p+=i.DB-e)):(r=i[l]>>(p-=e)&o,p<=0&&(p+=i.DB,--l)),r>0&&(a=!0),a&&(c+=int2char(r));return a?c:"0"}function bnNegate(){var t=nbi();return BigInteger.ZERO.subTo(this,t),t}function bnAbs(){return this.s<0?this.negate():this}function bnCompareTo(t){var e=this.s-t.s;if(0!=e)return e;var i=this.t;if(0!=(e=i-t.t))return this.s<0?-e:e;for(;--i>=0;)if(0!=(e=this[i]-t[i]))return e;return 0}function nbits(t){var e,i=1;return 0!=(e=t>>>16)&&(t=e,i+=16),0!=(e=t>>8)&&(t=e,i+=8),0!=(e=t>>4)&&(t=e,i+=4),0!=(e=t>>2)&&(t=e,i+=2),0!=(e=t>>1)&&(t=e,i+=1),i}function bnBitLength(){return this.t<=0?0:this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}function bnpDLShiftTo(t,e){var i;for(i=this.t-1;i>=0;--i)e[i+t]=this[i];for(i=t-1;i>=0;--i)e[i]=0;e.t=this.t+t,e.s=this.s}function bnpDRShiftTo(t,e){for(var i=t;i<this.t;++i)e[i-t]=this[i];e.t=Math.max(this.t-t,0),e.s=this.s}function bnpLShiftTo(t,e){var i,r=this,o=t%r.DB,a=r.DB-o,c=(1<<a)-1,l=Math.floor(t/r.DB),p=r.s<<o&r.DM;for(i=r.t-1;i>=0;--i)e[i+l+1]=r[i]>>a|p,p=(r[i]&c)<<o;for(i=l-1;i>=0;--i)e[i]=0;e[l]=p,e.t=r.t+l+1,e.s=r.s,e.clamp()}function bnpRShiftTo(t,e){var i=this;e.s=i.s;var r=Math.floor(t/i.DB);if(r>=i.t)e.t=0;else{var o=t%i.DB,a=i.DB-o,c=(1<<o)-1;e[0]=i[r]>>o;for(var l=r+1;l<i.t;++l)e[l-r-1]|=(i[l]&c)<<a,e[l-r]=i[l]>>o;o>0&&(e[i.t-r-1]|=(i.s&c)<<a),e.t=i.t-r,e.clamp()}}function bnpSubTo(t,e){for(var i=this,r=0,o=0,a=Math.min(t.t,i.t);r<a;)o+=i[r]-t[r],e[r++]=o&i.DM,o>>=i.DB;if(t.t<i.t){for(o-=t.s;r<i.t;)o+=i[r],e[r++]=o&i.DM,o>>=i.DB;o+=i.s}else{for(o+=i.s;r<t.t;)o-=t[r],e[r++]=o&i.DM,o>>=i.DB;o-=t.s}e.s=o<0?-1:0,o<-1?e[r++]=i.DV+o:o>0&&(e[r++]=o),e.t=r,e.clamp()}function bnpMultiplyTo(t,e){var i=this.abs(),r=t.abs(),o=i.t;for(e.t=o+r.t;--o>=0;)e[o]=0;for(o=0;o<r.t;++o)e[o+i.t]=i.am(0,r[o],e,o,0,i.t);e.s=0,e.clamp(),this.s!=t.s&&BigInteger.ZERO.subTo(e,e)}function bnpSquareTo(t){for(var e=this.abs(),i=t.t=2*e.t;--i>=0;)t[i]=0;for(i=0;i<e.t-1;++i){var r=e.am(i,e[i],t,2*i,0,1);(t[i+e.t]+=e.am(i+1,2*e[i],t,2*i+1,r,e.t-i-1))>=e.DV&&(t[i+e.t]-=e.DV,t[i+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(i,e[i],t,2*i,0,1)),t.s=0,t.clamp()}function bnpDivRemTo(t,e,i){var r=this,o=t.abs();if(!(o.t<=0)){var a=r.abs();if(a.t<o.t)return null!=e&&e.fromInt(0),void(null!=i&&r.copyTo(i));null==i&&(i=nbi());var c=nbi(),l=r.s,p=t.s,h=r.DB-nbits(o[o.t-1]);h>0?(o.lShiftTo(h,c),a.lShiftTo(h,i)):(o.copyTo(c),a.copyTo(i));var y=c.t,d=c[y-1];if(0!=d){var f=d*(1<<r.F1)+(y>1?c[y-2]>>r.F2:0),_=r.FV/f,g=(1<<r.F1)/f,m=1<<r.F2,b=i.t,v=b-y,w=null==e?nbi():e;for(c.dlShiftTo(v,w),i.compareTo(w)>=0&&(i[i.t++]=1,i.subTo(w,i)),BigInteger.ONE.dlShiftTo(y,w),w.subTo(c,c);c.t<y;)c[c.t++]=0;for(;--v>=0;){var T=i[--b]==d?r.DM:Math.floor(i[b]*_+(i[b-1]+m)*g);if((i[b]+=c.am(0,T,i,v,0,y))<T)for(c.dlShiftTo(v,w),i.subTo(w,i);i[b]<--T;)i.subTo(w,i)}null!=e&&(i.drShiftTo(y,e),l!=p&&BigInteger.ZERO.subTo(e,e)),i.t=y,i.clamp(),h>0&&i.rShiftTo(h,i),l<0&&BigInteger.ZERO.subTo(i,i)}}}function bnMod(t){var e=nbi();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(BigInteger.ZERO)>0&&t.subTo(e,e),e}function Classic(t){this.m=t}function cConvert(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t}function cRevert(t){return t}function cReduce(t){t.divRemTo(this.m,null,t)}function cMulTo(t,e,i){t.multiplyTo(e,i),this.reduce(i)}function cSqrTo(t,e){t.squareTo(e),this.reduce(e)}function bnpInvDigit(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e}function Montgomery(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}function montConvert(t){var e=nbi();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(BigInteger.ZERO)>0&&this.m.subTo(e,e),e}function montRevert(t){var e=nbi();return t.copyTo(e),this.reduce(e),e}function montReduce(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e<this.m.t;++e){var i=32767&t[e],r=i*this.mpl+((i*this.mph+(t[e]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[i=e+this.m.t]+=this.m.am(0,r,t,e,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)}function montSqrTo(t,e){t.squareTo(e),this.reduce(e)}function montMulTo(t,e,i){t.multiplyTo(e,i),this.reduce(i)}function bnpIsEven(){return 0==(this.t>0?1&this[0]:this.s)}function bnpExp(t,e){if(t>4294967295||t<1)return BigInteger.ONE;var i=nbi(),r=nbi(),o=e.convert(this),a=nbits(t)-1;for(o.copyTo(i);--a>=0;)if(e.sqrTo(i,r),(t&1<<a)>0)e.mulTo(r,o,i);else{var c=i;i=r,r=c}return e.revert(i)}function bnModPowInt(t,e){var i;return i=t<256||e.isEven()?new Classic(e):new Montgomery(e),this.exp(t,i)}function nbi(){return new BigInteger(null)}function bnClone(){var t=nbi();return this.copyTo(t),t}function bnIntValue(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function bnByteValue(){return 0==this.t?this.s:this[0]<<24>>24}function bnShortValue(){return 0==this.t?this.s:this[0]<<16>>16}function bnpChunkSize(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}function bnSigNum(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}function bnpToRadix(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var e=this.chunkSize(t),i=Math.pow(t,e),r=nbv(i),o=nbi(),a=nbi(),c="";for(this.divRemTo(r,o,a);o.signum()>0;)c=(i+a.intValue()).toString(t).substr(1)+c,o.divRemTo(r,o,a);return a.intValue().toString(t)+c}function bnpFromRadix(t,e){var i=this;i.fromInt(0),null==e&&(e=10);for(var r=i.chunkSize(e),o=Math.pow(e,r),a=!1,c=0,l=0,p=0;p<t.length;++p){var h=intAt(t,p);h<0?"-"==t.charAt(p)&&0==i.signum()&&(a=!0):(l=e*l+h,++c>=r&&(i.dMultiply(o),i.dAddOffset(l,0),c=0,l=0))}c>0&&(i.dMultiply(Math.pow(e,c)),i.dAddOffset(l,0)),a&&BigInteger.ZERO.subTo(i,i)}function bnpFromNumber(t,e,i){var r=this;if("number"==typeof e)if(t<2)r.fromInt(1);else for(r.fromNumber(t,i),r.testBit(t-1)||r.bitwiseTo(BigInteger.ONE.shiftLeft(t-1),op_or,r),r.isEven()&&r.dAddOffset(1,0);!r.isProbablePrime(e);)r.dAddOffset(2,0),r.bitLength()>t&&r.subTo(BigInteger.ONE.shiftLeft(t-1),r);else{var o=new Array,a=7&t;o.length=1+(t>>3),e.nextBytes(o),a>0?o[0]&=(1<<a)-1:o[0]=0,r.fromString(o,256)}}function bnToByteArray(){var t=this,e=t.t,i=new Array;i[0]=t.s;var r,o=t.DB-e*t.DB%8,a=0;if(e-- >0)for(o<t.DB&&(r=t[e]>>o)!=(t.s&t.DM)>>o&&(i[a++]=r|t.s<<t.DB-o);e>=0;)o<8?(r=(t[e]&(1<<o)-1)<<8-o,r|=t[--e]>>(o+=t.DB-8)):(r=t[e]>>(o-=8)&255,o<=0&&(o+=t.DB,--e)),0!=(128&r)&&(r|=-256),0===a&&(128&t.s)!=(128&r)&&++a,(a>0||r!=t.s)&&(i[a++]=r);return i}function bnEquals(t){return 0==this.compareTo(t)}function bnMin(t){return this.compareTo(t)<0?this:t}function bnMax(t){return this.compareTo(t)>0?this:t}function bnpBitwiseTo(t,e,i){var r,o,a=this,c=Math.min(t.t,a.t);for(r=0;r<c;++r)i[r]=e(a[r],t[r]);if(t.t<a.t){for(o=t.s&a.DM,r=c;r<a.t;++r)i[r]=e(a[r],o);i.t=a.t}else{for(o=a.s&a.DM,r=c;r<t.t;++r)i[r]=e(o,t[r]);i.t=t.t}i.s=e(a.s,t.s),i.clamp()}function op_and(t,e){return t&e}function bnAnd(t){var e=nbi();return this.bitwiseTo(t,op_and,e),e}function op_or(t,e){return t|e}function bnOr(t){var e=nbi();return this.bitwiseTo(t,op_or,e),e}function op_xor(t,e){return t^e}function bnXor(t){var e=nbi();return this.bitwiseTo(t,op_xor,e),e}function op_andnot(t,e){return t&~e}function bnAndNot(t){var e=nbi();return this.bitwiseTo(t,op_andnot,e),e}function bnNot(){for(var t=nbi(),e=0;e<this.t;++e)t[e]=this.DM&~this[e];return t.t=this.t,t.s=~this.s,t}function bnShiftLeft(t){var e=nbi();return t<0?this.rShiftTo(-t,e):this.lShiftTo(t,e),e}function bnShiftRight(t){var e=nbi();return t<0?this.lShiftTo(-t,e):this.rShiftTo(t,e),e}function lbit(t){if(0==t)return-1;var e=0;return 0==(65535&t)&&(t>>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function bnGetLowestSetBit(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+lbit(this[t]);return this.s<0?this.t*this.DB:-1}function cbit(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function bnBitCount(){for(var t=0,e=this.s&this.DM,i=0;i<this.t;++i)t+=cbit(this[i]^e);return t}function bnTestBit(t){var e=Math.floor(t/this.DB);return e>=this.t?0!=this.s:0!=(this[e]&1<<t%this.DB)}function bnpChangeBit(t,e){var i=BigInteger.ONE.shiftLeft(t);return this.bitwiseTo(i,e,i),i}function bnSetBit(t){return this.changeBit(t,op_or)}function bnClearBit(t){return this.changeBit(t,op_andnot)}function bnFlipBit(t){return this.changeBit(t,op_xor)}function bnpAddTo(t,e){for(var i=this,r=0,o=0,a=Math.min(t.t,i.t);r<a;)o+=i[r]+t[r],e[r++]=o&i.DM,o>>=i.DB;if(t.t<i.t){for(o+=t.s;r<i.t;)o+=i[r],e[r++]=o&i.DM,o>>=i.DB;o+=i.s}else{for(o+=i.s;r<t.t;)o+=t[r],e[r++]=o&i.DM,o>>=i.DB;o+=t.s}e.s=o<0?-1:0,o>0?e[r++]=o:o<-1&&(e[r++]=i.DV+o),e.t=r,e.clamp()}function bnAdd(t){var e=nbi();return this.addTo(t,e),e}function bnSubtract(t){var e=nbi();return this.subTo(t,e),e}function bnMultiply(t){var e=nbi();return this.multiplyTo(t,e),e}function bnSquare(){var t=nbi();return this.squareTo(t),t}function bnDivide(t){var e=nbi();return this.divRemTo(t,e,null),e}function bnRemainder(t){var e=nbi();return this.divRemTo(t,null,e),e}function bnDivideAndRemainder(t){var e=nbi(),i=nbi();return this.divRemTo(t,e,i),new Array(e,i)}function bnpDMultiply(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}function bnpDAddOffset(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}}function NullExp(){}function nNop(t){return t}function nMulTo(t,e,i){t.multiplyTo(e,i)}function nSqrTo(t,e){t.squareTo(e)}function bnPow(t){return this.exp(t,new NullExp)}function bnpMultiplyLowerTo(t,e,i){var r,o=Math.min(this.t+t.t,e);for(i.s=0,i.t=o;o>0;)i[--o]=0;for(r=i.t-this.t;o<r;++o)i[o+this.t]=this.am(0,t[o],i,o,0,this.t);for(r=Math.min(t.t,e);o<r;++o)this.am(0,t[o],i,o,0,e-o);i.clamp()}function bnpMultiplyUpperTo(t,e,i){--e;var r=i.t=this.t+t.t-e;for(i.s=0;--r>=0;)i[r]=0;for(r=Math.max(e-this.t,0);r<t.t;++r)i[this.t+r-e]=this.am(e-r,t[r],i,0,0,this.t+r-e);i.clamp(),i.drShiftTo(1,i)}function Barrett(t){this.r2=nbi(),this.q3=nbi(),BigInteger.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}function barrettConvert(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=nbi();return t.copyTo(e),this.reduce(e),e}function barrettRevert(t){return t}function barrettReduce(t){var e=this;for(t.drShiftTo(e.m.t-1,e.r2),t.t>e.m.t+1&&(t.t=e.m.t+1,t.clamp()),e.mu.multiplyUpperTo(e.r2,e.m.t+1,e.q3),e.m.multiplyLowerTo(e.q3,e.m.t+1,e.r2);t.compareTo(e.r2)<0;)t.dAddOffset(1,e.m.t+1);for(t.subTo(e.r2,t);t.compareTo(e.m)>=0;)t.subTo(e.m,t)}function barrettSqrTo(t,e){t.squareTo(e),this.reduce(e)}function barrettMulTo(t,e,i){t.multiplyTo(e,i),this.reduce(i)}function bnModPow(t,e){var i,r,o=t.bitLength(),a=nbv(1);if(o<=0)return a;i=o<18?1:o<48?3:o<144?4:o<768?5:6,r=o<8?new Classic(e):e.isEven()?new Barrett(e):new Montgomery(e);var c=new Array,l=3,p=i-1,h=(1<<i)-1;if(c[1]=r.convert(this),i>1){var y=nbi();for(r.sqrTo(c[1],y);l<=h;)c[l]=nbi(),r.mulTo(y,c[l-2],c[l]),l+=2}var d,f,_=t.t-1,g=!0,m=nbi();for(o=nbits(t[_])-1;_>=0;){for(o>=p?d=t[_]>>o-p&h:(d=(t[_]&(1<<o+1)-1)<<p-o,_>0&&(d|=t[_-1]>>this.DB+o-p)),l=i;0==(1&d);)d>>=1,--l;if((o-=l)<0&&(o+=this.DB,--_),g)c[d].copyTo(a),g=!1;else{for(;l>1;)r.sqrTo(a,m),r.sqrTo(m,a),l-=2;l>0?r.sqrTo(a,m):(f=a,a=m,m=f),r.mulTo(m,c[d],a)}for(;_>=0&&0==(t[_]&1<<o);)r.sqrTo(a,m),f=a,a=m,m=f,--o<0&&(o=this.DB-1,--_)}return r.revert(a)}function bnGCD(t){var e=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone();if(e.compareTo(i)<0){var r=e;e=i,i=r}var o=e.getLowestSetBit(),a=i.getLowestSetBit();if(a<0)return e;for(o<a&&(a=o),a>0&&(e.rShiftTo(a,e),i.rShiftTo(a,i));e.signum()>0;)(o=e.getLowestSetBit())>0&&e.rShiftTo(o,e),(o=i.getLowestSetBit())>0&&i.rShiftTo(o,i),e.compareTo(i)>=0?(e.subTo(i,e),e.rShiftTo(1,e)):(i.subTo(e,i),i.rShiftTo(1,i));return a>0&&i.lShiftTo(a,i),i}function bnpModInt(t){if(t<=0)return 0;var e=this.DV%t,i=this.s<0?t-1:0;if(this.t>0)if(0==e)i=this[0]%t;else for(var r=this.t-1;r>=0;--r)i=(e*i+this[r])%t;return i}function bnModInverse(t){var e=t.isEven();if(this.isEven()&&e||0==t.signum())return BigInteger.ZERO;for(var i=t.clone(),r=this.clone(),o=nbv(1),a=nbv(0),c=nbv(0),l=nbv(1);0!=i.signum();){for(;i.isEven();)i.rShiftTo(1,i),e?(o.isEven()&&a.isEven()||(o.addTo(this,o),a.subTo(t,a)),o.rShiftTo(1,o)):a.isEven()||a.subTo(t,a),a.rShiftTo(1,a);for(;r.isEven();)r.rShiftTo(1,r),e?(c.isEven()&&l.isEven()||(c.addTo(this,c),l.subTo(t,l)),c.rShiftTo(1,c)):l.isEven()||l.subTo(t,l),l.rShiftTo(1,l);i.compareTo(r)>=0?(i.subTo(r,i),e&&o.subTo(c,o),a.subTo(l,a)):(r.subTo(i,r),e&&c.subTo(o,c),l.subTo(a,l))}return 0!=r.compareTo(BigInteger.ONE)?BigInteger.ZERO:l.compareTo(t)>=0?l.subtract(t):l.signum()<0?(l.addTo(t,l),l.signum()<0?l.add(t):l):l}Classic.prototype.convert=cConvert,Classic.prototype.revert=cRevert,Classic.prototype.reduce=cReduce,Classic.prototype.mulTo=cMulTo,Classic.prototype.sqrTo=cSqrTo,Montgomery.prototype.convert=montConvert,Montgomery.prototype.revert=montRevert,Montgomery.prototype.reduce=montReduce,Montgomery.prototype.mulTo=montMulTo,Montgomery.prototype.sqrTo=montSqrTo,proto.copyTo=bnpCopyTo,proto.fromInt=bnpFromInt,proto.fromString=bnpFromString,proto.clamp=bnpClamp,proto.dlShiftTo=bnpDLShiftTo,proto.drShiftTo=bnpDRShiftTo,proto.lShiftTo=bnpLShiftTo,proto.rShiftTo=bnpRShiftTo,proto.subTo=bnpSubTo,proto.multiplyTo=bnpMultiplyTo,proto.squareTo=bnpSquareTo,proto.divRemTo=bnpDivRemTo,proto.invDigit=bnpInvDigit,proto.isEven=bnpIsEven,proto.exp=bnpExp,proto.toString=bnToString,proto.negate=bnNegate,proto.abs=bnAbs,proto.compareTo=bnCompareTo,proto.bitLength=bnBitLength,proto.mod=bnMod,proto.modPowInt=bnModPowInt,NullExp.prototype.convert=nNop,NullExp.prototype.revert=nNop,NullExp.prototype.mulTo=nMulTo,NullExp.prototype.sqrTo=nSqrTo,Barrett.prototype.convert=barrettConvert,Barrett.prototype.revert=barrettRevert,Barrett.prototype.reduce=barrettReduce,Barrett.prototype.mulTo=barrettMulTo,Barrett.prototype.sqrTo=barrettSqrTo,proto.chunkSize=bnpChunkSize,proto.toRadix=bnpToRadix,proto.fromRadix=bnpFromRadix,proto.fromNumber=bnpFromNumber,proto.bitwiseTo=bnpBitwiseTo,proto.changeBit=bnpChangeBit,proto.addTo=bnpAddTo,proto.dMultiply=bnpDMultiply,proto.dAddOffset=bnpDAddOffset,proto.multiplyLowerTo=bnpMultiplyLowerTo,proto.multiplyUpperTo=bnpMultiplyUpperTo,proto.modInt=bnpModInt,proto.clone=bnClone,proto.intValue=bnIntValue,proto.byteValue=bnByteValue,proto.shortValue=bnShortValue,proto.signum=bnSigNum,proto.toByteArray=bnToByteArray,proto.equals=bnEquals,proto.min=bnMin,proto.max=bnMax,proto.and=bnAnd,proto.or=bnOr,proto.xor=bnXor,proto.andNot=bnAndNot,proto.not=bnNot,proto.shiftLeft=bnShiftLeft,proto.shiftRight=bnShiftRight,proto.getLowestSetBit=bnGetLowestSetBit,proto.bitCount=bnBitCount,proto.testBit=bnTestBit,proto.setBit=bnSetBit,proto.clearBit=bnClearBit,proto.flipBit=bnFlipBit,proto.add=bnAdd,proto.subtract=bnSubtract,proto.multiply=bnMultiply,proto.divide=bnDivide,proto.remainder=bnRemainder,proto.divideAndRemainder=bnDivideAndRemainder,proto.modPow=bnModPow,proto.modInverse=bnModInverse,proto.pow=bnPow,proto.gcd=bnGCD,proto.square=bnSquare,BigInteger.ZERO=nbv(0),BigInteger.ONE=nbv(1),BigInteger.valueOf=nbv,BigInteger.fromByteArrayUnsigned=function(t){return t.length?128&t[0]?new BigInteger([0].concat(t)):new BigInteger(t):new BigInteger.valueOf(0)},BigInteger.fromByteArraySigned=function(t){return 128&t[0]?(t[0]&=127,BigInteger.fromByteArrayUnsigned(t).negate()):BigInteger.fromByteArrayUnsigned(t)},BigInteger.prototype.toByteArrayUnsigned=function(){var t=this.abs().toByteArray();if(!t.length)return t;0===t[0]&&(t=t.slice(1));for(var e=0;e<t.length;++e)t[e]=t[e]<0?t[e]+256:t[e];return t},BigInteger.prototype.toByteArraySigned=function(){var t=this.toByteArrayUnsigned(),e=this.s<0;return 128&t[0]?t.unshift(e?128:0):e&&(t[0]|=128),t},("undefined"==typeof Crypto||!Crypto.util)&&function(){var t,e=(t=window.Crypto={}).util={rotl:function(t,e){return t<<e|t>>>32-e},rotr:function(t,e){return t<<32-e|t>>>e},endian:function(t){if(t.constructor==Number)return 16711935&e.rotl(t,8)|4278255360&e.rotl(t,24);for(var i=0;i<t.length;i++)t[i]=e.endian(t[i]);return t},randomBytes:function(t){for(var e=[];t>0;t--)e.push(Math.floor(256*Math.random()));return e},bytesToWords:function(t){for(var e=[],i=0,r=0;i<t.length;i++,r+=8)e[r>>>5]|=(255&t[i])<<24-r%32;return e},wordsToBytes:function(t){for(var e=[],i=0;i<32*t.length;i+=8)e.push(t[i>>>5]>>>24-i%32&255);return e},bytesToHex:function(t){for(var e=[],i=0;i<t.length;i++)e.push((t[i]>>>4).toString(16)),e.push((15&t[i]).toString(16));return e.join("")},hexToBytes:function(t){for(var e=[],i=0;i<t.length;i+=2)e.push(parseInt(t.substr(i,2),16));return e},bytesToBase64:function(t){for(var e=[],i=0;i<t.length;i+=3)for(var r=t[i]<<16|t[i+1]<<8|t[i+2],o=0;o<4;o++)8*i+6*o<=8*t.length?e.push("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>>6*(3-o)&63)):e.push("=");return e.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var e=[],i=0,r=0;i<t.length;r=++i%4)0!=r&&e.push(("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(t.charAt(i-1))&Math.pow(2,-2*r+8)-1)<<2*r|"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(t.charAt(i))>>>6-2*r);return e}};(t=t.charenc={}).UTF8={stringToBytes:function(t){return i.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(i.bytesToString(t)))}};var i=t.Binary={stringToBytes:function(t){for(var e=[],i=0;i<t.length;i++)e.push(255&t.charCodeAt(i));return e},bytesToString:function(t){for(var e=[],i=0;i<t.length;i++)e.push(String.fromCharCode(t[i]));return e.join("")}}}(),function(){var t=Crypto,e=t.util,i=t.charenc,r=i.UTF8,o=i.Binary,a=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],c=t.SHA256=function(t,i){var r=e.wordsToBytes(c._sha256(t));return i&&i.asBytes?r:i&&i.asString?o.bytesToString(r):e.bytesToHex(r)};c._sha256=function(t){t.constructor==String&&(t=r.stringToBytes(t));var i,o,c,l,p,h,y,d,f,_,g,m=e.bytesToWords(t),b=8*t.length,v=(t=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],[]);for(m[b>>5]|=128<<24-b%32,m[15+(b+64>>9<<4)]=b,d=0;d<m.length;d+=16){for(b=t[0],i=t[1],o=t[2],c=t[3],l=t[4],p=t[5],h=t[6],y=t[7],f=0;f<64;f++){f<16?v[f]=m[f+d]:(_=v[f-15],g=v[f-2],v[f]=((_<<25|_>>>7)^(_<<14|_>>>18)^_>>>3)+(v[f-7]>>>0)+((g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10)+(v[f-16]>>>0)),g=b&i^b&o^i&o;var w=(b<<30|b>>>2)^(b<<19|b>>>13)^(b<<10|b>>>22);_=(y>>>0)+((l<<26|l>>>6)^(l<<21|l>>>11)^(l<<7|l>>>25))+(l&p^~l&h)+a[f]+(v[f]>>>0),y=h,h=p,p=l,l=c+_>>>0,c=o,o=i,i=b,b=_+(g=w+g)>>>0}t[0]+=b,t[1]+=i,t[2]+=o,t[3]+=c,t[4]+=l,t[5]+=p,t[6]+=h,t[7]+=y}return t},c._blocksize=16,c._digestsize=32}(),("undefined"==typeof Crypto||!Crypto.util)&&function(){var t,e=(t=window.Crypto={}).util={rotl:function(t,e){return t<<e|t>>>32-e},rotr:function(t,e){return t<<32-e|t>>>e},endian:function(t){if(t.constructor==Number)return 16711935&e.rotl(t,8)|4278255360&e.rotl(t,24);for(var i=0;i<t.length;i++)t[i]=e.endian(t[i]);return t},randomBytes:function(t){for(var e=[];t>0;t--)e.push(Math.floor(256*Math.random()));return e},bytesToWords:function(t){for(var e=[],i=0,r=0;i<t.length;i++,r+=8)e[r>>>5]|=(255&t[i])<<24-r%32;return e},wordsToBytes:function(t){for(var e=[],i=0;i<32*t.length;i+=8)e.push(t[i>>>5]>>>24-i%32&255);return e},bytesToHex:function(t){for(var e=[],i=0;i<t.length;i++)e.push((t[i]>>>4).toString(16)),e.push((15&t[i]).toString(16));return e.join("")},hexToBytes:function(t){for(var e=[],i=0;i<t.length;i+=2)e.push(parseInt(t.substr(i,2),16));return e},bytesToBase64:function(t){for(var e=[],i=0;i<t.length;i+=3)for(var r=t[i]<<16|t[i+1]<<8|t[i+2],o=0;o<4;o++)8*i+6*o<=8*t.length?e.push("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>>6*(3-o)&63)):e.push("=");return e.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var e=[],i=0,r=0;i<t.length;r=++i%4)0!=r&&e.push(("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(t.charAt(i-1))&Math.pow(2,-2*r+8)-1)<<2*r|"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(t.charAt(i))>>>6-2*r);return e}};(t=t.charenc={}).UTF8={stringToBytes:function(t){return i.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(i.bytesToString(t)))}};var i=t.Binary={stringToBytes:function(t){for(var e=[],i=0;i<t.length;i++)e.push(255&t.charCodeAt(i));return e},bytesToString:function(t){for(var e=[],i=0;i<t.length;i++)e.push(String.fromCharCode(t[i]));return e.join("")}}}(),function(){var t=Crypto,e=t.util,i=t.charenc,r=i.UTF8,o=i.Binary,a=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],c=t.SHA256=function(t,i){var r=e.wordsToBytes(c._sha256(t));return i&&i.asBytes?r:i&&i.asString?o.bytesToString(r):e.bytesToHex(r)};c._sha256=function(t){t.constructor==String&&(t=r.stringToBytes(t));var i,o,c,l,p,h,y,d,f,_,g,m=e.bytesToWords(t),b=8*t.length,v=(t=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],[]);for(m[b>>5]|=128<<24-b%32,m[15+(b+64>>9<<4)]=b,d=0;d<m.length;d+=16){for(b=t[0],i=t[1],o=t[2],c=t[3],l=t[4],p=t[5],h=t[6],y=t[7],f=0;f<64;f++){f<16?v[f]=m[f+d]:(_=v[f-15],g=v[f-2],v[f]=((_<<25|_>>>7)^(_<<14|_>>>18)^_>>>3)+(v[f-7]>>>0)+((g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10)+(v[f-16]>>>0)),g=b&i^b&o^i&o;var w=(b<<30|b>>>2)^(b<<19|b>>>13)^(b<<10|b>>>22);_=(y>>>0)+((l<<26|l>>>6)^(l<<21|l>>>11)^(l<<7|l>>>25))+(l&p^~l&h)+a[f]+(v[f]>>>0),y=h,h=p,p=l,l=c+_>>>0,c=o,o=i,i=b,b=_+(g=w+g)>>>0}t[0]+=b,t[1]+=i,t[2]+=o,t[3]+=c,t[4]+=l,t[5]+=p,t[6]+=h,t[7]+=y}return t},c._blocksize=16,c._digestsize=32}(),function(){var t=Crypto,e=t.util,i=t.charenc,r=i.UTF8,o=i.Binary;t.HMAC=function(t,i,a,c){i.constructor==String&&(i=r.stringToBytes(i)),a.constructor==String&&(a=r.stringToBytes(a)),a.length>4*t._blocksize&&(a=t(a,{asBytes:!0}));for(var l=a.slice(0),p=(a=a.slice(0),0);p<4*t._blocksize;p++)l[p]^=92,a[p]^=54;return t=t(l.concat(t(a.concat(i),{asBytes:!0})),{asBytes:!0}),c&&c.asBytes?t:c&&c.asString?o.bytesToString(t):e.bytesToHex(t)}}(),function(){var t=window.EllipticCurve=function(){};t.FieldElementFp=function(t,e){this.x=e,this.q=t},t.FieldElementFp.prototype.equals=function(t){return t==this||this.q.equals(t.q)&&this.x.equals(t.x)},t.FieldElementFp.prototype.toBigInteger=function(){return this.x},t.FieldElementFp.prototype.negate=function(){return new t.FieldElementFp(this.q,this.x.negate().mod(this.q))},t.FieldElementFp.prototype.add=function(e){return new t.FieldElementFp(this.q,this.x.add(e.toBigInteger()).mod(this.q))},t.FieldElementFp.prototype.subtract=function(e){return new t.FieldElementFp(this.q,this.x.subtract(e.toBigInteger()).mod(this.q))},t.FieldElementFp.prototype.multiply=function(e){return new t.FieldElementFp(this.q,this.x.multiply(e.toBigInteger()).mod(this.q))},t.FieldElementFp.prototype.square=function(){return new t.FieldElementFp(this.q,this.x.square().mod(this.q))},t.FieldElementFp.prototype.divide=function(e){return new t.FieldElementFp(this.q,this.x.multiply(e.toBigInteger().modInverse(this.q)).mod(this.q))},t.FieldElementFp.prototype.getByteLength=function(){return Math.floor((this.toBigInteger().bitLength()+7)/8)},t.FieldElementFp.prototype.sqrt=function(){if(!this.q.testBit(0))throw new Error("even value of q");if(this.q.testBit(1)){var e=new t.FieldElementFp(this.q,this.x.modPow(this.q.shiftRight(2).add(BigInteger.ONE),this.q));return e.square().equals(this)?e:null}var i=this.q.subtract(BigInteger.ONE),r=i.shiftRight(1);if(!this.x.modPow(r,this.q).equals(BigInteger.ONE))return null;var o,a,c=i.shiftRight(2).shiftLeft(1).add(BigInteger.ONE),l=this.x,p=l.shiftLeft(2).mod(this.q);do{var h,y=new SecureRandom;do{h=new BigInteger(this.q.bitLength(),y)}while(h.compareTo(this.q)>=0||!h.multiply(h).subtract(p).modPow(r,this.q).equals(i));var d=t.FieldElementFp.fastLucasSequence(this.q,h,l,c);if(o=d[0],(a=d[1]).multiply(a).mod(this.q).equals(p))return a.testBit(0)&&(a=a.add(this.q)),a=a.shiftRight(1),new t.FieldElementFp(this.q,a)}while(o.equals(BigInteger.ONE)||o.equals(i));return null},t.FieldElementFp.fastLucasSequence=function(t,e,i,r){for(var o=r.bitLength(),a=r.getLowestSetBit(),c=BigInteger.ONE,l=BigInteger.TWO,p=e,h=BigInteger.ONE,y=BigInteger.ONE,d=o-1;d>=a+1;--d)h=h.multiply(y).mod(t),r.testBit(d)?(y=h.multiply(i).mod(t),c=c.multiply(p).mod(t),l=p.multiply(l).subtract(e.multiply(h)).mod(t),p=p.multiply(p).subtract(y.shiftLeft(1)).mod(t)):(y=h,c=c.multiply(l).subtract(h).mod(t),p=p.multiply(l).subtract(e.multiply(h)).mod(t),l=l.multiply(l).subtract(h.shiftLeft(1)).mod(t));y=(h=h.multiply(y).mod(t)).multiply(i).mod(t),c=c.multiply(l).subtract(h).mod(t),l=p.multiply(l).subtract(e.multiply(h)).mod(t),h=h.multiply(y).mod(t);for(d=1;d<=a;++d)c=c.multiply(l).mod(t),l=l.multiply(l).subtract(h.shiftLeft(1)).mod(t),h=h.multiply(h).mod(t);return[c,l]},t.PointFp=function(t,e,i,r,o){this.curve=t,this.x=e,this.y=i,this.z=null==r?BigInteger.ONE:r,this.zinv=null,this.compressed=!!o},t.PointFp.prototype.getX=function(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var t=this.x.toBigInteger().multiply(this.zinv);return this.curve.reduce(t),this.curve.fromBigInteger(t)},t.PointFp.prototype.getY=function(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var t=this.y.toBigInteger().multiply(this.zinv);return this.curve.reduce(t),this.curve.fromBigInteger(t)},t.PointFp.prototype.equals=function(t){return t==this||(this.isInfinity()?t.isInfinity():t.isInfinity()?this.isInfinity():!!t.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(BigInteger.ZERO)&&t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(BigInteger.ZERO))},t.PointFp.prototype.isInfinity=function(){return null==this.x&&null==this.y||this.z.equals(BigInteger.ZERO)&&!this.y.toBigInteger().equals(BigInteger.ZERO)},t.PointFp.prototype.negate=function(){return new t.PointFp(this.curve,this.x,this.y.negate(),this.z)},t.PointFp.prototype.add=function(e){if(this.isInfinity())return e;if(e.isInfinity())return this;var i=e.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(e.z)).mod(this.curve.q),r=e.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(e.z)).mod(this.curve.q);if(BigInteger.ZERO.equals(r))return BigInteger.ZERO.equals(i)?this.twice():this.curve.getInfinity();var o=new BigInteger("3"),a=this.x.toBigInteger(),c=this.y.toBigInteger(),l=(e.x.toBigInteger(),e.y.toBigInteger(),r.square()),p=l.multiply(r),h=a.multiply(l),y=i.square().multiply(this.z),d=y.subtract(h.shiftLeft(1)).multiply(e.z).subtract(p).multiply(r).mod(this.curve.q),f=h.multiply(o).multiply(i).subtract(c.multiply(p)).subtract(y.multiply(i)).multiply(e.z).add(i.multiply(p)).mod(this.curve.q),_=p.multiply(this.z).multiply(e.z).mod(this.curve.q);return new t.PointFp(this.curve,this.curve.fromBigInteger(d),this.curve.fromBigInteger(f),_)},t.PointFp.prototype.twice=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var e=new BigInteger("3"),i=this.x.toBigInteger(),r=this.y.toBigInteger(),o=r.multiply(this.z),a=o.multiply(r).mod(this.curve.q),c=this.curve.a.toBigInteger(),l=i.square().multiply(e);BigInteger.ZERO.equals(c)||(l=l.add(this.z.square().multiply(c)));var p=(l=l.mod(this.curve.q)).square().subtract(i.shiftLeft(3).multiply(a)).shiftLeft(1).multiply(o).mod(this.curve.q),h=l.multiply(e).multiply(i).subtract(a.shiftLeft(1)).shiftLeft(2).multiply(a).subtract(l.square().multiply(l)).mod(this.curve.q),y=o.square().multiply(o).shiftLeft(3).mod(this.curve.q);return new t.PointFp(this.curve,this.curve.fromBigInteger(p),this.curve.fromBigInteger(h),y)},t.PointFp.prototype.multiply=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,i=t,r=i.multiply(new BigInteger("3")),o=this.negate(),a=this;for(e=r.bitLength()-2;e>0;--e){a=a.twice();var c=r.testBit(e);c!=i.testBit(e)&&(a=a.add(c?this:o))}return a},t.PointFp.prototype.multiplyTwo=function(t,e,i){var r;r=t.bitLength()>i.bitLength()?t.bitLength()-1:i.bitLength()-1;for(var o=this.curve.getInfinity(),a=this.add(e);r>=0;)o=o.twice(),t.testBit(r)?o=i.testBit(r)?o.add(a):o.add(this):i.testBit(r)&&(o=o.add(e)),--r;return o},t.PointFp.prototype.getEncoded=function(e){var i=this.getX().toBigInteger(),r=this.getY().toBigInteger(),o=t.integerToBytes(i,32);return e?r.isEven()?o.unshift(2):o.unshift(3):(o.unshift(4),o=o.concat(t.integerToBytes(r,32))),o},t.PointFp.decodeFrom=function(e,i){i[0];var r=i.length-1,o=i.slice(1,1+r/2),a=i.slice(1+r/2,1+r);o.unshift(0),a.unshift(0);var c=new BigInteger(o),l=new BigInteger(a);return new t.PointFp(e,e.fromBigInteger(c),e.fromBigInteger(l))},t.PointFp.prototype.add2D=function(e){if(this.isInfinity())return e;if(e.isInfinity())return this;if(this.x.equals(e.x))return this.y.equals(e.y)?this.twice():this.curve.getInfinity();var i=e.x.subtract(this.x),r=e.y.subtract(this.y).divide(i),o=r.square().subtract(this.x).subtract(e.x),a=r.multiply(this.x.subtract(o)).subtract(this.y);return new t.PointFp(this.curve,o,a)},t.PointFp.prototype.twice2D=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var e=this.curve.fromBigInteger(BigInteger.valueOf(2)),i=this.curve.fromBigInteger(BigInteger.valueOf(3)),r=this.x.square().multiply(i).add(this.curve.a).divide(this.y.multiply(e)),o=r.square().subtract(this.x.multiply(e)),a=r.multiply(this.x.subtract(o)).subtract(this.y);return new t.PointFp(this.curve,o,a)},t.PointFp.prototype.multiply2D=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,i=t,r=i.multiply(new BigInteger("3")),o=this.negate(),a=this;for(e=r.bitLength()-2;e>0;--e){a=a.twice();var c=r.testBit(e);c!=i.testBit(e)&&(a=a.add2D(c?this:o))}return a},t.PointFp.prototype.isOnCurve=function(){var t=this.getX().toBigInteger(),e=this.getY().toBigInteger(),i=this.curve.getA().toBigInteger(),r=this.curve.getB().toBigInteger(),o=this.curve.getQ(),a=e.multiply(e).mod(o),c=t.multiply(t).multiply(t).add(i.multiply(t)).add(r).mod(o);return a.equals(c)},t.PointFp.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"},t.PointFp.prototype.validate=function(){var t=this.curve.getQ();if(this.isInfinity())throw new Error("Point is at infinity.");var e=this.getX().toBigInteger(),i=this.getY().toBigInteger();if(e.compareTo(BigInteger.ONE)<0||e.compareTo(t.subtract(BigInteger.ONE))>0)throw new Error("x coordinate out of bounds");if(i.compareTo(BigInteger.ONE)<0||i.compareTo(t.subtract(BigInteger.ONE))>0)throw new Error("y coordinate out of bounds");if(!this.isOnCurve())throw new Error("Point is not on the curve.");if(this.multiply(t).isInfinity())throw new Error("Point is not a scalar multiple of G.");return!0},t.CurveFp=function(e,i,r){this.q=e,this.a=this.fromBigInteger(i),this.b=this.fromBigInteger(r),this.infinity=new t.PointFp(this,null,null),this.reducer=new Barrett(this.q)},t.CurveFp.prototype.getQ=function(){return this.q},t.CurveFp.prototype.getA=function(){return this.a},t.CurveFp.prototype.getB=function(){return this.b},t.CurveFp.prototype.equals=function(t){return t==this||this.q.equals(t.q)&&this.a.equals(t.a)&&this.b.equals(t.b)},t.CurveFp.prototype.getInfinity=function(){return this.infinity},t.CurveFp.prototype.fromBigInteger=function(e){return new t.FieldElementFp(this.q,e)},t.CurveFp.prototype.reduce=function(t){this.reducer.reduce(t)},t.CurveFp.prototype.decodePointHex=function(e){var i=parseInt(e.substr(0,2),16);switch(i){case 0:return this.infinity;case 2:case 3:var r=1&i,o=new BigInteger(c=e.substr(2,e.length-2),16);return this.decompressPoint(r,o);case 4:case 6:case 7:var a=(e.length-2)/2,c=e.substr(2,a),l=e.substr(a+2,a);return new t.PointFp(this,this.fromBigInteger(new BigInteger(c,16)),this.fromBigInteger(new BigInteger(l,16)));default:return null}},t.CurveFp.prototype.encodePointHex=function(t){if(t.isInfinity())return"00";var e=t.getX().toBigInteger().toString(16),i=t.getY().toBigInteger().toString(16),r=this.getQ().toString(16).length;for(r%2!=0&&r++;e.length<r;)e="0"+e;for(;i.length<r;)i="0"+i;return"04"+e+i},t.CurveFp.prototype.decompressPoint=function(e,i){var r=this.fromBigInteger(i),o=r.multiply(r.square().add(this.getA())).add(this.getB()).sqrt();if(null==o)throw new Error("Invalid point compression");var a=o.toBigInteger();return(a.testBit(0)?1:0)!=e&&(o=this.fromBigInteger(this.getQ().subtract(a))),new t.PointFp(this,r,o,null,!0)},t.fromHex=function(t){return new BigInteger(t,16)},t.integerToBytes=function(t,e){var i=t.toByteArrayUnsigned();if(e<i.length)i=i.slice(i.length-e);else for(;e>i.length;)i.unshift(0);return i},t.X9Parameters=function(t,e,i,r){this.curve=t,this.g=e,this.n=i,this.h=r},t.X9Parameters.prototype.getCurve=function(){return this.curve},t.X9Parameters.prototype.getG=function(){return this.g},t.X9Parameters.prototype.getN=function(){return this.n},t.X9Parameters.prototype.getH=function(){return this.h},t.secNamedCurves={secp256k1:function(){var e=t.fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F"),i=BigInteger.ZERO,r=t.fromHex("7"),o=t.fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"),a=BigInteger.ONE,c=new t.CurveFp(e,i,r),l=c.decodePointHex("0479BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8");return new t.X9Parameters(c,l,o,a)}},t.getSECCurveByName=function(e){return null==t.secNamedCurves[e]?null:t.secNamedCurves[e]()}}();var zl=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],zr=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],sl=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],sr=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11],hl=[0,1518500249,1859775393,2400959708,2840853838],hr=[1352829926,1548603684,1836072691,2053994217,0],bytesToWords=function(t){for(var e=[],i=0,r=0;i<t.length;i++,r+=8)e[r>>>5]|=t[i]<<24-r%32;return e},wordsToBytes=function(t){for(var e=[],i=0;i<32*t.length;i+=8)e.push(t[i>>>5]>>>24-i%32&255);return e},processBlock=function(t,e,i){for(var r=0;r<16;r++){var o=i+r,a=e[o];e[o]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}var c,l,p,h,y,d,f,_,g,m,b;d=c=t[0],f=l=t[1],_=p=t[2],g=h=t[3],m=y=t[4];for(r=0;r<80;r+=1)b=c+e[i+zl[r]]|0,b+=r<16?f1(l,p,h)+hl[0]:r<32?f2(l,p,h)+hl[1]:r<48?f3(l,p,h)+hl[2]:r<64?f4(l,p,h)+hl[3]:f5(l,p,h)+hl[4],b=(b=rotl(b|=0,sl[r]))+y|0,c=y,y=h,h=rotl(p,10),p=l,l=b,b=d+e[i+zr[r]]|0,b+=r<16?f5(f,_,g)+hr[0]:r<32?f4(f,_,g)+hr[1]:r<48?f3(f,_,g)+hr[2]:r<64?f2(f,_,g)+hr[3]:f1(f,_,g)+hr[4],b=(b=rotl(b|=0,sr[r]))+m|0,d=m,m=g,g=rotl(_,10),_=f,f=b;b=t[1]+p+g|0,t[1]=t[2]+h+m|0,t[2]=t[3]+y+d|0,t[3]=t[4]+c+f|0,t[4]=t[0]+l+_|0,t[0]=b};function f1(t,e,i){return t^e^i}function f2(t,e,i){return t&e|~t&i}function f3(t,e,i){return(t|~e)^i}function f4(t,e,i){return t&i|e&~i}function f5(t,e,i){return t^(e|~i)}function rotl(t,e){return t<<e|t>>>32-e}function ripemd160(t){var e=[1732584193,4023233417,2562383102,271733878,3285377520],i=bytesToWords(t),r=8*t.length,o=8*t.length;i[r>>>5]|=128<<24-r%32,i[14+(r+64>>>9<<4)]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8);for(var a=0;a<i.length;a+=16)processBlock(e,i,a);for(a=0;a<5;a++){var c=e[a];e[a]=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8)}return wordsToBytes(e)}!function(){function n(t){throw t}var t=null;function s(t,e){this.a=t,this.b=e}function u(t,e){var i,r=[],o=(1<<e)-1,a=t.length*e;for(i=0;i<a;i+=e)r[i>>>5]|=(t.charCodeAt(i/e)&o)<<32-e-i%32;return{value:r,binLen:a}}function x(t){var e,i,r=[],o=t.length;for(0!=o%2&&n("String of HEX type must be in byte increments"),e=0;e<o;e+=2)i=parseInt(t.substr(e,2),16),isNaN(i)&&n("String of HEX type contains invalid characters"),r[e>>>3]|=i<<24-e%8*4;return{value:r,binLen:4*o}}function B(t){var e,i,r,o,a,c=[],l=0;for(-1===t.search(/^[a-zA-Z0-9=+\/]+$/)&&n("Invalid character in base-64 string"),e=t.indexOf("="),t=t.replace(/\=/g,""),-1!==e&&e<t.length&&n("Invalid '=' found in base-64 string"),i=0;i<t.length;i+=4){for(a=t.substr(i,4),r=o=0;r<a.length;r+=1)o|=(e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(a[r]))<<18-6*r;for(r=0;r<a.length-1;r+=1)c[l>>2]|=(o>>>16-8*r&255)<<24-l%4*8,l+=1}return{value:c,binLen:8*l}}function E(t,e){var i,r,o="",a=4*t.length;for(i=0;i<a;i+=1)r=t[i>>>2]>>>8*(3-i%4),o+="0123456789abcdef".charAt(r>>>4&15)+"0123456789abcdef".charAt(15&r);return e.outputUpper?o.toUpperCase():o}function F(t,e){var i,r,o,a="",c=4*t.length;for(i=0;i<c;i+=3)for(o=(t[i>>>2]>>>8*(3-i%4)&255)<<16|(t[i+1>>>2]>>>8*(3-(i+1)%4)&255)<<8|t[i+2>>>2]>>>8*(3-(i+2)%4)&255,r=0;4>r;r+=1)a=8*i+6*r<=32*t.length?a+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(o>>>6*(3-r)&63):a+e.b64Pad;return a}function G(t){var e={outputUpper:!1,b64Pad:"="};try{t.hasOwnProperty("outputUpper")&&(e.outputUpper=t.outputUpper),t.hasOwnProperty("b64Pad")&&(e.b64Pad=t.b64Pad)}catch(t){}return"boolean"!=typeof e.outputUpper&&n("Invalid outputUpper formatting option"),"string"!=typeof e.b64Pad&&n("Invalid b64Pad formatting option"),e}function H(e,i){var r=t;r=new s(e.a,e.b);return 32>=i?new s(r.a>>>i|r.b<<32-i&4294967295,r.b>>>i|r.a<<32-i&4294967295):new s(r.b>>>i-32|r.a<<64-i&4294967295,r.a>>>i-32|r.b<<64-i&4294967295)}function I(t,e){return 32>=e?new s(t.a>>>e,t.b>>>e|t.a<<32-e&4294967295):new s(0,t.a>>>e-32)}function J(t,e,i){return new s(t.a&e.a^~t.a&i.a,t.b&e.b^~t.b&i.b)}function U(t,e,i){return new s(t.a&e.a^t.a&i.a^e.a&i.a,t.b&e.b^t.b&i.b^e.b&i.b)}function V(t){var e=H(t,28),i=H(t,34);return t=H(t,39),new s(e.a^i.a^t.a,e.b^i.b^t.b)}function W(t){var e=H(t,14),i=H(t,18);return t=H(t,41),new s(e.a^i.a^t.a,e.b^i.b^t.b)}function X(t){var e=H(t,1),i=H(t,8);return t=I(t,7),new s(e.a^i.a^t.a,e.b^i.b^t.b)}function Y(t){var e=H(t,19),i=H(t,61);return t=I(t,6),new s(e.a^i.a^t.a,e.b^i.b^t.b)}function Z(t,e){var i,r,o;return i=(65535&t.b)+(65535&e.b),o=(65535&(r=(t.b>>>16)+(e.b>>>16)+(i>>>16)))<<16|65535&i,i=(65535&t.a)+(65535&e.a)+(r>>>16),new s((65535&(r=(t.a>>>16)+(e.a>>>16)+(i>>>16)))<<16|65535&i,o)}function aa(t,e,i,r){var o,a,c;return o=(65535&t.b)+(65535&e.b)+(65535&i.b)+(65535&r.b),c=(65535&(a=(t.b>>>16)+(e.b>>>16)+(i.b>>>16)+(r.b>>>16)+(o>>>16)))<<16|65535&o,o=(65535&t.a)+(65535&e.a)+(65535&i.a)+(65535&r.a)+(a>>>16),new s((65535&(a=(t.a>>>16)+(e.a>>>16)+(i.a>>>16)+(r.a>>>16)+(o>>>16)))<<16|65535&o,c)}function ba(t,e,i,r,o){var a,c,l;return a=(65535&t.b)+(65535&e.b)+(65535&i.b)+(65535&r.b)+(65535&o.b),l=(65535&(c=(t.b>>>16)+(e.b>>>16)+(i.b>>>16)+(r.b>>>16)+(o.b>>>16)+(a>>>16)))<<16|65535&a,a=(65535&t.a)+(65535&e.a)+(65535&i.a)+(65535&r.a)+(65535&o.a)+(c>>>16),new s((65535&(c=(t.a>>>16)+(e.a>>>16)+(i.a>>>16)+(r.a>>>16)+(o.a>>>16)+(a>>>16)))<<16|65535&a,l)}function $(t,e,i){var r,o,a,c,l,p,h,y,d,f,_,g,m,b,v,w,T,k,C,S,j,A,q,M,N,D,O,R,P=[];for("SHA-384"===i||"SHA-512"===i?(_=80,r=31+(e+128>>>10<<5),b=32,v=2,w=Z,T=aa,k=ba,C=X,S=Y,j=V,A=W,M=U,q=J,D=[new(N=s)(1116352408,3609767458),new N(1899447441,602891725),new N(3049323471,3964484399),new N(3921009573,2173295548),new N(961987163,4081628472),new N(1508970993,3053834265),new N(2453635748,2937671579),new N(2870763221,3664609560),new N(3624381080,2734883394),new N(310598401,1164996542),new N(607225278,1323610764),new N(1426881987,3590304994),new N(1925078388,4068182383),new N(2162078206,991336113),new N(2614888103,633803317),new N(3248222580,3479774868),new N(3835390401,2666613458),new N(4022224774,944711139),new N(264347078,2341262773),new N(604807628,2007800933),new N(770255983,1495990901),new N(1249150122,1856431235),new N(1555081692,3175218132),new N(1996064986,2198950837),new N(2554220882,3999719339),new N(2821834349,766784016),new N(2952996808,2566594879),new N(3210313671,3203337956),new N(3336571891,1034457026),new N(3584528711,2466948901),new N(113926993,3758326383),new N(338241895,168717936),new N(666307205,1188179964),new N(773529912,1546045734),new N(1294757372,1522805485),new N(1396182291,2643833823),new N(1695183700,2343527390),new N(1986661051,1014477480),new N(2177026350,1206759142),new N(2456956037,344077627),new N(2730485921,1290863460),new N(2820302411,3158454273),new N(3259730800,3505952657),new N(3345764771,106217008),new N(3516065817,3606008344),new N(3600352804,1432725776),new N(4094571909,1467031594),new N(275423344,851169720),new N(430227734,3100823752),new N(506948616,1363258195),new N(659060556,3750685593),new N(883997877,3785050280),new N(958139571,3318307427),new N(1322822218,3812723403),new N(1537002063,2003034995),new N(1747873779,3602036899),new N(1955562222,1575990012),new N(2024104815,1125592928),new N(2227730452,2716904306),new N(2361852424,442776044),new N(2428436474,593698344),new N(2756734187,3733110249),new N(3204031479,2999351573),new N(3329325298,3815920427),new N(3391569614,3928383900),new N(3515267271,566280711),new N(3940187606,3454069534),new N(4118630271,4000239992),new N(116418474,1914138554),new N(174292421,2731055270),new N(289380356,3203993006),new N(460393269,320620315),new N(685471733,587496836),new N(852142971,1086792851),new N(1017036298,365543100),new N(1126000580,2618297676),new N(1288033470,3409855158),new N(1501505948,4234509866),new N(1607167915,987167468),new N(1816402316,1246189591)],f="SHA-384"===i?[new N(3418070365,3238371032),new N(1654270250,914150663),new N(2438529370,812702999),new N(355462360,4144912697),new N(1731405415,4290775857),new N(41048885895,1750603025),new N(3675008525,1694076839),new N(1203062813,3204075428)]:[new N(1779033703,4089235720),new N(3144134277,2227873595),new N(1013904242,4271175723),new N(2773480762,1595750129),new N(1359893119,2917565137),new N(2600822924,725511199),new N(528734635,4215389547),new N(1541459225,327033209)]):n("Unexpected error in SHA-2 implementation"),t[e>>>5]|=128<<24-e%32,t[r]=e,O=t.length,g=0;g<O;g+=b){for(e=f[0],r=f[1],o=f[2],a=f[3],c=f[4],l=f[5],p=f[6],h=f[7],m=0;m<_;m+=1)P[m]=16>m?new N(t[m*v+g],t[m*v+g+1]):T(S(P[m-2]),P[m-7],C(P[m-15]),P[m-16]),y=k(h,A(c),q(c,l,p),D[m],P[m]),d=w(j(e),M(e,r,o)),h=p,p=l,l=c,c=w(a,y),a=o,o=r,r=e,e=w(y,d);f[0]=w(e,f[0]),f[1]=w(r,f[1]),f[2]=w(o,f[2]),f[3]=w(a,f[3]),f[4]=w(c,f[4]),f[5]=w(l,f[5]),f[6]=w(p,f[6]),f[7]=w(h,f[7])}return"SHA-384"===i?R=[f[0].a,f[0].b,f[1].a,f[1].b,f[2].a,f[2].b,f[3].a,f[3].b,f[4].a,f[4].b,f[5].a,f[5].b]:"SHA-512"===i?R=[f[0].a,f[0].b,f[1].a,f[1].b,f[2].a,f[2].b,f[3].a,f[3].b,f[4].a,f[4].b,f[5].a,f[5].b,f[6].a,f[6].b,f[7].a,f[7].b]:n("Unexpected error in SHA-2 implementation"),R}window.jsSHA=function(e,i,r){var o=t,a=t,c=0,l=[0],p=0,h=t;8===(p=void 0!==r?r:8)||16===p||n("charSize must be 8 or 16"),"HEX"===i?(0!=e.length%2&&n("srcString of HEX type must be in byte increments"),h=x(e),c=h.binLen,l=h.value):"ASCII"===i||"TEXT"===i?(h=u(e,p),c=h.binLen,l=h.value):"B64"===i?(h=B(e),c=h.binLen,l=h.value):n("inputFormat must be HEX, TEXT, ASCII, or B64"),this.getHash=function(e,i,r){var p=t,h=l.slice(),y="";switch(i){case"HEX":p=E;break;case"B64":p=F;break;default:n("format must be HEX or B64")}return"SHA-384"===e?(t===o&&(o=$(h,c,e)),y=p(o,G(r))):"SHA-512"===e?(t===a&&(a=$(h,c,e)),y=p(a,G(r))):n("Chosen SHA variant is not supported"),y},this.getHMAC=function(e,i,r,o,a){var h,y,d,f,_,g=[],m=[],b=t;switch(o){case"HEX":h=E;break;case"B64":h=F;break;default:n("outputFormat must be HEX or B64")}for("SHA-384"===r?(d=128,_=384):"SHA-512"===r?(d=128,_=512):n("Chosen SHA variant is not supported"),"HEX"===i?(f=(b=x(e)).binLen,y=b.value):"ASCII"===i||"TEXT"===i?(f=(b=u(e,p)).binLen,y=b.value):"B64"===i?(f=(b=B(e)).binLen,y=b.value):n("inputFormat must be HEX, TEXT, ASCII, or B64"),e=8*d,i=d/4-1,d<f/8?(y=$(y,f,r))[i]&=4294967040:d>f/8&&(y[i]&=4294967040),d=0;d<=i;d+=1)g[d]=909522486^y[d],m[d]=1549556828^y[d];return h(r=$(m.concat($(g.concat(l),e+c,r)),e+_,r),G(a))}}}();var ychapi={};window.ychapi=ychapi,ychapi._data={buys:{},sells:{},trades:{},markets:{}},ychapi._nnum="",ychapi._sigi_num=30,ychapi._pagesize=15,ychapi._pubkey1="",ychapi._prvkey1="",ychapi._pubkey2="",ychapi._pubkey3="",ychapi._addresses={},ychapi._locktimes1={},ychapi._locktimes2={},ychapi._asset_extra_info={},ychapi._ready_init_data=!1,console.log("ychapi init1"),ychapi._zerotxid="0000000000000000000000000000000000000000000000000000000000000000",ychapi._evm_zeroaddr="0x0000000000000000000000000000000000000000",ychapi._start=null,ychapi._call_init=null,ychapi._call_login=null,ychapi._call_logout=null,ychapi._get_coin_names=null,ychapi._get_coin_info=null,ychapi._get_markets_groups_names=null,ychapi._get_market_group=null,ychapi._get_market_group_by_coinb=null,ychapi._get_markets_names_in_group=null,ychapi._get_markets_names=null,ychapi._get_market_info=null,ychapi._get_coin_balance=null,ychapi._get_coin_usd_rate=null,ychapi._get_coin_deposits=null,ychapi._get_coin_withdrawals=null,ychapi._get_coin_txouts=null,ychapi._call_register=null,ychapi._call_get_email_from_redeem=null,ychapi._call_get_registration_login=null,ychapi._call_confirm_registration_login=null,ychapi._call_confirm_registration_2fa=null,ychapi._get_user_login_keys_v1=null,ychapi._get_user_login_pubk=null,ychapi._has_user_login_prvk=null,ychapi._get_user_signing_pubk=null,ychapi._has_user_signing_prvk=null,ychapi._set_user_login_keys=null,ychapi._has_coin_holding_address=null,ychapi._get_coin_holding_address=null,ychapi._get_coin_user_locktime=null,ychapi._get_coin_server_locktime=null,ychapi._get_user_trading_discount=null,ychapi._get_buy_fee=null,ychapi._get_sell_fee=null,ychapi._get_user_buys=null,ychapi._get_user_sells=null,ychapi._get_user_trades=null,ychapi._get_market_buys=null,ychapi._get_market_sells=null,ychapi._get_market_trades=null,ychapi._call_buy=null,ychapi._call_sell=null,ychapi._call_buy_order_cancel=null,ychapi._call_sell_order_cancel=null,ychapi._call_get_chart_data=null,ychapi._validate_address=null,ychapi._get_withdraw_rawtx=null,ychapi._call_send=null,ychapi._create_withdraw=null,ychapi._update_withdraw=null,ychapi._set_withdraw_amount=null,ychapi._has_withdraw_inputs_stage=null,ychapi._call_withdraw_inputs_stage=null,ychapi._set_withdraw_inputs_for_debit=null,ychapi._call_withdraw=null,ychapi._call_withdraw_report_txid=null,ychapi._call_withdraw_cancel=null,ychapi._get_page_size=null,ychapi._get_evm_erc20_abi=null,ychapi._get_evm_vault7u_abi=null,ychapi._sign_evm_vault7u_user1=null,ychapi._get_user_account_id=null,ychapi._get_user_account_login=null,ychapi._get_user_account_twofa=null,ychapi._get_user_rewards=null,ychapi._get_user_referral_invitation_code=null,ychapi._get_user_referral_invitation_title=null,ychapi._is_logged_in=null,ychapi._has_profile=null,ychapi._jsonBNparse=function(t,e){return"string"==typeof e&&/^\-?\d+n$/.test(e)?BigInt(e.slice(0,-1)):e},ychapi._ajaxcall=function(t,e,i,r){try{const o=ychapi._get_cookie("jwt"),a=new XMLHttpRequest;a.open(t,e,!0),a.setRequestHeader("Authorization","Bearer "+o),a.onreadystatechange=function(){4===a.readyState&&(200===a.status?r(null,a.responseText):r(a.status+": "+a.statusText))},a.onerror=function(t){r(a.status+": "+a.statusText+" "+t)},"PUT"===t&&a.setRequestHeader("Content-Type","application/json"),a.send(i)}catch(t){r(t)}},ychapi._apicall=async function(t,e){if(null!=e&&null!=e||(e=0),"digest"in t){ychapi._init_coinjs();let e=ychapi._get_user_login_prvk();"uprvk"in t&&(e=t.uprvk);const i=ychapi._str2bytes(t.digest+ychapi._nnum),r=Crypto.SHA256(i,{asBytes:!0}),o=Crypto.SHA256(r,{asBytes:!0}),a=coinjs.privkey2wif(e),c=coinjs.signHash(a,o);t.data.usig=c}let i="PUT";return"calltype"in t&&(i=t.calltype),new Promise(((r,o)=>{ychapi._ajaxcall(i,ychapi._base_uri+t.uri,JSON.stringify(t.data,((t,e)=>"bigint"==typeof e?e.toString()+"n":e)),(function(a,c){if(a)o(a);else{const a=JSON.parse(c,ychapi._jsonBNparse);"GETRAW"==i||a.ok?r(a):0==a.ok&&"nnum"in a&&""!=a.nnum&&e<1?(ychapi._nnum=a.nnum,ychapi._apicall(t,e+1).then((function(t){r(t)})).catch((function(t){o(t)}))):o(a.error)}}))}))},ychapi._start=function(t,e){ychapi._base_uri=t,ychapi._ready_init_data=!1,ychapi._callbacks=e,ychapi._timer_reauth=setTimeout((function(){}),ychapi._timer_reauth_duration),ychapi._start_ws(),ychapi._call_init()},ychapi._do_apicall_reauth=function(){""!=ychapi._get_jwt_uid()&&ychapi._apicall({calltype:"GET",uri:"/u/reauth",data:{}}).then((function(t){document.cookie="jwt="+t.access+";SameSite=Strict",ychapi._do_ws_init()})).catch((function(t){ychapi._call_logout()}))},ychapi._get_user_login_pubk=function(){return ychapi._pubkey1},ychapi._has_user_login_prvk=function(){return null!=ychapi._prvkey1&&""!=ychapi._prvkey1},ychapi._get_user_login_prvk=function(){return ychapi._prvkey1},ychapi._get_user_signing_pubk=function(){return ychapi._pubkey1},ychapi._has_user_signing_prvk=function(){return null!=ychapi._prvkey1&&""!=ychapi._prvkey1},ychapi._get_user_signing_prvk=function(){return ychapi._prvkey1},ychapi._get_server_signing_pubk=function(){return ychapi._pubkey2},ychapi._get_credit_signing_pubk=function(){return ychapi._pubkey3},ychapi._set_user_login_keys=function(t,e){ychapi._pubkey1=t,ychapi._prvkey1=e},ychapi._get_coin_user_locktime=function(t){return null==ychapi._data.profile?0:t in ychapi._locktimes1?ychapi._locktimes1[t]:0},ychapi._get_coin_server_locktime=function(t){return null==ychapi._data.profile?0:t in ychapi._locktimes2?ychapi._locktimes2[t]:0},ychapi._cleanup_email=function(t){return t.startsWith("BM-")?t:t.toLowerCase()},ychapi._get_user_login_keys_v1=function(t,e){t=ychapi._cleanup_email(t);let i=Crypto.SHA256(Crypto.SHA256(t)+Crypto.SHA256(e));return[i,ychapi._priv_to_pub(i,!0)]},ychapi._priv_to_pub=function(t,e){let i=BigInteger.fromByteArrayUnsigned(Crypto.util.hexToBytes(t)),r=EllipticCurve.getSECCurveByName("secp256k1").getG().multiply(i),o=r.getX().toBigInteger(),a=r.getY().toBigInteger(),c=EllipticCurve.integerToBytes(o,32);if(c=c.concat(EllipticCurve.integerToBytes(a,32)),c.unshift(4),1==e){let t=EllipticCurve.integerToBytes(o,32);return a.isEven()?t.unshift(2):t.unshift(3),Crypto.util.bytesToHex(t)}return Crypto.util.bytesToHex(c)},ychapi._init_coinjs=function(t){coinjs.pub=[111],coinjs.priv=[239],coinjs.multisig=[196],coinjs.base32pref="",coinjs.compressed=!1,coinjs.txversion=1,coinjs.shf=0,coinjs.maxrbf=0,coinjs.txExtraTimeField=0;const e=ychapi._get_coin_info(t);if(null==e)return;if("peg_t1"!=e.type&&"txout_t1"!=e.type)return;const i=e.cfg;if(""==i.pub)return;const r=Crypto.util.hexToBytes(i.pub),o=Crypto.util.hexToBytes(i.prv),a=Crypto.util.hexToBytes(i.msig);coinjs.pub=r,coinjs.priv=o,coinjs.multisig=a,coinjs.base32pref=i.pref,coinjs.compressed=i.comp,coinjs.txversion=i.txver,coinjs.txExtraTimeField=i.txtime,coinjs.shf=i.shf,coinjs.maxrbf=i.maxrbf},ychapi._get_txouts_selection=function(t,e){let i=[],r=0n,o=0n,a=0n,c=0n;if(t.forEach((function(t,e){c+=t.free})),c<e)return console.log("ych_select_txouts, free",c," is less than amount",e),[i,-1,-1,-1];for(;r<e;){for(let c=0;c<t.length;c++){let l=t[c];if(c+1==t.length){i.push(l),l.selected=l.free,r+=l.free,o+=l.orders,a+=l.filled,t=t.slice(0,c);break}if(r+l.free>=e){i.push(l),l.selected=l.free,r+=l.free,o+=l.orders,a+=l.filled,t.splice(c,1);break}if(r>=e)break}if(r<e&&0==t.length)return console.log("ych_select_txouts, no fit",r,e),[i,-1,-1,-1]}return r>e&&i.length>0&&(txout=i[0],txout.selected-=r-e),[i,r,o,a]},ychapi._sign_txout_t1=function(t){if(""==t.txid)return[null,"Txid is empty"];if(t.nout<0)return[null,"Nout is not valid"];const e=t.coin,i=ychapi._get_coin_holding_address(e);if(""==i)return[null,"Not change address"];const r=ychapi._get_coin_info(e);if(null==r)return[null,"No coininfo"];const o=r.fee.minamount;if("txout_t1"!=r.type)return[null,"Not supported"];if(""==t.addr.rdsc)return[null,"Redeem script is not valid"];let a=t.free-t.selected,c=t.amount-a;c<o&&(c=o),c>t.amount&&(c=t.amount),a=t.amount-c;let l=t.amount-t.filled-a;l<o&&(l=o),l>t.amount-t.filled&&(l=t.amount-t.filled),a=t.amount-t.filled-l;let p={};if(p.txid=t.txid,p.nout=t.nout,p.amnt=t.amount,p.fill=t.filled,p.usea=t.selected,a>=o){const e=ychapi._sign_txout_t1_multipos(t,i,a);return 0==e.length?[null,"Fail to sign change"]:(p.sigv=a,p.siga=i,p.sigs=e,p.sigf="",[p,null])}const h=ychapi._sign_txout_t1_full(t);return 0==h.length?[null,"Fail to sign txout"]:(p.sigv=0n,p.siga="",p.sigs=[],p.sigf=h,[p,null])},ychapi._sign_txout_t1_hash=function(t,e,i){const r=t.coin;if(""==t.txid)return[null,"Txid is empty"];if(t.nout<0)return[null,"Nout is not valid"];const o=ychapi._get_coin_info(r);if(null==o)return[null,"No coininfo "+r];if("txout_t1"==o.type){if(""==t.addr.rdsc)return[null,"Redeem script is not valid"];ychapi._init_coinjs(r);const o=1;let a=coinjs.transaction();const c=coinjs.privkey2wif(ychapi._get_user_signing_prvk()),l=a.transactionSig(e,c,o,Crypto.util.hexToBytes(i)),p="",h=0n;return[{txid:t.txid,nout:t.nout,amnt:t.amount,fill:t.filled,usea:t.selected,sigf:l,sign:p,sigv:h},null]}return[null,"Not supported coin "+r]},ychapi._sign_txout_t1_full=function(t){const e=t.coin;if(""==t.txid)return console.log("Txid is empty"),[];if(t.nout<0)return console.log("Nout is not valid"),[];const i=ychapi._get_coin_info(e);if(null==i)return console.log("No coininfo",e),[];if("txout_t1"==i.type){if(""==t.addr.rdsc)return console.log("Redeem script is not valid"),[];ychapi._init_coinjs(e);let i=null;coinjs.maxrbf>0&&(i=coinjs.maxrbf-1);const r=130;let o=coinjs.transaction();o.addinput(t.txid,t.nout,Crypto.util.hexToBytes(t.addr.rdsc),i,t.amount);let a=o.transactionHash(0,r);if(2==t.addr.vers){a=o.transactionHashSegWitV0(0,t.addr.rdsc,r,Number(t.amount)).hash}const c=coinjs.privkey2wif(ychapi._get_user_signing_prvk());return o.transactionSig(0,c,r,Crypto.util.hexToBytes(a))}return console.log("Not supported",e),[]},ychapi._sign_txout_t1_multipos=function(t,e,i){const r=t.coin;if(""==t.txid)return console.log("Txid is empty"),[];if(t.nout<0)return console.log("Nout is not valid"),[];if(""==e)return console.log("Change address is empty"),[];if("bigint"!=typeof i)return console.log("Change need bigint",change),[];const o=ychapi._get_coin_info(r);if(null==o)return console.log("No coininfo",r),[];if("txout_t1"==o.type){if(""==t.addr.rdsc)return console.log("Redeem script is not valid"),[];ychapi._init_coinjs(r);let o=null;coinjs.maxrbf>0&&(o=coinjs.maxrbf-1);let a=coinjs.privkey2wif(ychapi._get_user_signing_prvk()),c=[];const l="e".repeat(64);for(let r=0;r<ychapi._sigi_num;r++){const p=131;let h=coinjs.transaction();for(let t=0;t<r;t++){const t=0,i=[];h.addinput(l,t,Crypto.util.hexToBytes(i),null,1n),h.addoutput(e,1n)}h.addinput(t.txid,t.nout,Crypto.util.hexToBytes(t.addr.rdsc),o,t.amount),h.addoutput(e,i);let y=h.transactionHash(r,p);if(2==t.addr.vers){y=h.transactionHashSegWitV0(r,t.addr.rdsc,p,Number(t.amount)).hash}const d=h.transactionSig(r,a,p,Crypto.util.hexToBytes(y));c.push(d)}return c}return console.log("Not supported",r),[]},ychapi._evm_erc20_abi=[{inputs:[{internalType:"string",name:"name_",type:"string"},{internalType:"string",name:"symbol_",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"}],name:"burn",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"}],name:"mint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}],ychapi._get_evm_erc20_abi=function(){return ychapi._evm_erc20_abi},ychapi._evm_vault7u_abi=[{inputs:[{internalType:"address",name:"tss_addr",type:"address"},{internalType:"address",name:"weth_addr",type:"address"},{internalType:"address[]",name:"add_coins",type:"address[]"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"coin",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"},{indexed:!0,internalType:"address",name:"user",type:"address"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"},{indexed:!1,internalType:"bytes32",name:"state",type:"bytes32"},{indexed:!1,internalType:"uint256",name:"irev",type:"uint256"},{indexed:!1,internalType:"uint256",name:"orev",type:"uint256"}],name:"In",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"coin",type:"address"},{indexed:!0,internalType:"address",name:"user",type:"address"},{indexed:!1,internalType:"bytes32",name:"state1",type:"bytes32"},{indexed:!1,internalType:"bytes32",name:"state2",type:"bytes32"},{indexed:!1,internalType:"uint256",name:"irev",type:"uint256"},{indexed:!1,internalType:"uint256",name:"orev",type:"uint256"},{indexed:!1,internalType:"uint256",name:"balance",type:"uint256"},{indexed:!1,internalType:"uint256",name:"sigr",type:"uint256"},{indexed:!1,internalType:"uint256",name:"sigv",type:"uint256"}],name:"Op",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"sender",type:"address"},{indexed:!0,internalType:"address",name:"user",type:"address"},{indexed:!1,internalType:"bool",name:"reg",type:"bool"}],name:"Reg",type:"event"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"}],name:"balances",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"coin",type:"address"},{components:[{internalType:"address",name:"user",type:"address"},{internalType:"uint256",name:"usea",type:"uint256"},{internalType:"bytes",name:"sig1",type:"bytes"},{internalType:"uint256",name:"sigr",type:"uint256"},{internalType:"uint256",name:"sigv",type:"uint256"}],internalType:"struct Vault7.Use[]",name:"uses",type:"tuple[]"},{components:[{internalType:"address",name:"user",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],internalType:"struct Vault7.Fill[]",name:"fills",type:"tuple[]"},{internalType:"bytes",name:"sig2",type:"bytes"},{internalType:"uint256",name:"tw",type:"uint256"}],name:"clearance1",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"coins",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"coin",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"address",name:"user",type:"address"},{internalType:"bytes",name:"sig1",type:"bytes"}],name:"deposit1",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"}],name:"irevs",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"addr",type:"address"},{internalType:"uint256",name:"min_amount",type:"uint256"},{internalType:"bool",name:"on",type:"bool"},{internalType:"bytes",name:"sig2",type:"bytes"},{internalType:"uint256",name:"tw",type:"uint256"}],name:"listCoin",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"locktime1",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"locktime2",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"minamount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"}],name:"orevs",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"user",type:"address"},{internalType:"bytes",name:"sig1",type:"bytes"},{internalType:"uint256",name:"tw",type:"uint256"}],name:"register1",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"user",type:"address"},{internalType:"bool",name:"on",type:"bool"},{internalType:"bytes",name:"sig2",type:"bytes"},{internalType:"uint256",name:"tw",type:"uint256"}],name:"register2",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"}],name:"sigr",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"},{internalType:"uint256",name:"",type:"uint256"}],name:"sigv",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"}],name:"states",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"totals",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"unregister1",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"user",type:"address"},{internalType:"bytes",name:"sig1",type:"bytes"}],name:"unregister2",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"users",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"ustate",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"coin",type:"address"},{internalType:"address",name:"user",type:"address"},{internalType:"address",name:"dest",type:"address"},{components:[{internalType:"address",name:"user",type:"address"},{internalType:"uint256",name:"usea",type:"uint256"},{internalType:"bytes",name:"sig1",type:"bytes"},{internalType:"uint256",name:"sigr",type:"uint256"},{internalType:"uint256",name:"sigv",type:"uint256"}],internalType:"struct Vault7.Use[]",name:"uses",type:"tuple[]"},{internalType:"bytes",name:"sig2",type:"bytes"},{internalType:"uint256",name:"tw",type:"uint256"}],name:"withdraw1",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"coin",type:"address"},{internalType:"address",name:"dest",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes",name:"sig2",type:"bytes"}],name:"withdraw3",outputs:[],stateMutability:"nonpayable",type:"function"},{stateMutability:"payable",type:"receive"}],ychapi._get_evm_vault7u_abi=function(){return ychapi._evm_vault7u_abi},ychapi._get_evm_vault7u_hash1=function(t,e,i,r,o){const a=_ethers.utils.arrayify(e),c=_ethers.utils.arrayify(t),l=_ethers.utils.arrayify(r),p=_ethers.utils.hexZeroPad(_ethers.utils.hexValue(i),32),h=_ethers.utils.arrayify(p),y=_ethers.utils.hexZeroPad(_ethers.utils.hexValue(o),32),d=_ethers.utils.arrayify(y),f=_ethers.utils.concat([c,a,h,l,d]),_=_ethers.utils.keccak256(f),g=_ethers.utils.arrayify(_),m=_ethers.utils.toUtf8Bytes("Ethereum Signed Message:\n32"),b=_ethers.utils.concat([m,g]);return _ethers.utils.keccak256(b)},ychapi._sign_evm_vault7u_user1=function(t,e,i,r,o){const a=ychapi._get_evm_vault7u_hash1(t,e,i,r,o),c=new _ethers.utils.SigningKey("0x"+ychapi._get_user_signing_prvk()).signDigest(a);return _ethers.utils.joinSignature(c)},ychapi._get_evm_vault7u_next_state1=function(t,e,i,r){const o=_ethers.utils.arrayify(t),a=_ethers.utils.arrayify(e),c=_ethers.utils.hexZeroPad(_ethers.utils.hexValue(i),32),l=_ethers.utils.arrayify(c),p=_ethers.utils.hexZeroPad(_ethers.utils.hexValue(r),32),h=_ethers.utils.arrayify(p),y=_ethers.utils.concat([o,a,l,h]);return _ethers.utils.keccak256(y)},ychapi._call_register=async function(t,e,i){return new Promise(((r,o)=>{const[a,c]=ychapi._get_user_login_keys_v1(t,e),l=i+t+c;ychapi._apicall({uri:"/u/register",uprvk:a,digest:l,data:{invt:i,user:t,upub:c}}).then((function(){r()})).catch((function(t){o(t)}))}))},ychapi._call_get_email_from_redeem=async function(t){return new Promise(((e,i)=>{ychapi._apicall({uri:"/u/redeem",data:{code:t}}).then((function(t){e(t.email)})).catch((function(t){i(t)}))}))},ychapi._call_get_registration_login=async function(t){return new Promise(((e,i)=>{ychapi._apicall({uri:"/u/confirmg",data:{code:t}}).then((function(t){e(t.login)})).catch((function(t){i(t)}))}))},ychapi._call_confirm_registration_login=async function(t,e,i){return new Promise(((r,o)=>{const[a,c]=ychapi._get_user_login_keys_v1(t,e),l=i+c;ychapi._apicall({uri:"/u/confirme",uprvk:a,digest:l,data:{code:i}}).then((function(t){r(t)})).catch((function(t){o(t)}))}))},ychapi._call_confirm_registration_2fa=async function(t,e,i,r){return new Promise(((o,a)=>{const[c,l]=ychapi._get_user_login_keys_v1(t,e),p=i+r+l;ychapi._apicall({uri:"/u/confirma",uprvk:c,digest:p,data:{code:i,auth:r}}).then((function(t){o(t)})).catch((function(t){a(t)}))}))},ychapi._ready_data=!1,ychapi._call_init=async function(){return new Promise(((t,e)=>{ychapi._apicall({calltype:"GET",uri:"/u/init",data:{}}).then((function(e){ychapi._on_data_call_init(e),ychapi._ready_init_data=!0,t(e)})).catch((function(t){ychapi._ready_init_data=!1,console.log("apicall err:",t),console.log("apicall err, logout"),ychapi._callbacks.on_sync_connection_error(t),e(t)}))}))},ychapi._call_login=async function(t,e,i){return new Promise(((r,o)=>{const[a,c]=ychapi._get_user_login_keys_v1(t,e),l=t+c+i;ychapi._apicall({uri:"/u/init",uprvk:a,digest:l,data:{user:t,upub:c,code:i}}).then((function(t){if(!t.access)return void o("notoken");if("unconfirmed"==t.access)return void o("unconfirmed");document.cookie="jwt="+t.access+";SameSite=Strict",window.location.hash="";""!=ychapi._get_jwt_uid()?(ychapi._set_user_login_keys(c,a),ychapi._on_data_call_init(t),r()):o("notoken")})).catch((function(t){o(t)}))}))},ychapi._call_logout=function(){document.cookie="jwt=; expires=Thu, 01 Jan 1970 00:00:01 GMT;SameSite=Strict",ychapi._set_user_login_keys("",""),ychapi._data.profile=void 0,ychapi._callbacks.on_sync_data_update("logout",{}),ychapi._do_ws_init()},ychapi._on_data_call_init=function(t){ychapi._data=t,ychapi._nnum=t.nnum;for(const t in ychapi._data.coininfos)ychapi._callbacks.on_sync_data_update("coininfo",ychapi._data.coininfos[t]);if(null!=t.profile){ychapi._pubkey1=t.profile.pubk1,ychapi._pubkey2=t.profile.pubk2,ychapi._pubkey3=t.profile.pubk3;t.profile.assets.forEach((function(t){const e=t.coin;ychapi._addresses[e]=t.address,ychapi._locktimes1[e]=t.locktime1,ychapi._locktimes2[e]=t.locktime2,null!=t.extra&&(ychapi._asset_extra_info[e]=t.extra)})),ychapi._callbacks.on_sync_data_update("login",{})}else ychapi._call_logout();ychapi._ready_data=!0,ychapi._callbacks.on_sync_data_init(),ychapi._do_ws_init()},ychapi._get_coin_names=function(){return ychapi._data.coins},ychapi._get_coin_info=function(t){return t in ychapi._data.coininfos?ychapi._data.coininfos[t]:null},ychapi._get_coin_balance=function(t){return null==ychapi._data.profile?null:t in ychapi._data.profile.balances?ychapi._data.profile.balances[t]:null},ychapi._get_coin_usd_rate=function(t){const e=ychapi._get_coin_info(t);return null==e?0:e.ext.priceext},ychapi._get_coin_deposits=function(t){return null==ychapi._data.profile?[]:t in ychapi._data.profile.deposits?ychapi._data.profile.deposits[t]:[]},ychapi._get_coin_withdrawals=function(t){return null==ychapi._data.profile?[]:t in ychapi._data.profile.withdraws?ychapi._data.profile.withdraws[t]:[]},ychapi._get_coin_txouts=function(t){if(null==ychapi._data.profile)return[];if(!(t in ychapi._data.profile.txouts))return[];const e=ychapi._data.profile.txouts[t];return JSON.parse(JSON.stringify(e,((t,e)=>"bigint"==typeof e?e.toString()+"n":e)),ychapi._jsonBNparse)},ychapi._get_markets_groups_names=function(){let t=[];return ychapi._data.groups.forEach((function(e,i){t.push(e.name)})),t},ychapi._get_market_group=function(t){for(let e in ychapi._data.groups){const i=ychapi._data.groups[e];if(i.name==t)return i}return null},ychapi._get_market_group_by_coinb=function(t){for(let e in ychapi._data.groups){const i=ychapi._data.groups[e];if(i.coinb==t)return i}return null},ychapi._get_markets_names_in_group=function(t){const e=ychapi._get_market_group(t);if(null==e)return[];let i=[];for(let t in ychapi._data.markets)i.push(ychapi._data.markets[t]);i.sort((function(t,e){return Number(t.index-e.index)}));let r=[];return i.forEach((function(t,i){t.coinb==e.coinb&&r.push(t.name)})),r},ychapi._get_markets_names=function(){let t=[];for(let e in ychapi._data.markets)t.push(ychapi._data.markets[e]);t.sort((function(t,e){return Number(t.index-e.index)}));let e=[];return t.forEach((function(t,i){e.push(t.name)})),e},ychapi._get_market_info=function(t){return t in ychapi._data.markets?ychapi._data.markets[t]:null},ychapi._get_user_account_id=function(){return null==ychapi._data.profile?"":ychapi._data.profile.uidx},ychapi._get_user_account_login=function(){return null==ychapi._data.profile?"":ychapi._data.profile.user},ychapi._get_user_account_twofa=function(){return null!=ychapi._data.profile&&ychapi._data.profile.twofa},ychapi._get_user_trading_discount=function(){return null==ychapi._data.profile?0:ychapi._data.profile.discount},ychapi._get_user_rewards=function(t){return null==ychapi._data.profile?0n:t in ychapi._data.profile.rewards?ychapi._data.profile.rewards[t]:0n},ychapi._get_user_referral_invitation_code=function(){return null==ychapi._data.profile?"":ychapi._data.profile.invt},ychapi._get_user_referral_invitation_title=function(){return null==ychapi._data.profile?"":ychapi._data.profile.title},ychapi._get_user_trades=function(t){return null==ychapi._data.profile||null==ychapi._data.profile.trades?[]:t in ychapi._data.profile.trades?ychapi._data.profile.trades[t]:[]},ychapi._get_user_buys=function(t){return null==ychapi._data.profile||null==ychapi._data.profile.buys?[]:t in ychapi._data.profile.buys?ychapi._data.profile.buys[t]:[]},ychapi._get_user_sells=function(t){return null==ychapi._data.profile||null==ychapi._data.profile.sells?[]:t in ychapi._data.profile.sells?ychapi._data.profile.sells[t]:[]},ychapi._get_market_trades=function(t){return null==ychapi._data.trades?[]:t in ychapi._data.trades?ychapi._data.trades[t]:[]},ychapi._get_market_buys=function(t){return null==ychapi._data.buys?[]:t in ychapi._data.buys?ychapi._data.buys[t]:[]},ychapi._get_market_sells=function(t){return null==ychapi._data.sells?[]:t in ychapi._data.sells?ychapi._data.sells[t]:[]},ychapi._get_buy_fee=function(t,e,i){const r=ychapi._get_user_trading_discount(),o=ychapi._get_coin_info(i).fee.buyfee*(100-r)/100;if(null==ychapi._data.markets)return o;if(!t in ychapi._data.markets)return o;const a=ychapi._data.markets[t];return a.fee.over?a.fee.buyfee:o},ychapi._get_sell_fee=function(t,e,i){const r=ychapi._get_user_trading_discount(),o=ychapi._get_coin_info(e).fee.sellfee*(100-r)/100;if(null==ychapi._data.markets)return o;if(!t in ychapi._data.markets)return o;const a=ychapi._data.markets[t];return a.fee.over?a.fee.sellfee:o},ychapi._is_logged_in=function(){const t=ychapi._get_cookie("jwt").split(".");if(3==t.length){const e=t[1].replace("-","+").replace("_","/");if("uid"in JSON.parse(window.atob(e)))return!0}return!1},ychapi._has_profile=function(){return null!=ychapi._data.profile&&null!=ychapi._data.profile},ychapi._call_send=function(t,e,i,r){return new Promise(((o,a)=>{if(!ychapi._has_user_login_prvk())return void a("no login key to sign");if(""==ychapi._get_coin_holding_address(t))return void a("Not available the change address");const c=ychapi._get_coin_info(t),l=c.fee.sendfee;if(BigInt(Math.floor(.5+Number(i)*l))!=r)return void a("Fee calculation error");const p=i+r;let h=0n,y=p;const d=ychapi._get_coin_balance(t);if(p>d.free)return void a("Not enough coins");if(d.debit>0){let t=d.debit-d.ordersindebit;if(t<0)return void a("Error debt usage is negative");t>=p?(h=p,y=0n):t>0&&(h=t,y=p-t)}let f=[];if(y>0){console.log("total_via_txouts",y);let e=ychapi._get_coin_txouts(t);ychapi._init_coinjs(t);const i=e.filter((t=>350==t.state||400==t.state||800==t.state));if(e=e.filter((t=>400==t.state)),e.sort((function(t,e){return Number(t.free-e.free)})),"txout_t1"==c.type){const[t,i,r,o]=ychapi._get_txouts_selection(e,y);if(i<0n||i<y)return void a("send: not enough available coins in txouts to use "+y);console.log("selected txouts:",t,i,r,o);for(let e=0;e<t.length;e++){const i=t[e],[r,o]=ychapi._sign_txout_t1(i);if(null!=o)return void a(o);f.push(r)}}if("evm_t1"==c.type||"erc20_t1"==c.type){const e=c.cfg.unit,r=y;for(let o=0;o<i.length;o++){const a=i[o],c="0x"+a.txid,l=a.orders+a.filled+r,p=l*e,h=[ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(t),c,p,ychapi._evm_zeroaddr,a.nout+1)];let y={};y.txid=a.txid,y.nout=a.nout,y.amnt=a.amount,y.fill=a.filled,y.usea=r,y.sigf="",y.sigv=l,y.sigs=h,f.push(y)}}}let _="";f.forEach((function(t,e){_+=t.txid+":"+t.nout,_+=t.fill.toString(),_+=t.usea.toString()}));const g=t+e+i.toString()+r.toString()+h.toString()+_+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/send",digest:g,data:{coin:t,addr:e,amount:i,fee:r,usedebit:h,usetxouts:f}}).then((function(){o()})).catch((function(t){a(t)}))}))},ychapi._call_buy=async function(t,e,i,r,o,a,c){return new Promise(((l,p)=>{if(!ychapi._has_user_login_prvk())return void p("no login key to sign");if(""==ychapi._get_coin_holding_address(i))return void p("not available the change address");const h=ychapi._get_coin_info(i),y=ychapi._get_buy_fee(t,e,i);if(o*r/BigInt(1e8)!=a)return void p("amountb calculation error");if(BigInt(Math.floor(.5+Number(a)*y))!=c)return void p("feeb calculation error");const d=a+c,f=ychapi._get_coin_balance(i);let _=0n,g=d;if(f.debit>0){let t=f.debit-f.ordersindebit;if(t<0)return void p("error debt usage is negative");t>=d?(_=d,g=0):t>0&&(_=t,g=d-t)}let m=[];if(g>0){let t=ychapi._get_coin_txouts(i);ychapi._init_coinjs(i);const e=t.filter((t=>350==t.state||400==t.state||800==t.state));if(t=t.filter((t=>400==t.state)),t.sort((function(t,e){return Number(t.free-e.free)})),"txout_t1"==h.type){const[e,i]=ychapi._get_txouts_selection(t,g);if(i<0||i<g)return void p("not enough available coins in txouts to trade "+g);for(let t=0;t<e.length;t++){const i=e[t],[r,o]=ychapi._sign_txout_t1(i);if(null!=o)return void p(o);m.push(r)}}if("evm_t1"==h.type||"erc20_t1"==h.type){const t=h.cfg.unit,r=g;for(let o=0;o<e.length;o++){const a=e[o],c="0x"+a.txid,l=a.orders+a.filled+r,p=l*t,h=[ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(i),c,p,ychapi._evm_zeroaddr,a.nout+1)],y={txid:a.txid,nout:a.nout,amnt:a.amount,fill:a.filled,usea:r,sigf:"",sigv:l,sigs:h};m.push(y)}}}let b="";m.forEach((function(t){b+=t.txid+":"+t.nout,b+=t.fill.toString(),b+=t.usea.toString()}));const v=e+i+r.toString()+o.toString()+a.toString()+"0"+c.toString()+_.toString()+b+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/buy",digest:v,data:{coina:e,coinb:i,price:r,amounta:o,amountb:a,feea:0n,feeb:c,usedebit:_,usetxouts:m}}).then((function(t){l(t)})).catch((function(t){p(t)}))}))},ychapi._call_buy_order_cancel=async function(t,e,i){return new Promise(((r,o)=>{const a=t+e+i.toString()+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/nobuy",digest:a,data:{coina:t,coinb:e,index:i}}).then((function(){r()})).catch((function(t){o(t)}))}))},ychapi._call_sell=async function(t,e,i,r,o,a,c){return new Promise(((l,p)=>{if(!ychapi._has_user_login_prvk())return void p("no login key to sign");if(""==ychapi._get_coin_holding_address(e))return void p("not available the change address");const h=ychapi._get_coin_info(e),y=ychapi._get_sell_fee(t,e,i);if(o*r/BigInt(1e8)!=a)return void p("amountb calculation error");if(BigInt(Math.floor(.5+Number(o)*y))!=c)return void p("feea calculation error");const d=o+c,f=ychapi._get_coin_balance(e);let _=0n,g=d;if(f.debit>0){let t=f.debit-f.ordersindebit;if(t<0)return void p("error debt usage is negative");t>=d?(_=d,g=0n):t>0&&(_=t,g=d-t)}let m=[];if(g>0){let t=ychapi._get_coin_txouts(e);ychapi._init_coinjs(e);const i=t.filter((t=>350==t.state||400==t.state||800==t.state));if(t=t.filter((t=>400==t.state)),t.sort((function(t,e){return Number(t.free-e.free)})),"txout_t1"==h.type){const[e,i,r,o]=ychapi._get_txouts_selection(t,g);if(i<0||i<g){return void p("not enough available coins in txouts to trade "+g)}for(let t=0;t<e.length;t++){const i=e[t],[r,o]=ychapi._sign_txout_t1(i);if(null!=o)return void p(o);m.push(r)}}if("evm_t1"==h.type||"erc20_t1"==h.type){const t=h.cfg.unit,r=g;for(let o=0;o<i.length;o++){const a=i[o],c="0x"+a.txid,l=a.orders+a.filled+r,p=l*t,h=[ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(e),c,p,ychapi._evm_zeroaddr,a.nout+1)],y={txid:a.txid,nout:a.nout,amnt:a.amount,fill:a.filled,usea:r,sigf:"",sigv:l,sigs:h};m.push(y)}}}let b="";m.forEach((function(t,e){b+=t.txid+":"+t.nout,b+=t.fill.toString(),b+=t.usea.toString()}));const v=e+i+r.toString()+o.toString()+a.toString()+c.toString()+"0"+_.toString()+b+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/sell",digest:v,data:{coina:e,coinb:i,price:r,amounta:o,amountb:a,feea:c,feeb:0n,usedebit:_,usetxouts:m}}).then((function(t){l(t)})).catch((function(t){p(t)}))}))},ychapi._call_sell_order_cancel=async function(t,e,i){return new Promise(((r,o)=>{const a=t+e+i.toString()+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/nosell",digest:a,data:{coina:t,coinb:e,index:i}}).then((function(){r()})).catch((function(t){o(t)}))}))},ychapi._call_get_chart_data=async function(t,e){return new Promise(((i,r)=>{ychapi._apicall({calltype:"GETRAW",uri:"/u/chart/"+t+"/"+e,data:{}}).then((function(t){i(t)})).catch((function(t){r(t)}))}))},ychapi._is_valid_evm_address=function(t){return!!/^(0x)?[0-9a-f]{40}$/i.test(t)&&(!(!/^(0x)?[0-9a-f]{40}$/.test(t)&&!/^(0x)?[0-9A-F]{40}$/.test(t))||_ethers.utils.isAddress(t))},ychapi._validate_address=function(t,e){if(""==e)return"Address is empty";const i=ychapi._get_coin_info(t);if("txout_t1"==i.type){ychapi._init_coinjs(t);try{let t=coinjs.addressDecode(e);if(0==t)return"Address is not recognized(1)";if("other"==t.type)return"Address is not recognized(2)"}catch(t){return"Address is not recognized(3)"}}if("peg_t1"==i.type){ychapi._init_coinjs(t);try{let t=coinjs.addressDecode(e);if(0==t)return"Address is not recognized(1)";if("bech32"==t.type)return"Address type bech32 is not supported";if("other"==t.type)return"Address is not recognized(2)"}catch(t){return"Address is not recognized(3)"}}return"evm_t1"!=i.type&&"erc20_t1"!=i.type||ychapi._is_valid_evm_address(e)?null:"Address is not recognized"},ychapi._has_coin_holding_address=function(t){return null!=ychapi._data.profile&&(t in ychapi._addresses&&""!=ychapi._addresses[t])},ychapi._get_coin_holding_address=function(t){return null==ychapi._data.profile?"":t in ychapi._addresses?ychapi._addresses[t]:""},ychapi._get_coin_credit_address=function(t){if("txout_t1"!=ychapi._get_coin_info(t).type)return"";if(null==ychapi._data.profile)return"";const e=ychapi._get_credit_signing_pubk();if(null==e)return"";const i=ychapi._get_server_signing_pubk();if(null==i)return"";return coinjs.pubkeys2MultisigAddressWithBackup(e,i,0,0).address},ychapi._create_withdraw=function(t,e){let i={};i.coin=t,i.scope=e,i.sendfee=0n,i.datatag=0n,i.mode="reduce",i.last_error=null;return"txout_t1"==ychapi._get_coin_info(t).type&&(i.datatag=1n),i.op1=ychapi._create_withdraw_op(),i.op2=ychapi._create_withdraw_op(),i.op3=ychapi._create_withdraw_op(),i.get_available_amount=function(){let t=0n;return i.op1.txouts.forEach((function(e){t+=e.free})),t},i.get_sendfee=function(){return i.sendfee},i.get_output_datatag_amount=function(){return 0n==i.op2.amount_out?0n:i.datatag},i.set_txouts_user=function(t){t.txouts_user=ychapi._get_coin_txouts(i.coin),t.txouts_user=t.txouts_user.filter((t=>400==t.state&&"allocated"!=i.scope||500==t.state&&"allocated"==i.scope)),t.txouts_user.sort((function(t,e){return Number(e.free-t.free)})),t.txouts=t.txouts_user},i.set_txouts_debit=function(t){if(t.txouts_debit=[],"allocated"==i.scope)return;const e=ychapi._get_coin_balance(i.coin);if(null==e)return;if(e.debit<=0)return;const r=ychapi._get_coin_info(i.coin);if("peg_t1"!=r.type&&"evm_t1"!=r.type&&"txout_t1"!=r.type&&"erc20_t1"!=r.type)return;0n!=e.debit-e.ordersindebit&&(t.txouts_debit=[ychapi._create_virtual_debit_txout(i.coin)],t.txouts=t.txouts.concat(t.txouts_debit))},i.select_txouts2=function(){if("reduce"==i.mode){let t=0n;i.op2.txouts.forEach((function(e){t+=e.free})),t<i.op2.amount_inp&&(i.op2.amount_inp=t)}let t=i.op2.select2(i.op2.amount_inp);return null!=t?t:("reduce"==i.mode?i.op2.reduce(i.get_output_datatag_amount()):i.op2.change-=i.get_output_datatag_amount(),null)},i.stabilize_op=function(t){i.trace("stabilize_op",t);let e=0n;const r=ychapi._get_coin_info(i.coin);"txout_t1"==r.type&&(e=r.fee.minamount);let o=t.stabilize(r,e);return i.trace("stabilize_op end",t),o},i.trace=function(t,e){},i},ychapi._update_withdraw=function(t){return t.set_txouts_user(t.op1),t.set_txouts_debit(t.op1),t.op1.make_id2idx(),t.set_txouts_user(t.op2),t.set_txouts_debit(t.op2),t.op2.make_id2idx(),err=t.last_error=ychapi._compute_withdraw_datas(t),err},ychapi._set_withdraw_amount=function(t,e,i){t.op1.amount_inp=e,t.op2.amount_inp=e;const r=Number(t.op1.amount_inp)/1e8,o=ychapi._get_coin_info(t.coin);return null==o?"Coin is not supported":(t.sendfee=BigInt(Math.floor(.5+r*o.fee.withfee*1e8)),"allocated"==t.scope&&(t.sendfee=0n),t.mode=i,"manual"==t.mode&&(t.op2.reduce_mode=!1,t.op3.reduce_mode=!0),"reduce"==t.mode&&(t.op2.reduce_mode=!0,t.op3.reduce_mode=!0),err=t.last_error=ychapi._compute_withdraw_datas(t),err)},ychapi._set_withdraw_inputs_for_debit=function(t,e){t.set_txouts_user(t.op3),t.op3.txouts_debit=e,t.op3.txouts=t.op3.txouts.concat(t.op3.txouts_debit),t.op3.make_id2idx();let i=t.op3.select3(t.op2.amount_out);return null!=i?i:(t.op3.change>0n?t.op3.change-=t.get_output_datatag_amount():t.op3.reduce(t.get_output_datatag_amount()),i=t.stabilize_op(t.op3),null!=i?i:null)},ychapi._compute_withdraw_datas=function(t){let e=t.last_error=t.op1.select1(t.get_sendfee(),t.op2);if(null!=e)return e;if(e=t.last_error=t.select_txouts2(),null!=e)return e;if(e=t.last_error=t.stabilize_op(t.op2),null!=e)return e;if(e=t.last_error=ychapi._validate_address(t.coin,ychapi._get_coin_holding_address(t.coin)),null!=e)return e;const i=ychapi._get_coin_info(t.coin);if(null==i)return"Coin is not supported";if("txout_t1"==i.type){const i=ychapi._get_coin_credit_address(t.coin);if(""==i)return"Credit address is not available";if(e=t.last_error=ychapi._validate_address(t.coin,i),null!=e)return e}return e=t.last_error=ychapi._validate_withdraw_inputs_outputs(t),null!=e?e:null},ychapi._build_txout_t1_tx=function(t,e,i){if("txout_t1"!=ychapi._get_coin_info(t).type)return null;ychapi._init_coinjs(t);let r=null;coinjs.maxrbf>0&&(r=coinjs.maxrbf-1);let o=coinjs.transaction();for(let t=0;t<e.selected.length;t++){let i=e.selected[t],a=coinjs.pubkeys2MultisigAddressWithBackup(i.addr.pub1,i.addr.pub2,i.addr.lck1,i.addr.lck2),c=r;2==i.hold&&(c=i.nseq),o.addinput(i.txid,i.nout,Crypto.util.hexToBytes(a.redeemScript),c,i.amount)}e.amount_out>0n&&o.addoutput(i,e.amount_out),e.change>0n&&o.addoutput(ychapi._get_coin_holding_address(t),e.change),e.credit>0n&&o.addoutput(ychapi._get_coin_credit_address(t),e.credit);let a=[];e.selected.forEach((function(t){let e=Crypto.util.hexToBytes(t.txid).reverse();for(let t=0;t<e.length;t++)a.push(e[t]);let i=coinjs.numToBytes(t.nout);for(let t=0;t<i.length;t++)a.push(i[t])})),a.push("L".charCodeAt(0));for(let t=0;t<i.length;t++)a.push(i.charCodeAt(t));let c=coinjs.numToBytes(Number(e.amount_out));for(let t=0;t<c.length;t++)a.push(c[t]);var l=Crypto.SHA256(Crypto.SHA256(a,{asBytes:!0}),{asBytes:!0});let p="XCH:0:"+Crypto.util.bytesToHex(l.reverse());return o.adddata(Crypto.util.bytesToHex(ychapi._str2bytes(p)),1),o},ychapi._get_withdraw_rawtx=function(t){const e=ychapi._build_txout_t1_tx(t.coin,t.op2,t.addr_send);return null==e?null:e.serialize()},ychapi._validate_withdraw_inputs_outputs=function(t){let e=0n;t.op2.selected.forEach((function(t){e+=t.amount}));let i=t.op2.amount_out+t.op2.change+t.op2.credit+t.get_output_datatag_amount()+t.op2.netfee;return e!=i?"Can not configure inputs(6), change the quantity":null},ychapi._create_virtual_debit_txout=function(t){let e=0n,i=0n;const r=ychapi._get_coin_balance(t);null!=r&&(e=r.debit,i=r.ordersindebit);let o={gidx:1,cidx:1,coin:t,hold:2,state:500,addr:{vers:1,host:"",addr:ychapi._get_coin_holding_address(t),pub1:ychapi._get_credit_signing_pubk(),pub2:ychapi._get_server_signing_pubk(),lck1:0,lck2:0,pksc:"",rdsc:"00"},txid:ychapi._zerotxid,nout:0,free:e-i,orders:0n,amount:e-i,filled:0n,selected:0n};return"peg_t1"==ychapi._get_coin_info(t).type&&(o.amount=e,o.orders=0n,o.filled=i),o},ychapi._has_withdraw_inputs_stage=function(t){return ychapi._has_withdraw_op2_inputs_stage(t.coin,t.op2)},ychapi._has_withdraw_op2_inputs_stage=function(t,e){if("txout_t1"!=ychapi._get_coin_info(t).type)return!1;for(let t=0;t<e.selected.length;t++){if(e.selected[t].txid==ychapi._zerotxid)return!0}return!1},ychapi._prepare_withdraw_call_payload=function(t,e,i,r,o){const a=ychapi._get_coin_info(t);ychapi._init_coinjs(t);const c=Math.floor((new Date).getTime()/1e3)+a.cfg.tw,l=BigInt(c);let p=[],h=[],y="",d="";if("txout_t1"==a.type){for(let t=0;t<r.selected.length;t++){const e=r.selected[t];y+=e.txid+":"+e.nout,y+=e.filled.toString(),y+=e.selected.toString();const[i,o]=ychapi._sign_txout_t1(e);if(null!=o)return[null,null,o];p.push(i)}const i=ychapi._build_txout_t1_tx(t,o,e);console.log("op2 tx:",i);for(let t=0;t<o.selected.length;t++){const e=o.selected[t];d+=e.txid+":"+e.nout,d+=e.filled.toString(),d+=e.selected.toString();const r=1;let a=i.transactionHash(t,r);if(2==e.addr.vers){a=i.transactionHashSegWitV0(t,e.addr.rdsc,r,Number(e.amount)).hash}const[c,l]=ychapi._sign_txout_t1_hash(e,t,a);if(null!=l)return[null,null,l];h.push(c)}}if("peg_t1"==a.type)for(let t=0;t<o.selected.length;t++){const e=o.selected[t];d+=e.txid+":"+e.nout,d+=e.filled.toString(),d+=e.selected.toString();const i="",r="",a=0n,c={txid:e.txid,nout:e.nout,amnt:e.amount,fill:e.filled,usea:e.selected,sigf:i,sign:r,sigv:a};h.push(c)}if("evm_t1"==a.type||"erc20_t1"==a.type){const i=a.cfg.unit;for(let e=0;e<r.selected.length;e++){const o=r.selected[e];y+=o.txid+":"+o.nout,y+=o.filled.toString(),y+=o.selected.toString();const a="0x"+o.txid,c=o.orders+o.filled+o.selected,l=c*i,h=[ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(t),a,l,ychapi._evm_zeroaddr,o.nout+1)],d={txid:o.txid,nout:o.nout,amnt:o.amount,fill:o.filled,usea:o.selected,sigf:"",sigv:c,sigs:h};p.push(d)}let f=0,_=0;if(o.selected.forEach((function(t,e){t.txid==ychapi._zerotxid?_++:f++})),f>1){return[null,null,"More than one state: unfinished chain operations, try later"]}if(_>1){return[null,null,"More than one debit, error"]}o.selected.forEach((function(r,o){d+=r.txid+":"+r.nout,d+=r.filled.toString(),d+=r.selected.toString();let a="",p="",y=0n;if(r.txid==ychapi._zerotxid);else{y=r.selected;const o=r.selected*i,h="0x"+r.txid;a=ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(t),h,o,e,c);const d=(0,ychapi._get_evm_vault7u_next_state1)(h,e,o,l),f=(r.orders+r.filled)*i;p=ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(t),d,f,ychapi._evm_zeroaddr,r.nout+1)}const f={txid:r.txid,nout:r.nout,amnt:r.amount,fill:r.filled,usea:r.selected,sigf:a,sign:p,sigv:y,sigs:[]};h.push(f)}))}const f=ychapi._get_coin_holding_address(t),_=ychapi._get_coin_credit_address(t);return[t+e+_+f+o.amount_out.toString()+o.debit.toString()+o.credit.toString()+o.change.toString()+o.netfee.toString()+i.toString()+y+d+ychapi._get_user_login_pubk(),{coin:t,addr_send:e,addr_credit:_,addr_change:f,value_send:o.amount_out,value_debit:o.debit,value_credit:o.credit,value_change:o.change,value_netfee:o.netfee,value_sendfee:i,usetxouts1:p,usetxouts2:h,twin:l},null]},ychapi._call_withdraw_inputs_stage=function(t){return new Promise(((e,i)=>{let r=!1;for(let e=0;e<t.op2.selected.length;e++){if(t.op2.selected[e].txid==ychapi._zerotxid){r=!0;break}}if(!r)throw new Error("No debit");if("txout_t1"!=ychapi._get_coin_info(t.coin).type)throw new Error("Invalid coin type");const[o,a,c]=ychapi._prepare_withdraw_call_payload(t.coin,t.addr_send,t.get_sendfee(),t.op1,t.op2);if(null!=c)throw c;ychapi._apicall({uri:"/u/withdraw",digest:o,data:a}).then((function(t){if(!("step"in t))throw new Error("Unexpected response without step");if("txouts"!=t.step)throw new Error("Unexpected response without txouts step: "+t.step);e(t.txouts)})).catch((function(t){i(t)}))}))},ychapi._call_withdraw=function(t,e,i,r,o){return new Promise(((a,c)=>{if(ychapi._has_withdraw_op2_inputs_stage(t,o))return void c("Debit is not filled");const[l,p,h]=ychapi._prepare_withdraw_call_payload(t,e,i,r,o);null==h?ychapi._apicall({uri:"/u/withdraw",digest:l,data:p}).then((function(t){a(t)})).catch((function(t){c(t)})):c(h)}))},ychapi._call_withdraw_report_txid=function(t,e,i){return new Promise(((r,o)=>{ychapi._apicall({uri:"/u/withdraw_evm_txid",data:{coin:t,gidx:e,txid:i}}).then((function(t){r()})).catch((function(t){o(t)}))}))},ychapi._call_withdraw_cancel=function(t,e){return new Promise(((i,r)=>{const o=t+e+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/nowithdraw",digest:o,data:{coin:t,gidx:e}}).then((function(t){i()})).catch((function(t){r(t)}))}))},ychapi._create_withdraw_op=function(){let t={reduce_mode:!1,amount_inp:0n,amount_out:0n,txouts:[],txouts_user:[],txouts_debit:[],txout_id_to_idx:{},selected:[],unselected:[],netfee:0n,debit:0n,change:0n,credit:0n,num_inps:0,num_outs:0,rawtx:"",select1:function(e,i){if(t.selected=[],t.txouts.forEach((function(t){t.selected=0n})),1==t.txouts_debit.length){let i=t.txouts_debit[0];if(i.free>0n){let r=i.free;r>e&&(r=e),i.selected=r,t.selected.push(i),e-=r}}if(e>0n){let i=[...t.txouts_user];i.sort((function(t,e){return Number(t.free-e.free)}));{let t=0n;if(i.forEach((function(e,i){t+=e.free})),t<e)return console.log("txouts_free < amount",t,e),"Not enough available for withdraw"}let r=0n;for(;r<e;)for(let o=0;o<i.length;o++){let a=i[o];if(o+1==i.length){t.selected.push(a);let c=a.free;r+c>e&&(c=e-r),a.selected=c,r+=a.free,i=i.slice(0,o);break}if(r+a.free>=e){t.selected.push(a);let c=a.free;r+c>e&&(c=e-r),a.selected=c,r+=a.free,i.splice(o,1);break}if(r>=e)break}}return t.make_unselected(),t.use2credit(i),null},make_id2idx:function(){t.txout_id_to_idx={},t.txouts.forEach((function(e,i){const r=e.txid+":"+e.nout;t.txout_id_to_idx[r]=i}))},make_unselected:function(){let e={};t.selected.forEach((function(i){let r=i.txid+":"+i.nout;e[r]=!0,t.credit+=i.filled;const o=i.amount-i.selected-i.filled;t.change+=o})),t.unselected=[],t.txouts.forEach((function(i){i.txid+":"+i.nout in e||t.unselected.push(i)}))},use2credit:function(e){return t.selected.forEach((function(t,i){const r=t.txid+":"+t.nout;if(!(r in e.txout_id_to_idx))return;const o=e.txout_id_to_idx[r];let a=e.txouts[o];a.txid==ychapi._zerotxid?(a.free=t.free-t.selected,a.amount=t.amount-t.selected):(a.free=t.free-t.selected,a.filled=t.filled+t.selected)})),null},select2:function(e){t.selected=[],t.amount_inp=e,t.amount_out=e,t.debit=0n,t.credit=0n,t.change=0n,t.netfee=0n,t.txouts.forEach((function(t){t.selected=0n}));let i=[...t.txouts_user];i.sort((function(t,e){return Number(t.free-e.free)}));let r=0n,o=e,a=0n;i.forEach((function(t){a+=t.free})),o>a&&(r=o-a,o=a);let c=!1;if(r>0n){let e=r;if(1==t.txouts_debit.length){let i=t.txouts_debit[0];if(i.free>0n){let r=i.free;r>e&&(r=e),i.selected=r,t.selected.push(i),e-=r,c=!0}}if(e>0n)return"Not enough available for withdraw"}let l=o,p=0n;for(;p<l;){for(let e=0;e<i.length;e++){let r=i[e];if(e+1==i.length){t.selected.push(r);let o=r.free;p+o>l&&(o=l-p),r.selected=o,p+=r.free,i=i.slice(0,e);break}if(p+r.free>=l){t.selected.push(r);let o=r.free;p+o>l&&(o=l-p),r.selected=o,p+=r.free,i.splice(e,1);break}if(p>=l)break}if(0==i.length)break}return p<l?"Not enough available for withdraw":(t.make_unselected(),null)},select3:function(e){t.selected=[],t.amount_inp=e,t.amount_out=e,t.debit=0n,t.credit=0n,t.change=0n,t.netfee=0n,t.txouts.forEach((function(t){t.selected=0n}));let i=[...t.txouts_user];i.sort((function(t,e){return Number(t.free-e.free)}));let r=0n,o=e,a=0n;i.forEach((function(t){a+=t.free})),o>a&&(r=o-a,o=a);let c=o,l=0n;for(;l<c;){for(let e=0;e<i.length;e++){let r=i[e];if(e+1==i.length){t.selected.push(r);let o=r.free;l+o>c&&(o=c-l),r.selected=o,l+=r.free,i=i.slice(0,e);break}if(l+r.free>=c){t.selected.push(r);let o=r.free;l+o>c&&(o=c-l),r.selected=o,l+=r.free,i.splice(e,1);break}if(l>=c)break}if(0==i.length)break}if(l<c)return"Not enough available for withdraw";for(i=[...t.txouts_debit],i.sort((function(t,e){return Number(t.free-e.free)})),c=r,l=0n;l<c;){for(let e=0;e<i.length;e++){let r=i[e];if(e+1==i.length){t.selected.push(r);let o=r.free;l+o>c&&(o=c-l),r.selected=o,l+=r.free,i=i.slice(0,e);break}if(l+r.free>=c){t.selected.push(r);let o=r.free;l+o>c&&(o=c-l),r.selected=o,l+=r.free,i.splice(e,1);break}if(l>=c)break}if(0==i.length)break}return l<c?"Not enough available for withdraw":(t.make_unselected(),null)},add_more:function(e){let i=[],r=null;t.unselected.forEach((function(t){t.txid!=ychapi._zerotxid?i.push(t):r=t}));let o=[],a=0n;for(i.sort((function(t,e){return Number(t.amount-t.filled-(e.amount-e.filled))}));a<e;){for(let r=0;r<i.length;r++){let c=i[r],l=c.amount-c.filled;if(r+1==i.length){t.selected.push(c),o.push(c),c.selected=0n,a+=l,i=i.slice(0,r);break}if(a+l>=e){t.selected.push(c),o.push(c),c.selected=0n,a+=l,i.splice(r,1);break}if(a>=e)break}if(0==i.length)break}if(a<e&&null!=r){let e=r,i=e.amount-e.filled;t.selected.push(r),o.push(r),r.selected=0n,a+=i}if(a<e)return"Not enough available to select";let c={};return t.selected.forEach((function(t){let e=t.txid+":"+t.nout;c[e]=!0})),o.forEach((function(e){t.credit+=e.filled;const i=e.amount-e.selected-e.filled;t.change+=i})),t.unselected=[],t.txouts.forEach((function(e){e.txid+":"+e.nout in c||t.unselected.push(e)})),null},reduce:function(e){t.amount_out-=e;let i=t.selected;i.sort((function(t,e){return Number(t.selected-e.selected)}));for(let t=0;t<i.length;t++){let r=i[t],o=e;if(o>r.selected&&(o=r.selected),r.selected-=o,0n==(e-=o))break}},stabilize_changes:function(e){if(0n==e)return!0;if((0n==t.credit||t.credit>=e)&&(0n==t.change||t.change>=e))return!0;const i=t.change+t.credit;if(t.credit>0n&&e<=i&&i<e+e)return t.debit=t.change,t.credit=i,t.change=0n,!0;if(t.credit>0n&&t.credit<e&&i>=e+e){let i=e-t.credit;return t.debit+=i,t.credit+=i,t.change-=i,!0}return t.change>0n&&t.change<e&&i>=e+e&&(t.debit+=t.change,t.credit+=t.change,t.change=0n,!0)},stabilize_change:function(e,i){if(t.stabilize_changes(e))return null;let r=e-(t.change+t.credit),o=0n;if(t.unselected.forEach((function(t){o+=t.amount-t.filled})),r<=o){let i=t.add_more(r);if(null!=i)return i;if(t.stabilize_changes(e))return null}else if(i&&t.amount_out>r){t.reduce(r),t.change+=r;if(t.stabilize_changes(e))return null}return"Can not configure inputs(1), change the quantity"},compute_netfee:function(e){if(0n!=t.amount_inp)if("peg_t1"!=e.type)if("txout_t1"!=e.type)t.netfee=0n;else{const i=e.fee.txbytefee;t.num_inps=t.selected.length,t.num_outs=1,t.change>0n&&t.num_outs++,t.credit>0n&&t.num_outs++,t.num_outs++;let r=386*t.num_inps+34*(t.num_outs-1)+80;e.fee.txbyteround>1&&(r=Math.ceil(r/e.fee.txbyteround)*e.fee.txbyteround),t.netfee=BigInt(Math.floor(r*i*1e8+.5));const o=e.fee.mempoolminfee,a=BigInt(Math.floor(1e8*o+.5));t.netfee<a&&(t.netfee=a)}else t.netfee=10000000n;else t.netfee=0n},stabilize_netfee:function(e,i){let r=0n;"txout_t1"==e.type&&(r=e.fee.minamount);let o=0n,a=0n,c=0n;for(let l=0;l<10;l++){if(t.change+=o,t.credit+=a,t.debit+=c,o=0n,a=0n,c=0n,null!=t.stabilize_change(r,i))break;t.compute_netfee(e);let l=t.netfee,p=l;if(t.debit>0n&&t.credit>0n){let e=t.credit;if(e>t.debit&&(e=t.debit),e>p&&(e=p),t.credit-e>0n&&t.credit-e<r&&(e=t.credit-r),p-=e,a+=e,t.credit-=e,c+=e,t.debit-=e,0n==p)return null}if(t.change>0n&&t.change>=p){if(o+=p,t.change-=p,p=0n,null!=t.stabilize_change(r,i))break;if(t.compute_netfee(e),l!=t.netfee)continue;return null}t.change>0n&&t.change<p&&(o+=t.change,p-=t.change,t.change=0n);let h=0n;if(t.unselected.forEach((function(t,e){h+=t.amount-t.filled})),p<=h){if(t.add_more(p),o+=p,t.change-=p,p=0n,!t.stabilize_changes(r))break;if(t.compute_netfee(e),l!=t.netfee)continue;return null}if(i&&t.amount_out>p){if(t.reduce(p),p=0n,!t.stabilize_changes(r))break;if(t.compute_netfee(e),l!=t.netfee)continue;return null}}return"Can not configure inputs(3), change the quantity"},stabilize:function(e,i){let r=t.stabilize_change(i,t.reduce_mode);return null!=r?r:(r=t.stabilize_netfee(e,t.reduce_mode),null!=r?r:null)}};return t},ychapi._ready_wsdata=!1,ychapi._timer_reauth_duration=3e5,ychapi._ws_callbacks={},ychapi._start_ws=function(){ychapi._ready_wsdata=!1;let t="ws:";"https:"==window.location.protocol&&(t="wss:");let e=t+"//"+window.location.hostname+":"+window.location.port+"/ws";""!=ychapi._base_uri&&(e=ychapi._base_uri+"/ws"),console.log("Use sync connection: "+e),ychapi._websocket=new ReconnectingWebSocket(e),ychapi._websocket.onopen=ychapi._on_ws_onopen,ychapi._websocket.onclose=ychapi._on_ws_onclose,ychapi._websocket.onmessage=ychapi._on_ws_onmessage},ychapi._on_ws_onclose=function(t){ychapi._ready_wsdata=!1,ychapi._callbacks.on_sync_connection_lost()},ychapi._on_ws_onopen=function(t){ychapi._ready_wsdata=!0,ychapi._do_ws_init()},ychapi._do_ws_init=function(){if(ychapi._websocket.readyState!=WebSocket.OPEN)return;const t={type:"init",jwt:ychapi._get_cookie("jwt")};ychapi._websocket.send(JSON.stringify(t)),ychapi._ready_wsdata=!0,ychapi._callbacks.on_sync_connecting(),ychapi._ready_wsdata&&ychapi._ready_data&&ychapi._callbacks.on_sync_ready(),clearTimeout(ychapi._timer_reauth),ychapi._timer_reauth=setTimeout(ychapi._do_apicall_reauth,ychapi._timer_reauth_duration)},ychapi._on_ws_onmessage=function(t){if("message"==t.type){let e={};t.data.split("\n").forEach((function(t,i){try{e=JSON.parse(t,ychapi._jsonBNparse)}catch(t){return}ychapi._on_ws_message(e)}))}else console.log("Received ws event, not a message: ",t)},ychapi._on_ws_message=function(t){"type"in t?(t.type in ychapi._ws_callbacks?ychapi._ws_callbacks[t.type](t):console.log("Received unknown ws event, message: ",t),ychapi._callbacks.on_sync_message(t)):console.log("Received unknown ws event, message: ",t)},ychapi._ws_callbacks.nnum=function(t){const e=t.objects[0];ychapi._nnum=e},ychapi._ws_callbacks.coininfo=function(t){const e=t.objects[0];null==ychapi._data.coininfos&&(ychapi._data.coininfos={}),ychapi._data.coininfos[e.coin]=e,ychapi._callbacks.on_sync_data_update("coininfo",e)},ychapi._ws_callbacks.market=function(t){const e=t.objects[0];ychapi._data.markets[e.name]=e,ychapi._callbacks.on_sync_data_update("market",e)},ychapi._ws_callbacks.markettradesupdate=function(t){const e=t.objects[0],i=e.coina+"-"+e.coinb;ychapi._data.trades[i]=e.page,ychapi._callbacks.on_sync_data_update("trades",i,e.coina,e.coinb,e.page)},ychapi._ws_callbacks.usertradesupdate=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[0],i=e.coina+"-"+e.coinb;ychapi._data.profile.trades[i]=e.page,ychapi._callbacks.on_sync_data_update("user_trades",i,e.coina,e.coinb,e.page)},ychapi._ws_callbacks.depositaddress=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[0],i=e.coin;if(ychapi._addresses[i]=e.addr,ychapi._locktimes1[i]=e.lck1,ychapi._locktimes2[i]=e.lck2,i in ychapi._data.profile.balances){const t=ychapi._data.profile.balances[i];ychapi._callbacks.on_sync_data_update("balance",t)}},ychapi._ws_callbacks.adddeposit=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[1],i=e.coin;let r=ychapi._data.profile.deposits[i],o=!0;r.forEach((function(t,i){t.index>=e.index&&(o=!1)})),o&&(r.unshift(e),r=r.slice(0,ychapi._get_page_size()),ychapi._data.profile.deposits[i]=r)},ychapi._ws_callbacks.regdeposit=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[1],i=e.coin;let r=ychapi._data.profile.deposits[i];r.forEach((function(t,i){e.index==t.index&&(r[i]=e,t=e)}))},ychapi._ws_callbacks.addwithdraw=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[1],i=e.coin;let r=ychapi._data.profile.withdraws[i],o=!0;r.forEach((function(t,i){t.uidx>=e.uidx&&(o=!1)})),o&&(r.unshift(e),r=r.slice(0,ychapi._get_page_size()),ychapi._data.profile.withdraws[e.coin]=r)},ychapi._ws_callbacks.regwithdraw=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[1],i=e.coin;let r=ychapi._data.profile.withdraws[i];r.forEach((function(t,i){e.uidx==t.uidx&&(r[i]=e,t=e)}))},ychapi._ws_callbacks.balances=function(t){t.objects[0].forEach((function(t){ychapi._data.profile.balances[t.coin]=t,ychapi._callbacks.on_sync_data_update("balance",t)}))},ychapi._ws_callbacks.accountchange=function(t){},ychapi._ws_callbacks.newcandle=function(t){},ychapi._ws_callbacks.updatecandle=function(t){},ychapi._ws_callbacks.txoutsupdate=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[0],i=t.objects[1];ychapi._data.profile.txouts[e]=i,ychapi._callbacks.on_sync_data_update("txouts",e,i)},ychapi._ws_callbacks.buysupdate=function(t){const e=t.objects[0],i=e.coina+"-"+e.coinb;ychapi._data.buys[i]=e.buyspage,ychapi._callbacks.on_sync_data_update("buys",i,e.coina,e.coinb,e.buyspage)},ychapi._ws_callbacks.sellsupdate=function(t){const e=t.objects[0],i=e.coina+"-"+e.coinb;ychapi._data.sells[i]=e.sellspage,ychapi._callbacks.on_sync_data_update("sells",i,e.coina,e.coinb,e.sellspage)},ychapi._ws_callbacks.userbuysupdate=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[0],i=e.coina+"-"+e.coinb;ychapi._data.profile.buys[i]=e.buyspage,ychapi._callbacks.on_sync_data_update("user_buys",i,e.coina,e.coinb,e.buyspage)},ychapi._ws_callbacks.usersellsupdate=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[0],i=e.coina+"-"+e.coinb;ychapi._data.profile.sells[i]=e.sellspage,ychapi._callbacks.on_sync_data_update("user_sells",i,e.coina,e.coinb,e.sellspage)},ychapi._get_cookie=function(t){const e=t+"=",i=decodeURIComponent(document.cookie).split(";");for(let t=0;t<i.length;t++){let r=i[t];for(;" "==r.charAt(0);)r=r.substring(1);if(0==r.indexOf(e))return r.substring(e.length,r.length)}return""},ychapi._get_jwt_uid=function(){const t=ychapi._get_cookie("jwt").split(".");if(3==t.length){const e=t[1].replace("-","+").replace("_","/");return JSON.parse(window.atob(e)).uid}return""},ychapi._str2bytes=function(t){let e=[];for(let i=0;i<t.length;i++){let r=t.charCodeAt(i);r<128?e.push(r):r<2048?e.push(192|r>>6,128|63&r):r<55296||r>=57344?e.push(224|r>>12,128|r>>6&63,128|63&r):(i++,r=65536+((1023&r)<<10|1023&t.charCodeAt(i)),e.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return e},ychapi._get_page_size=function(){return ychapi._pagesize};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ychapi",
3
- "version": "0.945.0",
3
+ "version": "0.1192.0",
4
4
  "description": "Walrus-compatible exchange js api layer",
5
5
  "main": "api.js",
6
6
  "scripts": {