UNPKG

@woleet/woleet-widgetv2

Version:

Woleet web widgets V2

2 lines 535 kB
/*! For license information please see file-hasher-widget.js.LICENSE.txt */ (()=>{var __webpack_modules__={3353:e=>{e.exports=function(e,t={}){return new Promise(((r,n)=>{const i=new XMLHttpRequest;i.onload=()=>{switch(i.status){case 200:case 201:r(i.response);break;default:n({code:i.status})}},i.onerror=function(){n({code:0})},i.open(t.method||"GET",e,!0),t.token&&i.setRequestHeader("Authorization","Bearer "+t.token),"POST"===t.method&&i.setRequestHeader("Content-Type","application/json"),i.setRequestHeader("Accept","application/json"),i.responseType="json",i.json="json",i.send(JSON.stringify(t.data))}))}},9314:(e,t,r)=>{if("undefined"==typeof window)throw new Error("This module is not meant to be used by node");const n=r(3353),i=r(1393)(n);i.crypto=r(7129),i.file=r(3934),i.receipt.validate=r(2165)(i.crypto),i.signature=r(3895)(i.identity.get),i.verify=r(9257)(i),e.exports=i},7129:(e,t,r)=>{var n=r(8764).Buffer;if("undefined"==typeof _in_worker&&"undefined"==typeof window)throw new Error("This module is not meant to be used by node");const i=(e=>e)(r(8249),r(7792),r(2153),r(7460),r(34),r(4433)),s=i.lib.WordArray;function a(e){const t=i.algo[e].create(),r={update:function(e,a){let o;if(e instanceof Uint8Array)o=s.create(e);else if(s.isPrototypeOf(e))o=e;else if(a)switch(a){case"binary":const t=e.length,r=new Uint8Array(t);for(let n=0;n<t;n++)r[n]=e.charCodeAt(n);o=s.create(r);break;case"hex":o=i.enc.Hex.parse(e);break;case"utf8":o=e;break;default:o=s.create(new n(e,a))}else if(e){if("string"!=typeof e)throw new TypeError;o=e}else o=s.create();return t.update(o),r},digest:function(e){const r=i.enc.Hex.stringify(t.finalize());if(e&&"hex"===e)return r;{const t=new n(r,"hex");return e?t.toString(e):t}}};return r}function o(e){switch(e){case"sha224":return a("SHA224");case"sha256":return a("SHA256");case"sha384":return a("SHA384");case"sha512":return a("SHA512");default:throw new Error("Hash algorithm not supported")}}e.exports={createHash:o,CryptoJS:i,Buffer:n,sha256:()=>o("sha256"),sha224:()=>o("sha224"),sha384:()=>o("sha384"),sha512:()=>o("sha512")}},3934:(e,t,r)=>{if("undefined"==typeof window)throw new Error("This module is not meant to be used by node");const n=r(7129),i=window,s=i.crypto&&i.crypto.subtle&&i.crypto.subtle.digest,a=function(){let e="woleet-hashfile-worker.min.js",t=document.getElementsByTagName("script"),r=t[t.length-1].src.split("?")[0].split("/").slice(0,-1).join("/")+"/",n=i.woleet&&i.woleet.workerScriptPath?i.woleet.workerScriptPath:r?r+e:null;return n?(console.log("Woleet WebLibs' default worker script will be loaded from: ",n),n):(console.error("Cannot find Woleet WebLibs' default worker script "+e),null)}();function o(e){const t=new XMLHttpRequest;return new Promise((r=>{t.onload=()=>r(200===t.status),t.onerror=()=>r(!1),t.open("GET",e,!0),t.send()})).catch((()=>!1))}function c(e){e||(e=a);let t=!0,r=null,c=null,l={};const[h,d,u,f,p,b]=["start","progress","error","result","cancel","skip"],g=(e,t)=>l[e]&&l[e](t),m=e=>l[e],_=e=>r=e,y=e=>c=e,v="__cancel__",w="__skip__",A=134217728,S=1073741824;function E(e){let t=new Worker(e);this.hash=function(e){return new Promise(((r,n)=>{let i=!1,s=!1;const a=new FileReader;_((()=>{i=!0,t.terminate(),a.abort(),t=null,g(p,{file:e}),n(v)})),y((()=>{s=!0,a.abort(),t.postMessage({action:"reset"})}));const o=e.size;let c=0,l=0;t.onmessage=p=>{if(!i){if(p.data.reset)return g(b,{file:e}),void n(w);if(!s){if(p.data.result)return g(f,{result:p.data.result,file:e}),r();if(p.data.error){let t=p.data.error;if(a.abort(),!m(u))return n(new Error(t));g(u,{error:new Error(t),file:e})}else p.data.start?g(h,{start:p.data.start,file:e}):p.data.progress?g(d,{progress:l/o,file:e}):console.trace("Unexpected worker message: ",p);var _,y;l!==o?(c=l,l=(_=l+1048575)>(y=o)?y:_,a.readAsArrayBuffer(e.slice(c,l))):t.postMessage({action:"finalize"})}}},a.onload=e=>{t.postMessage({chunk:e.target.result,action:"update"})},t.postMessage({action:"start"})}))},this.worker=t}function x(e,r,n){if(e.size>r){t=!0;let r=new Error("file_too_big_to_be_hashed_without_worker");return m(u)?g(u,{error:r,file:e}):(n(r),!1)}return!0}function C(e){return new Promise(((t,r)=>{if(!x(e,A,r))return;let i=0,s=!1,a=!1,o=!1;const c=n.sha256(),l=new FileReader;function u(e,t){const r=e.slice(i,t),n=new Uint8Array(r);c.update(n),i=t}_((()=>{s=!0,l.abort(),g(p,{file:e})})),y((()=>{a=!0,l.abort(),g(b,{file:e})})),l.onloadstart=()=>{s||a||g(h,{start:!0,file:e})},l.onload=r=>{if(s||a)return;o&&u(r.target.result,r.loaded,r.total);const n=c.digest("hex");g(f,{result:n,file:e}),t()},l.onprogress=t=>{if(s||a)return;let r=t.target.result;if(g(d,{progress:t.loaded/t.total,file:e}),!r)return o=!0;u(r,t.loaded,t.total)},l.onabort=()=>{r(s?v:a?w:new Error("Unhandled abort exception"))},l.readAsArrayBuffer(e)}))}function k(e){return new Promise(((t,r)=>{if(!x(e,S,r))return;let n=!1,s=!1;const a=new FileReader;_((()=>{n=!0,a.abort(),g(p,{file:e})})),y((()=>{s=!0,a.abort(),g(b,{file:e})})),a.onloadstart=()=>{n||s||g(h,{start:!0,file:e})},a.onprogress=t=>{n||s||g(d,{progress:t.loaded/t.total,file:e})},a.onload=function(a){if(n||s)return;let o=a.target.result;i.crypto.subtle.digest("SHA-256",o).then((r=>{if(n||s)return;let i=new Uint8Array(r).reduce(((e,t)=>e+("00"+t.toString(16)).slice(-2)),"");g(f,{result:i,file:e}),t()})).catch((t=>l[u]?g(u,{error:t,file:e}):r(t)))},a.onabort=()=>{r(n?v:s?w:new Error("Unhandled abort exception"))},a.readAsArrayBuffer(e)}))}this.on=function(e,t){switch(e){case h:case d:case u:case f:case b:case p:l[e]=t;break;default:throw new Error('Invalid event name "'+e+'"')}},this.start=function(r){let n=null;if(!t)throw new Error("not_ready");if(t=!1,!(r instanceof FileList||r instanceof File||Array.isArray(r)&&r.every((e=>e instanceof File))))throw new Error("invalid_parameter");(function(){if(!e)return Promise.resolve(!1);const t=o(e),r=o(e.split("/").slice(0,-1).join("/")+"/woleet-crypto.min.js"),n=new Promise((function(e){try{let t=function(e){let t=i.URL||window.webkitURL,r=i.Blob,n=i.Worker;if(!(t&&r&&n))return null;let s=new r([e]);return new n(t.createObjectURL(s))}("onmessage = function(e) { postMessage(!!FileReaderSync); close() };");t?(t.onmessage=function(r){t.terminate(),t=null,e(r.data)},t.postMessage({})):e(!1)}catch(t){e(!1)}}));return Promise.all([t,r,n]).then((e=>e.every((e=>!0===e))))})().then((e=>(e||console.warn("Failed to load worker."),e))).then((i=>{function a(r,o,c){if(r>=o)return t=!0,n&&n.worker&&(n.worker.terminate(),n.worker=null),Promise.resolve();{let t;return 0===c[r].size?t=C:s&&c[r].size<=S?t=k:i&&c[r].size>A?(n||(n=new E(e)),t=n.hash):t=C,t(c[r]).then((()=>a(r+1,o,c))).catch((e=>{if(e===w)return a(r+1,o,c);if(e!==v)throw e}))}}return r instanceof FileList?a(0,r.length,r):r instanceof File?a(0,1,[r]):a(0,r.length,r)}))},this.cancel=function(){r&&(r(),r=null,t=!0)},this.skip=function(){r&&(c(),c=null)},this.isReady=()=>t}e.exports={Hasher:c,hashFileOrCheckHash:function(e,t){return new Promise(((r,n)=>{if(e instanceof File){const i=new c;i.on("result",((e,n)=>{r(e.result),t&&t({progress:1,file:n})})),t&&"function"==typeof t&&i.on("progress",t),i.on("error",n),i.start(e)}else"string"==typeof e?/^[a-f0-9]{64}$/i.test(e)?r(e):n(new Error("parameter_string_not_a_sha256_hash")):n(new Error("invalid_parameter"))}))}}},1393:e=>{e.exports=function(e){const t={receipt:{},identity:{}};function r(e){if(!e||0===Object.keys(e).length)return"";const t=[];for(let r in e)e[r]&&t.push([encodeURIComponent(r),encodeURIComponent(e[r])].join("="));return"?"+t.join("&")}function n(e,t,r,n,i){return"Invalid Date"===r.toString()&&(r=null),{txId:e,confirmations:t,timestamp:r,blockHash:n,opReturn:i}}let i="https://api.woleet.io/v1";const s="woleet.io";let a=s;t.config={setDefaultTransactionProvider:e=>{switch(e){case"blockcypher.com":case"blockstream.info":case"woleet.io":a=e;break;default:a=s}},setDefaultWoleetApiUrl:e=>{i=e}},t.transaction={get:function(t){switch(a){case"woleet.io":return e(i+"/bitcoin/transaction/"+t).then((e=>{if(!e.time||!e.confirmations)throw new Error("tx_not_confirmed");return n(e.txid,e.confirmations,new Date(1e3*e.time),e.blockhash,(t=(e.vout||[]).find((e=>e.hasOwnProperty("scriptPubKey")&&e.scriptPubKey.hasOwnProperty("asm")&&e.scriptPubKey.asm.startsWith("OP_RETURN"))))?t.scriptPubKey.asm.split(" ")[1]:null);var t})).catch((()=>{throw new Error("tx_not_found")}));case"blockstream.info":return e("https://blockstream.info/api/tx/"+t).then((r=>{if(!r.status.block_hash)throw new Error("tx_not_confirmed");return e("https://blockstream.info/api/blocks/tip/height").then((i=>e("https://blockstream.info/api/block/"+r.status.block_hash).then((e=>{return n(t,i-e.height,new Date(1e3*e.timestamp),e.id,(s=(r.vout||[]).find((e=>e.hasOwnProperty("scriptpubkey")&&e.scriptpubkey_asm&&e.scriptpubkey_asm.startsWith("OP_RETURN"))))?s.scriptpubkey_asm.split(" ")[2]:null);var s})).catch((e=>{throw new Error("Failed to get block")})))).catch((e=>{throw new Error("Failed to get current block height")}))})).catch((e=>{throw new Error("tx_not_found")}));case"blockcypher.com":return e("https://api.blockcypher.com/v1/btc/main/txs/"+t).then((e=>{if(e.error)throw new Error("tx_not_found");if(!e.confirmed||!e.confirmations)throw new Error("tx_not_confirmed");return n(e.hash,e.confirmations,new Date(e.confirmed),e.block_hash,(t=(e.outputs||[]).find((e=>e.hasOwnProperty("data_hex"))))?t.data_hex:null);var t})).catch((()=>{throw new Error("tx_not_found")}))}}};const o={DATA:1,SIGNATURE:2,BOTH:3};return t.anchor={types:o,getAnchorIDs:(n,s,a)=>{switch(s){case o.SIGNATURE:return e(i+"/anchorids"+r({signedHash:n,size:a})).then((e=>e.content||[])).catch((e=>{throw new Error("http_error")}));case o.DATA:return e(i+"/anchorids"+r({hash:n,size:a})).then((e=>e.content||[])).catch((e=>{throw new Error("http_error")}));default:const s=t.anchor.getAnchorIDs(n,o.SIGNATURE,a),c=t.anchor.getAnchorIDs(n,o.DATA,a);return Promise.all([s,c]).then((([e,t])=>{if(e instanceof Error||t instanceof Error)throw new Error("http_error");return[].concat(e,t)}))}}},t.receipt.get=t=>e(i+"/receipt/"+t).catch((e=>{throw 404===e.code?new Error("not_found"):new Error(e.code)})),t.identity.get=(t,n,i,s)=>e(t+r({pubKey:n,signedIdentity:i,leftData:s})).catch((e=>{throw 404===e.code?new Error("key_not_found"):400===e.code||0===e.code?new Error("http_error"):new Error(e.code)})),t.isSHA256=e=>/^[a-f0-9]{64}$/i.test(e),t.getJSON=e,t}},2165:e=>{e.exports=function(e){const t="invalid_receipt_format",r="invalid_target_proof",n="non_sha256_target_proof_element",i="merkle_root_mismatch",s=e=>{const t=new RegExp("^[a-f0-9]{"+e+"}$","i");return e=>t.test(e)},a=s(64),o=e.sha224,c=e.sha256,l=e.sha384,h=e.sha512;function d(e){const t=this;this.branches=[],this.target=e,this.add=e=>{t.branches.push(e)},this.is_valid=function(e){let r=t.target;if(!t.branches.length)return!1;for(let e,n=0;n<t.branches.length;n++){if(e=t.branches[n],r!==e.left&&r!==e.right)return!1;r=e.parent}return r.toLowerCase()===e.toLowerCase()},this.getJSON=()=>t.branches.map((e=>e.getJSON()))}function u(e,...t){for(let r of t)if(r instanceof Array){if(!e.hasOwnProperty(r[0]))return!1;if("string"==typeof r[1]){if(typeof e[r[0]]!==r[1])return!1}else if(!(e[r[0]]instanceof r[1]))return!1}else if(!e.hasOwnProperty(r)||"string"!=typeof e[r])return!1;return!0}return function(e){if(!e||"object"!=typeof e)throw new Error(t);return e.hasOwnProperty("header")?function(e){if(!u(e,["header","object"],["target","object"]))throw new Error(t);if(!u(e.header,"chainpoint_version","hash_type","merkle_root","tx_id",["timestamp","number"]))throw new Error(t);if(!u(e.target,"target_hash",["target_proof",Array]))throw new Error(t);if(!e.target.target_proof.every((e=>u(e,"left","right","parent"))))throw new Error(r);if(!e.target.target_proof.every((e=>a(e.left)&&a(e.right)&&a(e.parent))))throw new Error(n);if(0===e.target.target_proof.length){if(e.target.target_hash.toLowerCase()===e.header.merkle_root.toLowerCase())return!0;throw new Error(i)}{const t=new d(e.target.target_hash);if(e.target.target_proof.forEach((e=>{const r=c().update(e.left+e.right,"utf8").digest("hex");if(r!==e.parent)throw new Error("invalid_parent_in_proof_element");t.add({left:e.left,right:e.right,parent:r})})),t.is_valid(e.header.merkle_root))return!0;throw new Error(i)}}(e):function(e){if(!u(e,"targetHash","merkleRoot",["proof",Array],["anchors",Array]))throw new Error(t);if(!(e.hasOwnProperty("@context")||e.hasOwnProperty("context")&&e.hasOwnProperty("@type")||e.hasOwnProperty("type")))throw new Error(t);const a=e.type||e["@type"];if("string"!=typeof a||!/^ChainpointSHA([0-9]-)?[0-9]{3}v2$/.test(a))throw new Error(t);let f=null,p=null;switch(a){case"ChainpointSHA224v2":f=o,p=s(56);break;case"ChainpointSHA256v2":f=c,p=s(64);break;case"ChainpointSHA384v2":f=l,p=s(96);break;case"ChainpointSHA512v2":f=h,p=s(128);break;case"ChainpointSHA3-224v2":case"ChainpointSHA3-256v2":case"ChainpointSHA3-384v2":case"ChainpointSHA3-512v2":throw new Error("unsupported_algorithm");default:throw new Error("invalid_type")}if(!e.proof.every((e=>{return t=e.hasOwnProperty("left"),r=e.hasOwnProperty("right"),t?!r:r;var t,r})))throw new Error(r);if(!e.proof.every((e=>p(e.left||e.right))))throw new Error(n);if(0===e.proof.length){if(e.targetHash.toLowerCase()===e.merkleRoot.toLowerCase())return!0;throw new Error(i)}{const t=new d(e.targetHash);let r=e.targetHash;if(e.proof.forEach((e=>{let n,i;e.left?(n=e.left,i=r):(n=r,i=e.right);const s=f().update(n+i,"hex").digest("hex");r=s,t.add({left:n,right:i,parent:s})})),t.is_valid(e.merkleRoot))return!0;throw new Error(i)}}(e)}}},3895:(e,t,r)=>{var n=r(8764).Buffer;e.exports=function(e){const t=r(7790).verify;function i(e,t){return t?(t=s(t)).commonName!==e.commonName||t.emailAddress&&e.emailAddress&&t.emailAddress!==e.emailAddress?{valid:!1,reason:"identity_mismatch"}:{valid:!0,identity:e,signedIdentity:t}:{valid:!0,identity:e}}function s(e){function t(e,t){let r,n=[],i=0;for(let s=0;s<t.length;s++){const a=t.charAt(s);a===e&&"\\"!==r&&(n.push(t.slice(i,s)),s++,i=s),s>=t.length-1&&n.push(t.slice(i,s+1)),r=a}return n}const r={};return t(",",e).forEach((e=>{const n=t("=",e),i=n[0],s=n[1].replace("\\ "," ").replace("\\=","=").replace('\\"','"').replace("\\,",",").replace("\\;",";").replace("\\+","+");switch(i.toUpperCase().trim()){case"CN":r.commonName=s;break;case"EMAILADDRESS":r.emailAddress=s;break;case"O":r.organization=s;break;case"OU":r.organizationalUnit=s;break;case"L":r.locality=s;break;case"C":r.country=s}})),r}function a(e,r,n){try{return Promise.resolve({valid:t(e,r,n,"Bitcoin Signed Message:\n")})}catch(e){return Promise.resolve({valid:!1,reason:e.message})}}return{validateSignature:a,validateIdentity:function(t,r,o,c){if(!t)return o?Promise.resolve({valid:!0,signedIdentity:s(o)}):Promise.resolve({valid:!1});if(c&&!new URL(t).hostname.includes(c))return Promise.resolve({valid:!1,reason:"identity_mismatch"});const l=function(e){let t=0;const r=[];for(;t++<16;)r.push(Math.floor(255*Math.random()));return new n(r).toString("hex")}();return e(t,r,o,l).then((e=>e&&"object"==typeof e?e.signature?e.rightData.startsWith(t)?a(l+e.rightData,r,e.signature).then((t=>t.valid?i(e.identity,o):t)):{valid:!1,reason:`'rightData' should start with '${t}'`}:e.identity?i(e.identity,o):{valid:!1,reason:"'identity' should be provided'"}:{valid:!1,reason:"invalid response"})).catch((e=>"key_not_found"===e.message?{valid:!1,reason:e.message}:o?Promise.resolve({valid:!0,signedIdentity:s(o)}):Promise.resolve({valid:!1,reason:e.message})))},deserializeX500DN:s}}},9257:e=>{e.exports=function(e){function t(t){return Promise.resolve(t).then((t=>{const r=t.receipt.signature;if(!r)return t;if(!r.signature||!r.signedHash||!r.pubKey)throw new Error("invalid_receipt_signature_format");let n=r.signedHash;return(r.signedIdentity||r.signedIssuerDomain)&&(n=e.crypto.sha256().update(r.signedHash+(r.signedIdentity||"")+(r.signedIssuerDomain||"")).digest("hex")),e.signature.validateSignature(n,r.pubKey,r.signature).then((n=>{if(!n.valid)throw new Error("invalid_receipt_signature");return e.signature.validateIdentity(r.identityURL,r.pubKey,r.signedIdentity,r.signedIssuerDomain).then((e=>(e.valid?t.identityVerificationStatus={code:"verified",identity:e.identity,signedIdentity:e.signedIdentity}:t.identityVerificationStatus={code:e.reason,identity:e.identity,signedIdentity:e.signedIdentity},t))).catch((e=>(t.identityVerificationStatus={code:e.message},t)))}))}))}function r(r,n){return Promise.resolve().then((()=>e.receipt.validate(r))).then((()=>{n&&function(e,t){if(e.signature){if(e.signature.signedHash!==t)throw new Error("target_hash_mismatch")}else if((e.target&&e.target.target_hash||e.targetHash)!==t)throw new Error("target_hash_mismatch")}(r,n)})).then((()=>function(t){return e.transaction.get((e=>e.header&&e.header.tx_id||e.anchors&&e.anchors.find((e=>"BTCOpReturn"===e.type)).sourceId)(t)).then((e=>{if(e.opReturn===(t.header&&t.header.merkle_root||t.merkleRoot))return{receipt:t,confirmations:e.confirmations,timestamp:e.timestamp,code:"verified"};throw new Error("op_return_mismatches_merkle_root")}))}(r))).then(t).catch((e=>({receipt:r,code:e.message})))}return{WoleetDAB:function(t,n){return e.file.hashFileOrCheckHash(t,n).then((t=>e.anchor.getAnchorIDs(t,e.anchor.types.BOTH))).then((t=>{const r=[];return t.reduce(((t,n)=>t.then((()=>e.receipt.get(n).then((e=>{r.push(e)})).catch((e=>{if("202"!==e.message)throw e}))))),Promise.resolve()).then((()=>{if(t.length&&!r.length)throw new Error("file_matched_but_anchor_not_yet_processed");return r}))})).then((e=>{const t=[];return e.reduce(((e,n)=>e.then((()=>r(n).then((e=>{t.push(e)})).catch((e=>{t.push({receipt:n,code:e.message})}))))),Promise.resolve()).then((()=>t.sort(((e,t)=>e.timestamp?t.timestamp?e.timestamp&&t.timestamp?e.timestamp.getTime()-t.timestamp.getTime():0:-1:1))))}))},DAB:function(t,n,i){return e.file.hashFileOrCheckHash(t,i).then((e=>r(n,e)))},receipt:r}}},8162:(e,t,r)=>{"use strict";var n=r(9509).Buffer;e.exports=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var i=0;i<e.length;i++){var s=e.charAt(i),a=s.charCodeAt(0);if(255!==t[a])throw new TypeError(s+" is ambiguous");t[a]=i}var o=e.length,c=e.charAt(0),l=Math.log(o)/Math.log(256),h=Math.log(256)/Math.log(o);function d(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return n.alloc(0);for(var r=0,i=0,s=0;e[r]===c;)i++,r++;for(var a=(e.length-r)*l+1>>>0,h=new Uint8Array(a);e[r];){var d=t[e.charCodeAt(r)];if(255===d)return;for(var u=0,f=a-1;(0!==d||u<s)&&-1!==f;f--,u++)d+=o*h[f]>>>0,h[f]=d%256>>>0,d=d/256>>>0;if(0!==d)throw new Error("Non-zero carry");s=u,r++}for(var p=a-s;p!==a&&0===h[p];)p++;var b=n.allocUnsafe(i+(a-p));b.fill(0,0,i);for(var g=i;p!==a;)b[g++]=h[p++];return b}return{encode:function(t){if((Array.isArray(t)||t instanceof Uint8Array)&&(t=n.from(t)),!n.isBuffer(t))throw new TypeError("Expected Buffer");if(0===t.length)return"";for(var r=0,i=0,s=0,a=t.length;s!==a&&0===t[s];)s++,r++;for(var l=(a-s)*h+1>>>0,d=new Uint8Array(l);s!==a;){for(var u=t[s],f=0,p=l-1;(0!==u||f<i)&&-1!==p;p--,f++)u+=256*d[p]>>>0,d[p]=u%o>>>0,u=u/o>>>0;if(0!==u)throw new Error("Non-zero carry");i=f,s++}for(var b=l-i;b!==l&&0===d[b];)b++;for(var g=c.repeat(r);b<l;++b)g+=e.charAt(d[b]);return g},decodeUnsafe:d,decode:function(e){var t=d(e);if(t)return t;throw new Error("Non-base"+o+" character")}}}},9742:(e,t)=>{"use strict";t.byteLength=function(e){var t=c(e),r=t[0],n=t[1];return 3*(r+n)/4-n},t.toByteArray=function(e){var t,r,s=c(e),a=s[0],o=s[1],l=new i(function(e,t,r){return 3*(t+r)/4-r}(0,a,o)),h=0,d=o>0?a-4:a;for(r=0;r<d;r+=4)t=n[e.charCodeAt(r)]<<18|n[e.charCodeAt(r+1)]<<12|n[e.charCodeAt(r+2)]<<6|n[e.charCodeAt(r+3)],l[h++]=t>>16&255,l[h++]=t>>8&255,l[h++]=255&t;return 2===o&&(t=n[e.charCodeAt(r)]<<2|n[e.charCodeAt(r+1)]>>4,l[h++]=255&t),1===o&&(t=n[e.charCodeAt(r)]<<10|n[e.charCodeAt(r+1)]<<4|n[e.charCodeAt(r+2)]>>2,l[h++]=t>>8&255,l[h++]=255&t),l},t.fromByteArray=function(e){for(var t,n=e.length,i=n%3,s=[],a=16383,o=0,c=n-i;o<c;o+=a)s.push(l(e,o,o+a>c?c:o+a));return 1===i?(t=e[n-1],s.push(r[t>>2]+r[t<<4&63]+"==")):2===i&&(t=(e[n-2]<<8)+e[n-1],s.push(r[t>>10]+r[t>>4&63]+r[t<<2&63]+"=")),s.join("")};for(var r=[],n=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,o=s.length;a<o;++a)r[a]=s[a],n[s.charCodeAt(a)]=a;function c(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function l(e,t,n){for(var i,s,a=[],o=t;o<n;o+=3)i=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),a.push(r[(s=i)>>18&63]+r[s>>12&63]+r[s>>6&63]+r[63&s]);return a.join("")}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63},2882:e=>{"use strict";for(var t="qpzry9x8gf2tvdw0s3jn54khce6mua7l",r={},n=0;n<t.length;n++){var i=t.charAt(n);if(void 0!==r[i])throw new TypeError(i+" is ambiguous");r[i]=n}function s(e){var t=e>>25;return(33554431&e)<<5^996825010&-(t>>0&1)^642813549&-(t>>1&1)^513874426&-(t>>2&1)^1027748829&-(t>>3&1)^705979059&-(t>>4&1)}function a(e){for(var t=1,r=0;r<e.length;++r){var n=e.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+e+")";t=s(t)^n>>5}for(t=s(t),r=0;r<e.length;++r){var i=e.charCodeAt(r);t=s(t)^31&i}return t}function o(e,t){if(t=t||90,e.length<8)return e+" too short";if(e.length>t)return"Exceeds length limit";var n=e.toLowerCase(),i=e.toUpperCase();if(e!==n&&e!==i)return"Mixed-case string "+e;var o=(e=n).lastIndexOf("1");if(-1===o)return"No separator character for "+e;if(0===o)return"Missing prefix for "+e;var c=e.slice(0,o),l=e.slice(o+1);if(l.length<6)return"Data too short";var h=a(c);if("string"==typeof h)return h;for(var d=[],u=0;u<l.length;++u){var f=l.charAt(u),p=r[f];if(void 0===p)return"Unknown character "+f;h=s(h)^p,u+6>=l.length||d.push(p)}return 1!==h?"Invalid checksum for "+e:{prefix:c,words:d}}function c(e,t,r,n){for(var i=0,s=0,a=(1<<r)-1,o=[],c=0;c<e.length;++c)for(i=i<<t|e[c],s+=t;s>=r;)s-=r,o.push(i>>s&a);if(n)s>0&&o.push(i<<r-s&a);else{if(s>=t)return"Excess padding";if(i<<r-s&a)return"Non-zero padding"}return o}e.exports={decodeUnsafe:function(){var e=o.apply(null,arguments);if("object"==typeof e)return e},decode:function(e){var t=o.apply(null,arguments);if("object"==typeof t)return t;throw new Error(t)},encode:function(e,r,n){if(n=n||90,e.length+7+r.length>n)throw new TypeError("Exceeds length limit");var i=a(e=e.toLowerCase());if("string"==typeof i)throw new Error(i);for(var o=e+"1",c=0;c<r.length;++c){var l=r[c];if(l>>5!=0)throw new Error("Non 5-bit word");i=s(i)^l,o+=t.charAt(l)}for(c=0;c<6;++c)i=s(i);for(i^=1,c=0;c<6;++c)o+=t.charAt(i>>5*(5-c)&31);return o},toWordsUnsafe:function(e){var t=c(e,8,5,!0);if(Array.isArray(t))return t},toWords:function(e){var t=c(e,8,5,!0);if(Array.isArray(t))return t;throw new Error(t)},fromWordsUnsafe:function(e){var t=c(e,5,8,!1);if(Array.isArray(t))return t},fromWords:function(e){var t=c(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}}},3027:(e,t,r)=>{var n=r(9509).Buffer;e.exports={check:function(e){if(e.length<8)return!1;if(e.length>72)return!1;if(48!==e[0])return!1;if(e[1]!==e.length-2)return!1;if(2!==e[2])return!1;var t=e[3];if(0===t)return!1;if(5+t>=e.length)return!1;if(2!==e[4+t])return!1;var r=e[5+t];return!(0===r||6+t+r!==e.length||128&e[4]||t>1&&0===e[4]&&!(128&e[5])||128&e[t+6]||r>1&&0===e[t+6]&&!(128&e[t+7]))},decode:function(e){if(e.length<8)throw new Error("DER sequence length is too short");if(e.length>72)throw new Error("DER sequence length is too long");if(48!==e[0])throw new Error("Expected DER sequence");if(e[1]!==e.length-2)throw new Error("DER sequence length is invalid");if(2!==e[2])throw new Error("Expected DER integer");var t=e[3];if(0===t)throw new Error("R length is zero");if(5+t>=e.length)throw new Error("R length is too long");if(2!==e[4+t])throw new Error("Expected DER integer (2)");var r=e[5+t];if(0===r)throw new Error("S length is zero");if(6+t+r!==e.length)throw new Error("S length is invalid");if(128&e[4])throw new Error("R value is negative");if(t>1&&0===e[4]&&!(128&e[5]))throw new Error("R value excessively padded");if(128&e[t+6])throw new Error("S value is negative");if(r>1&&0===e[t+6]&&!(128&e[t+7]))throw new Error("S value excessively padded");return{r:e.slice(4,4+t),s:e.slice(6+t)}},encode:function(e,t){var r=e.length,i=t.length;if(0===r)throw new Error("R length is zero");if(0===i)throw new Error("S length is zero");if(r>33)throw new Error("R length is too long");if(i>33)throw new Error("S length is too long");if(128&e[0])throw new Error("R value is negative");if(128&t[0])throw new Error("S value is negative");if(r>1&&0===e[0]&&!(128&e[1]))throw new Error("R value excessively padded");if(i>1&&0===t[0]&&!(128&t[1]))throw new Error("S value excessively padded");var s=n.allocUnsafe(6+r+i);return s[0]=48,s[1]=s.length-2,s[2]=2,s[3]=e.length,e.copy(s,4),s[4+r]=2,s[5+r]=t.length,t.copy(s,6+r),s}}},7790:(e,t,r)=>{var n=r(8764).Buffer;const i=r(8334),s=r(2882),a=r(8055),o=r(3482),c=r(7221),l=r(7795),h="p2wpkh",d="p2sh(p2wpkh)";function u(e){return o("sha256").update(e).digest()}function f(e){return o("ripemd160").update(u(e)).digest()}function p(e,t){t=t||"Bitcoin Signed Message:\n",n.isBuffer(t)||(t=n.from(t,"utf8")),n.isBuffer(e)||(e=n.from(e,"utf8"));const r=l.encodingLength(e.length),i=n.allocUnsafe(t.length+r+e.length);return t.copy(i,0),l.encode(e.length,i,t.length),e.copy(i,t.length+r),function(e){return u(u(e))}(i)}function b(e){return f(n.concat([n.from("0014","hex"),e]))}function g(e){const t=s.decode(e),r=s.fromWords(t.words.slice(1));return n.from(r)}e.exports={magicHash:p,sign:function(e,t,r,i,s){"object"==typeof i&&void 0===s&&(s=i,i=void 0);let{segwitType:a,extraEntropy:o}=s||{};if(a&&("string"==typeof a||a instanceof String)&&(a=a.toLowerCase()),a&&a!==d&&a!==h)throw new Error('Unrecognized segwitType: use "p2sh(p2wpkh)" or "p2wpkh"');const l=p(e,i),u=c.sign(l,t,{data:o});return function(e,t,r,i){return void 0!==i?(t+=8,i===h&&(t+=4)):r&&(t+=4),n.concat([n.alloc(1,t+27),e])}(u.signature,u.recovery,r,a)},verify:function(e,t,r,s,o){n.isBuffer(r)||(r=n.from(r,"base64"));const l=function(e){if(65!==e.length)throw new Error("Invalid signature length");const t=e.readUInt8(0)-27;if(t>15||t<0)throw new Error("Invalid signature parameter");return{compressed:!!(12&t),segwitType:8&t?4&t?h:d:null,recovery:3&t,signature:e.slice(1)}}(r);if(o&&!l.compressed)throw new Error("checkSegwitAlways can only be used with a compressed pubkey signature flagbyte");const u=p(e,s),m=f(c.recover(u,l.signature,l.recovery,l.compressed));let _,y;if(l.segwitType)l.segwitType===d?(_=b(m),y=i.decode(t).slice(1)):l.segwitType===h&&(_=m,y=g(t));else if(o)try{return y=g(t),a(m,y)}catch(e){const r=b(m);return y=i.decode(t).slice(1),a(m,y)||a(r,y)}else _=m,y=i.decode(t).slice(1);return a(_,y)}}},3550:function(e,t,r){!function(e,t){"use strict";function n(e,t){if(!e)throw new Error(t||"Assertion failed")}function i(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}function s(e,t,r){if(s.isBN(e))return e;this.negative=0,this.words=null,this.length=0,this.red=null,null!==e&&("le"!==t&&"be"!==t||(r=t,t=10),this._init(e||0,t||10,r||"be"))}var a;"object"==typeof e?e.exports=s:t.BN=s,s.BN=s,s.wordSize=26;try{a="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:r(6601).Buffer}catch(e){}function o(e,t){var r=e.charCodeAt(t);return r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:r-48&15}function c(e,t,r){var n=o(e,r);return r-1>=t&&(n|=o(e,r-1)<<4),n}function l(e,t,r,n){for(var i=0,s=Math.min(e.length,r),a=t;a<s;a++){var o=e.charCodeAt(a)-48;i*=n,i+=o>=49?o-49+10:o>=17?o-17+10:o}return i}s.isBN=function(e){return e instanceof s||null!==e&&"object"==typeof e&&e.constructor.wordSize===s.wordSize&&Array.isArray(e.words)},s.max=function(e,t){return e.cmp(t)>0?e:t},s.min=function(e,t){return e.cmp(t)<0?e:t},s.prototype._init=function(e,t,r){if("number"==typeof e)return this._initNumber(e,t,r);if("object"==typeof e)return this._initArray(e,t,r);"hex"===t&&(t=16),n(t===(0|t)&&t>=2&&t<=36);var i=0;"-"===(e=e.toString().replace(/\s+/g,""))[0]&&(i++,this.negative=1),i<e.length&&(16===t?this._parseHex(e,i,r):(this._parseBase(e,t,i),"le"===r&&this._initArray(this.toArray(),t,r)))},s.prototype._initNumber=function(e,t,r){e<0&&(this.negative=1,e=-e),e<67108864?(this.words=[67108863&e],this.length=1):e<4503599627370496?(this.words=[67108863&e,e/67108864&67108863],this.length=2):(n(e<9007199254740992),this.words=[67108863&e,e/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),t,r)},s.prototype._initArray=function(e,t,r){if(n("number"==typeof e.length),e.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(e.length/3),this.words=new Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var s,a,o=0;if("be"===r)for(i=e.length-1,s=0;i>=0;i-=3)a=e[i]|e[i-1]<<8|e[i-2]<<16,this.words[s]|=a<<o&67108863,this.words[s+1]=a>>>26-o&67108863,(o+=24)>=26&&(o-=26,s++);else if("le"===r)for(i=0,s=0;i<e.length;i+=3)a=e[i]|e[i+1]<<8|e[i+2]<<16,this.words[s]|=a<<o&67108863,this.words[s+1]=a>>>26-o&67108863,(o+=24)>=26&&(o-=26,s++);return this.strip()},s.prototype._parseHex=function(e,t,r){this.length=Math.ceil((e.length-t)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var i,s=0,a=0;if("be"===r)for(n=e.length-1;n>=t;n-=2)i=c(e,t,n)<<s,this.words[a]|=67108863&i,s>=18?(s-=18,a+=1,this.words[a]|=i>>>26):s+=8;else for(n=(e.length-t)%2==0?t+1:t;n<e.length;n+=2)i=c(e,t,n)<<s,this.words[a]|=67108863&i,s>=18?(s-=18,a+=1,this.words[a]|=i>>>26):s+=8;this.strip()},s.prototype._parseBase=function(e,t,r){this.words=[0],this.length=1;for(var n=0,i=1;i<=67108863;i*=t)n++;n--,i=i/t|0;for(var s=e.length-r,a=s%n,o=Math.min(s,s-a)+r,c=0,h=r;h<o;h+=n)c=l(e,h,h+n,t),this.imuln(i),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(0!==a){var d=1;for(c=l(e,h,e.length,t),h=0;h<a;h++)d*=t;this.imuln(d),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c)}this.strip()},s.prototype.copy=function(e){e.words=new Array(this.length);for(var t=0;t<this.length;t++)e.words[t]=this.words[t];e.length=this.length,e.negative=this.negative,e.red=this.red},s.prototype.clone=function(){var e=new s(null);return this.copy(e),e},s.prototype._expand=function(e){for(;this.length<e;)this.words[this.length++]=0;return this},s.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},s.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},s.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var h=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],d=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],u=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function f(e,t,r){r.negative=t.negative^e.negative;var n=e.length+t.length|0;r.length=n,n=n-1|0;var i=0|e.words[0],s=0|t.words[0],a=i*s,o=67108863&a,c=a/67108864|0;r.words[0]=o;for(var l=1;l<n;l++){for(var h=c>>>26,d=67108863&c,u=Math.min(l,t.length-1),f=Math.max(0,l-e.length+1);f<=u;f++){var p=l-f|0;h+=(a=(i=0|e.words[p])*(s=0|t.words[f])+d)/67108864|0,d=67108863&a}r.words[l]=0|d,c=0|h}return 0!==c?r.words[l]=0|c:r.length--,r.strip()}s.prototype.toString=function(e,t){var r;if(t=0|t||1,16===(e=e||10)||"hex"===e){r="";for(var i=0,s=0,a=0;a<this.length;a++){var o=this.words[a],c=(16777215&(o<<i|s)).toString(16);r=0!=(s=o>>>24-i&16777215)||a!==this.length-1?h[6-c.length]+c+r:c+r,(i+=2)>=26&&(i-=26,a--)}for(0!==s&&(r=s.toString(16)+r);r.length%t!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(e===(0|e)&&e>=2&&e<=36){var l=d[e],f=u[e];r="";var p=this.clone();for(p.negative=0;!p.isZero();){var b=p.modn(f).toString(e);r=(p=p.idivn(f)).isZero()?b+r:h[l-b.length]+b+r}for(this.isZero()&&(r="0"+r);r.length%t!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}n(!1,"Base should be between 2 and 36")},s.prototype.toNumber=function(){var e=this.words[0];return 2===this.length?e+=67108864*this.words[1]:3===this.length&&1===this.words[2]?e+=4503599627370496+67108864*this.words[1]:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-e:e},s.prototype.toJSON=function(){return this.toString(16)},s.prototype.toBuffer=function(e,t){return n(void 0!==a),this.toArrayLike(a,e,t)},s.prototype.toArray=function(e,t){return this.toArrayLike(Array,e,t)},s.prototype.toArrayLike=function(e,t,r){var i=this.byteLength(),s=r||Math.max(1,i);n(i<=s,"byte array longer than desired length"),n(s>0,"Requested array length <= 0"),this.strip();var a,o,c="le"===t,l=new e(s),h=this.clone();if(c){for(o=0;!h.isZero();o++)a=h.andln(255),h.iushrn(8),l[o]=a;for(;o<s;o++)l[o]=0}else{for(o=0;o<s-i;o++)l[o]=0;for(o=0;!h.isZero();o++)a=h.andln(255),h.iushrn(8),l[s-o-1]=a}return l},Math.clz32?s.prototype._countBits=function(e){return 32-Math.clz32(e)}:s.prototype._countBits=function(e){var t=e,r=0;return t>=4096&&(r+=13,t>>>=13),t>=64&&(r+=7,t>>>=7),t>=8&&(r+=4,t>>>=4),t>=2&&(r+=2,t>>>=2),r+t},s.prototype._zeroBits=function(e){if(0===e)return 26;var t=e,r=0;return 0==(8191&t)&&(r+=13,t>>>=13),0==(127&t)&&(r+=7,t>>>=7),0==(15&t)&&(r+=4,t>>>=4),0==(3&t)&&(r+=2,t>>>=2),0==(1&t)&&r++,r},s.prototype.bitLength=function(){var e=this.words[this.length-1],t=this._countBits(e);return 26*(this.length-1)+t},s.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,t=0;t<this.length;t++){var r=this._zeroBits(this.words[t]);if(e+=r,26!==r)break}return e},s.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},s.prototype.toTwos=function(e){return 0!==this.negative?this.abs().inotn(e).iaddn(1):this.clone()},s.prototype.fromTwos=function(e){return this.testn(e-1)?this.notn(e).iaddn(1).ineg():this.clone()},s.prototype.isNeg=function(){return 0!==this.negative},s.prototype.neg=function(){return this.clone().ineg()},s.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},s.prototype.iuor=function(e){for(;this.length<e.length;)this.words[this.length++]=0;for(var t=0;t<e.length;t++)this.words[t]=this.words[t]|e.words[t];return this.strip()},s.prototype.ior=function(e){return n(0==(this.negative|e.negative)),this.iuor(e)},s.prototype.or=function(e){return this.length>e.length?this.clone().ior(e):e.clone().ior(this)},s.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},s.prototype.iuand=function(e){var t;t=this.length>e.length?e:this;for(var r=0;r<t.length;r++)this.words[r]=this.words[r]&e.words[r];return this.length=t.length,this.strip()},s.prototype.iand=function(e){return n(0==(this.negative|e.negative)),this.iuand(e)},s.prototype.and=function(e){return this.length>e.length?this.clone().iand(e):e.clone().iand(this)},s.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},s.prototype.iuxor=function(e){var t,r;this.length>e.length?(t=this,r=e):(t=e,r=this);for(var n=0;n<r.length;n++)this.words[n]=t.words[n]^r.words[n];if(this!==t)for(;n<t.length;n++)this.words[n]=t.words[n];return this.length=t.length,this.strip()},s.prototype.ixor=function(e){return n(0==(this.negative|e.negative)),this.iuxor(e)},s.prototype.xor=function(e){return this.length>e.length?this.clone().ixor(e):e.clone().ixor(this)},s.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},s.prototype.inotn=function(e){n("number"==typeof e&&e>=0);var t=0|Math.ceil(e/26),r=e%26;this._expand(t),r>0&&t--;for(var i=0;i<t;i++)this.words[i]=67108863&~this.words[i];return r>0&&(this.words[i]=~this.words[i]&67108863>>26-r),this.strip()},s.prototype.notn=function(e){return this.clone().inotn(e)},s.prototype.setn=function(e,t){n("number"==typeof e&&e>=0);var r=e/26|0,i=e%26;return this._expand(r+1),this.words[r]=t?this.words[r]|1<<i:this.words[r]&~(1<<i),this.strip()},s.prototype.iadd=function(e){var t,r,n;if(0!==this.negative&&0===e.negative)return this.negative=0,t=this.isub(e),this.negative^=1,this._normSign();if(0===this.negative&&0!==e.negative)return e.negative=0,t=this.isub(e),e.negative=1,t._normSign();this.length>e.length?(r=this,n=e):(r=e,n=this);for(var i=0,s=0;s<n.length;s++)t=(0|r.words[s])+(0|n.words[s])+i,this.words[s]=67108863&t,i=t>>>26;for(;0!==i&&s<r.length;s++)t=(0|r.words[s])+i,this.words[s]=67108863&t,i=t>>>26;if(this.length=r.length,0!==i)this.words[this.length]=i,this.length++;else if(r!==this)for(;s<r.length;s++)this.words[s]=r.words[s];return this},s.prototype.add=function(e){var t;return 0!==e.negative&&0===this.negative?(e.negative=0,t=this.sub(e),e.negative^=1,t):0===e.negative&&0!==this.negative?(this.negative=0,t=e.sub(this),this.negative=1,t):this.length>e.length?this.clone().iadd(e):e.clone().iadd(this)},s.prototype.isub=function(e){if(0!==e.negative){e.negative=0;var t=this.iadd(e);return e.negative=1,t._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(e),this.negative=1,this._normSign();var r,n,i=this.cmp(e);if(0===i)return this.negative=0,this.length=1,this.words[0]=0,this;i>0?(r=this,n=e):(r=e,n=this);for(var s=0,a=0;a<n.length;a++)s=(t=(0|r.words[a])-(0|n.words[a])+s)>>26,this.words[a]=67108863&t;for(;0!==s&&a<r.length;a++)s=(t=(0|r.words[a])+s)>>26,this.words[a]=67108863&t;if(0===s&&a<r.length&&r!==this)for(;a<r.length;a++)this.words[a]=r.words[a];return this.length=Math.max(this.length,a),r!==this&&(this.negative=1),this.strip()},s.prototype.sub=function(e){return this.clone().isub(e)};var p=function(e,t,r){var n,i,s,a=e.words,o=t.words,c=r.words,l=0,h=0|a[0],d=8191&h,u=h>>>13,f=0|a[1],p=8191&f,b=f>>>13,g=0|a[2],m=8191&g,_=g>>>13,y=0|a[3],v=8191&y,w=y>>>13,A=0|a[4],S=8191&A,E=A>>>13,x=0|a[5],C=8191&x,k=x>>>13,M=0|a[6],P=8191&M,I=M>>>13,R=0|a[7],T=8191&R,L=R>>>13,F=0|a[8],O=8191&F,D=F>>>13,N=0|a[9],B=8191&N,j=N>>>13,U=0|o[0],q=8191&U,z=U>>>13,W=0|o[1],H=8191&W,V=W>>>13,G=0|o[2],Y=8191&G,K=G>>>13,$=0|o[3],X=8191&$,J=$>>>13,Q=0|o[4],Z=8191&Q,ee=Q>>>13,te=0|o[5],re=8191&te,ne=te>>>13,ie=0|o[6],se=8191&ie,ae=ie>>>13,oe=0|o[7],ce=8191&oe,le=oe>>>13,he=0|o[8],de=8191&he,ue=he>>>13,fe=0|o[9],pe=8191&fe,be=fe>>>13;r.negative=e.negative^t.negative,r.length=19;var ge=(l+(n=Math.imul(d,q))|0)+((8191&(i=(i=Math.imul(d,z))+Math.imul(u,q)|0))<<13)|0;l=((s=Math.imul(u,z))+(i>>>13)|0)+(ge>>>26)|0,ge&=67108863,n=Math.imul(p,q),i=(i=Math.imul(p,z))+Math.imul(b,q)|0,s=Math.imul(b,z);var me=(l+(n=n+Math.imul(d,H)|0)|0)+((8191&(i=(i=i+Math.imul(d,V)|0)+Math.imul(u,H)|0))<<13)|0;l=((s=s+Math.imul(u,V)|0)+(i>>>13)|0)+(me>>>26)|0,me&=67108863,n=Math.imul(m,q),i=(i=Math.imul(m,z))+Math.imul(_,q)|0,s=Math.imul(_,z),n=n+Math.imul(p,H)|0,i=(i=i+Math.imul(p,V)|0)+Math.imul(b,H)|0,s=s+Math.imul(b,V)|0;var _e=(l+(n=n+Math.imul(d,Y)|0)|0)+((8191&(i=(i=i+Math.imul(d,K)|0)+Math.imul(u,Y)|0))<<13)|0;l=((s=s+Math.imul(u,K)|0)+(i>>>13)|0)+(_e>>>26)|0,_e&=67108863,n=Math.imul(v,q),i=(i=Math.imul(v,z))+Math.imul(w,q)|0,s=Math.imul(w,z),n=n+Math.imul(m,H)|0,i=(i=i+Math.imul(m,V)|0)+Math.imul(_,H)|0,s=s+Math.imul(_,V)|0,n=n+Math.imul(p,Y)|0,i=(i=i+Math.imul(p,K)|0)+Math.imul(b,Y)|0,s=s+Math.imul(b,K)|0;var ye=(l+(n=n+Math.imul(d,X)|0)|0)+((8191&(i=(i=i+Math.imul(d,J)|0)+Math.imul(u,X)|0))<<13)|0;l=((s=s+Math.imul(u,J)|0)+(i>>>13)|0)+(ye>>>26)|0,ye&=67108863,n=Math.imul(S,q),i=(i=Math.imul(S,z))+Math.imul(E,q)|0,s=Math.imul(E,z),n=n+Math.imul(v,H)|0,i=(i=i+Math.imul(v,V)|0)+Math.imul(w,H)|0,s=s+Math.imul(w,V)|0,n=n+Math.imul(m,Y)|0,i=(i=i+Math.imul(m,K)|0)+Math.imul(_,Y)|0,s=s+Math.imul(_,K)|0,n=n+Math.imul(p,X)|0,i=(i=i+Math.imul(p,J)|0)+Math.imul(b,X)|0,s=s+Math.imul(b,J)|0;var ve=(l+(n=n+Math.imul(d,Z)|0)|0)+((8191&(i=(i=i+Math.imul(d,ee)|0)+Math.imul(u,Z)|0))<<13)|0;l=((s=s+Math.imul(u,ee)|0)+(i>>>13)|0)+(ve>>>26)|0,ve&=67108863,n=Math.imul(C,q),i=(i=Math.imul(C,z))+Math.imul(k,q)|0,s=Math.imul(k,z),n=n+Math.imul(S,H)|0,i=(i=i+Math.imul(S,V)|0)+Math.imul(E,H)|0,s=s+Math.imul(E,V)|0,n=n+Math.imul(v,Y)|0,i=(i=i+Math.imul(v,K)|0)+Math.imul(w,Y)|0,s=s+Math.imul(w,K)|0,n=n+Math.imul(m,X)|0,i=(i=i+Math.imul(m,J)|0)+Math.imul(_,X)|0,s=s+Math.imul(_,J)|0,n=n+Math.imul(p,Z)|0,i=(i=i+Math.imul(p,ee)|0)+Math.imul(b,Z)|0,s=s+Math.imul(b,ee)|0;var we=(l+(n=n+Math.imul(d,re)|0)|0)+((8191&(i=(i=i+Math.imul(d,ne)|0)+Math.imul(u,re)|0))<<13)|0;l=((s=s+Math.imul(u,ne)|0)+(i>>>13)|0)+(we>>>26)|0,we&=67108863,n=Math.imul(P,q),i=(i=Math.imul(P,z))+Math.imul(I,q)|0,s=Math.imul(I,z),n=n+Math.imul(C,H)|0,i=(i=i+Math.imul(C,V)|0)+Math.imul(k,H)|0,s=s+Math.imul(k,V)|0,n=n+Math.imul(S,Y)|0,i=(i=i+Math.imul(S,K)|0)+Math.imul(E,Y)|0,s=s+Math.imul(E,K)|0,n=n+Math.imul(v,X)|0,i=(i=i+Math.imul(v,J)|0)+Math.imul(w,X)|0,s=s+Math.imul(w,J)|0,n=n+Math.imul(m,Z)|0,i=(i=i+Math.imul(m,ee)|0)+Math.imul(_,Z)|0,s=s+Math.imul(_,ee)|0,n=n+Math.imul(p,re)|0,i=(i=i+Math.imul(p,ne)|0)+Math.imul(b,re)|0,s=s+Math.imul(b,ne)|0;var Ae=(l+(n=n+Math.imul(d,se)|0)|0)+((8191&(i=(i=i+Math.imul(d,ae)|0)+Math.imul(u,se)|0))<<13)|0;l=((s=s+Math.imul(u,ae)|0)+(i>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,n=Math.imul(T,q),i=(i=Math.imul(T,z))+Math.imul(L,q)|0,s=Math.imul(L,z),n=n+Math.imul(P,H)|0,i=(i=i+Math.imul(P,V)|0)+Math.imul(I,H)|0,s=s+Math.imul(I,V)|0,n=n+Math.imul(C,Y)|0,i=(i=i+Math.imul(C,K)|0)+Math.imul(k,Y)|0,s=s+Math.imul(k,K)|0,n=n+Math.imul(S,X)|0,i=(i=i+Math.imul(S,J)|0)+Math.imul(E,X)|0,s=s+Math.imul(E,J)|0,n=n+Math.imul(v,Z)|0,i=(i=i+Math.imul(v,ee)|0)+Math.imul(w,Z)|0,s=s+Math.imul(w,ee)|0,n=n+Math.imul(m,re)|0,i=(i=i+Math.imul(m,ne)|0)+Math.imul(_,re)|0,s=s+Math.imul(_,ne)|0,n=n+Math.imul(p,se)|0,i=(i=i+Math.imul(p,ae)|0)+Math.imul(b,se)|0,s=s+Math.imul(b,ae)|0;var Se=(l+(n=n+Math.imul(d,ce)|0)|0)+((8191&(i=(i=i+Math.imul(d,le)|0)+Math.imul(u,ce)|0))<<13)|0;l=((s=s+Math.imul(u,le)|0)+(i>>>13)|0)+(Se>>>26)|0,Se&=67108863,n=Math.imul(O,q),i=(i=Math.imul(O,z))+Math.imul(D,q)|0,s=Math.imul(D,z),n=n+Math.imul(T,H)|0,i=(i=i+Math.imul(T,V)|0)+Math.imul(L,H)|0,s=s+Math.imul(L,V)|0,n=n+Math.imul(P,Y)|0,i=(i=i+Math.imul(P,K)|0)+Math.imul(I,Y)|0,s=s+Math.imul(I,K)|0,n=n+Math.imul(C,X)|0,i=(i=i+Math.imul(C,J)|0)+Math.imul(k,X)|0,s=s+Math.imul(k,J)|0,n=n+Math.imul(S,Z)|0,i=(i=i+Math.imul(S,ee)|0)+Math.imul(E,Z)|0,s=s+Math.imul(E,ee)|0,n=n+Math.imul(v,re)|0,i=(i=i+Math.imul(v,ne)|0)+Math.imul(w,re)|0,s=s+Math.imul(w,ne)|0,n=n+Math.imul(m,se)|0,i=(i=i+Math.imul(m,ae)|0)+Math.imul(_,se)|0,s=s+Math.imul(_,ae)|0,n=n+Math.imul(p,ce)|0,i=(i=i+Math.imul(p,le)|0)+Math.imul(b,ce)|0,s=s+Math.imul(b,le)|0;var Ee=(l+(n=n+Math.imul(d,de)|0)|0)+((8191&(i=(i=i+Math.imul(d,ue)|0)+Math.imul(u,de)|0))<<13)|0;l=((s=s+Math.imul(u,ue)|0)+(i>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,n=Math.imul(B,q),i=(i=Math.imul(B,z))+Math.imul(j,q)|0,s=Math.imul(j,z),n=n+Math.imul(O,H)|0,i=(i=i+Math.imul(O,V)|0)+Math.imul(D,H)|0,s=s+Math.imul(D,V)|0,n=n+Math.imul(T,Y)|0,i=(i=i+Math.imul(T,K)|0)+Math.imul(L,Y)|0,s=s+Math.imul(L,K)|0,n=n+Math.imul(P,X)|0,i=(i=i+Math.imul(P,J)|0)+Math.imul(I,X)|0,s=s+Math.imul(I,J)|0,n=n+Math.imul(C,Z)|0,i=(i=i+Math.imul(C,ee)|0)+Math.imul(k,Z)|0,s=s+Math.imul(k,ee)|0,n=n+Math.imul(S,re)|0,i=(i=i+Math.imul(S,ne)|0)+Math.imul(E,re)|0,s=s+Math.imul(E,ne)|0,n=n+Math.imul(v,se)|0,i=(i=i+Math.imul(v,ae)|0)+Math.imul(w,se)|0,s=s+Math.imul(w,ae)|0,n=n+Math.imul(m,ce)|0,i=(i=i+Math.imul(m,le)|0)+Math.imul(_,ce)|0,s=s+Math.imul(_,le)|0,n=n+Math.imul(p,de)|0,i=(i=i+Math.imul(p,ue)|0)+Math.imul(b,de)|0,s=s+Math.imul(b,ue)|0;var xe=(l+(n=n+Math.imul(d,pe)|0)|0)+((8191&(i=(i=i+Math.imul(d,be)|0)+Math.imul(u,pe)|0))<<13)|0;l=((s=s+Math.imul(u,be)|0)+(i>>>13)|0)+(xe>>>26)|0,xe&=67108863,n=Math.imul(B,H),i=(i=Math.imul(B,V))+Math.imul(j,H)|0,s=Math.imul(j,V),n=n+Math.imul(O,Y)|0,i=(i=i+Math.imul(O,K)|0)+Math.imul(D,Y)|0,s=s+Math.imul(D,K)|0,n=n+Math.imul(T,X)|0,i=(i=i+Math.imul(T,J)|0)+Math.imul(L,X)|0,s=s+Math.imul(L,J)|0,n=n+Math.imul(P,Z)|0,i=(i=i+Math.imul(P,ee)|0)+Math.imul(I,Z)|0,s=s+Math.imul(I,ee)|0,n=n+Math.imul(C,re)|0,i=(i=i+Math.imul(C,ne)|0)+Math.imul(k,re)|0,s=s+Math.imul(k,ne)|0,n=n+Math.imul(S,se)|0,i=(i=i+Math.imul(S,ae)|0)+Math.imul(E,se)|0,s=s+Math.imul(E,ae)|0,n=n+Math.imul(v,ce)|0,i=(i=i+Math.imul(v,le)|0)+Math.imul(w,ce)|0,s=s+Math.imul(w,le)|0,n=n+Math.imul(m,de)|0,i=(i=i+Math.imul(m,ue)|0)+Math.imul(_,de)|0,s=s+Math.imul(_,ue)|0;var Ce=(l+(n=n+Math.imul(p,pe)|0)|0)+((8191&(i=(i=i+Math.imul(p,be)|0)+Math.imul(b,pe)|0))<<13)|0;l=((s=s+Math.imul(b,be)|0)+(i>>>13)|0)+(Ce>>>26)|0,Ce&=67108863,n=Math.imul(B,Y),i=(i=Math.imul(B,K))+Math.imul(j,Y)|0,s=Math.imul(j,K),n=n+Math.imul(O,X)|0,i=(i=i+Math.imul(O,J)|0)+Math.imul(D,X)|0,s=s+Math.imul(D,J)|0,n=n+Math.imul(T,Z)|0,i=(i=i+Math.imul(T,ee)|0)+Math.imul(L,Z)|0,s=s+Math.imul(L,ee)|0,n=n+Math.imul(P,re)|0,i=(i=i+Math.imul(P,ne)|0)+Math.imul(I,re)|0,s=s+Math.imul(I,ne)|0,n=n+Math.imul(C,se)|0,i=(i=i+Math.imul(C,ae)|0)+Math.imul(k,se)|0,s=s+Math.imul(k,ae)|0,n=n+Math.imul(S,ce)|0,i=(i=i+Math.imul(S,le)|0)+Math.imul(E,ce)|0,s=s+Math.imul(E,le)|0,n=n+Math.imul(v,de)|0,i=(i=i+Math.imul(v,ue)|0)+Math.imul(w,de)|0,s=s+Math.imul(w,ue)|0;var ke=(l+(n=n+Math.imul(m,pe)|0)|0)+((8191&(i=(i=i+Math.imul(m,be)|0)+Math.imul(_,pe)|0))<<13)|0;l=((s=s+Math.imul(_,be)|0)+(i>>>13)|0)+(ke>>>26)|0,ke&=67108863,n=Math.imul(B,X),i=(i=Math.imul(B,J))+Math.imul(j,X)|0,s=Math.imul(j,J),n=n+Math.imul(O,Z)|0,i=(i=i+Math.imul(O,ee)|0)+Math.imul(D,Z)|0,s=s+Math.imul(D,ee)|0,n=n+Math.imul(T,re)|0,i=(i=i+Math.imul(T,ne)|0)+Math.imul(L,re)|0,s=s+Math.imul(L,ne)|0,n=n+Math.imul(P,se)|0,i=(i=i+Math.imul(P,ae)|0)+Math.imul(I,se)|0,s=s+Math.imul(I,ae)|0,n=n+Math.imul(C,ce)|0,i=(i=i+Math.imul(C,le)|0)+Math.imul(k,ce)|0,s=s+Math.imul(k,le)|0,n=n+Math.imul(S,de)|0,i=(i=i+Math.imul(S,ue)|0)+Math.imul(E,de)|0,s=s+Math.imul(E,ue)|0;var Me=(l+(n=n+Math.imul(v,pe)|0)|0)+((8191&(i=(i=i+Math.imul(v,be)|0)+Math.imul(w,pe)|0))<<13)|0;l=((s=s+Math.imul(w,be)|0)+(i>>>13)|0)+(Me>>>26)|0,Me&=67108863,n=Math.imul(B,Z),i=(i=Math.imul(B,ee))+Math.imul(j,Z)|0,s=Math.imul(j,ee),n=n+Math.imul(O,re)|0,i=(i=i+Math.imul(O,ne)|0)+Math.imul(D,re)|0,s=s+Math.imul(D,ne)|0,n=n+Math.imul(T,se)|0,i=(i=i+Math.imul(T,ae)|0)+Math.imul(L,se)|0,s=s+Math.imul(L,ae)|0,n=n+Math.imul(P,ce)|0,i=(i=i+Math.imul(P,le)|0)+Math.imul(I,ce)|0,s=s+Math.imul(I,le)|0,n=n+Math.imul(C,de)|0,i=(i=i+Math.imul(C,ue)|0)+Math.imul(k,de)|0,s=s+Math.imul(k,ue)|0;var Pe=(l+(n=n+Math.imul(S,pe)|0)|0)+((8191&(i=(i=i+Math.imul(S,be)|0)+Math.imul(E,pe)|0))<<13)|0;l=((s=s+Math.imul(E,be)|0)+(i>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,n=Math.imul(B,re),i=(i=Math.imul(B,ne))+Math.imul(j,re)|0,s=Math.imul(j,ne),n=n+Math.imul(O,se)|0,i=(i=i+Math.imul(O,ae)|0)+Math.imul(D,se)|0,s=s+Math.imul(D,ae)|0,n=n+Math.imul(T,ce)|0,i=(i=i+Math.imul(T,le)|0)+Math.imul(L,ce)|0,s=s+Math.imul(L,le)|0,n=n+Math.imul(P,de)|0,i=(i=i+Math.imul(P,ue)|0)+Math.imul(I,de)|0,s=s+Math.imul(I,ue)|0;var Ie=(l+(n=n+Math.imul(C,pe)|0)|0)+((8191&(i=(i=i+Math.imul(C,be)|0)+Math.imul(k,pe)|0))<<13)|0;l=((s=s+Math.imul(k,be)|0)+(i>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,n=Math.imul(B,se),i=(i=Math.imul(B,ae))+Math.imul(j,se)|0,s=Math.imul(j,ae),n=n+Math.imul(O,ce)|0,i=(i=i+Math.imul(O,le)|0)+Math.imul(D,ce)|0,s=s+Math.imul(D,le)|0,n=n+Math.imul(T,de)|0,i=(i=i+Math.imul(T,ue)|0)+Math.imul(L,de)|0,s=s+Math.imul(L,ue)|0;var Re=(l+(n=n+Math.imul(P,pe)|0)|0)+((8191&(i=(i=i+Math.imul(P,be)|0)+Math.imul(I,pe)|0))<<13)|0;l=((s=s+Math.imul(I,be)|0)+(i>>>13)|0)+(Re>>>26)|0,Re&=67108863,n=Math.imul(B,ce),i=(i=Math.imul(B,le))+Math.imul(j,ce)|0,s=Math.imul(j,le),n=n+Math.imul(O,de)|0,i=(i=i+Math.imul(O,ue)|0)+Math.imul(D,de)|0,s=s+Math.imul(D,ue)|0;var Te=(l+(n=n+Math.imul(T,pe)|0)|0)+((8191&(i=(i=i+Math.imul(T,be)|0)+Math.imul(L,pe)|0))<<13)|0;l=((s=s+Math.imul(L,be)|0)+(i>>>13)|0)+(Te>>>26)|0,Te&=67108863,n=Math.imul(B,de),i=(i=Math.imul(B,ue))+Math.imul(j,de)|0,s=Math.imul(j,ue);var Le=(l+(n=n+Math.imul(O,pe)|0)|0)+((8191&(i=(i=i+Math.imul(O,be)|0)+Math.imul(D,pe)|0))<<13)|0;l=((s=s+Math.imul(D,be)|0)+(i>>>13)|0)+(Le>>>26)|0,Le&=67108863;var Fe=(l+(n=Math.imul(B,pe))|0)+((8191&(i=(i=Math.imul(B,be))+Math.imul(j,pe)|0))<<13)|0;return l=((s=Math.imul(j,be))+(i>>>13)|0)+(Fe>>>26)|0,Fe&=67108863,c[0]=ge,c[1]=me,c[2]=_e,c[3]=ye,c[4]=ve,c[5]=we,c[6]=Ae,c[7]=Se,c[8]=Ee,c[9]=xe,c[10]=Ce,c[11]=ke,c[12]=Me,c[13]=Pe,c[14]=Ie,c[15]=Re,c[16]=Te,c[17]=Le,c[18]=Fe,0!==l&&(c[19]=l,r.length++),r};function b(e,t,r){return(new g).mulp(e,t,r)}function g(e,t){this.x=e,this.y=t}Math.imul||(p=f),s.prototype.mulTo=function(e,t){var r,n=this.length+e.length;return r=10===this.length&&10===e.length?p(this,e,t):n<63?f(this,e,t):n<1024?function(e,t,r){r.negative=t.negative^e.negative,r.length=e.length+t.length;for(var n=0,i=0,s=0;s<r.length-1;s++){var a=i;i=0;for(var o=67108863&n,c=Math.min(s,t.length-1),l=Math.max(0,s-e.length+1);l<=c;l++){var h=s-l,d=(0|e.words[h])*(0|t.words[l]),u=67108863&d;o=67108863&(u=u+o|0),i+=(a=(a=a+(d/67108864|0)|0)+(u>>>26)|0)>>>26,a&=67108863}r.words[s]=o,n=a,a=i}return 0!==n?r.words[s]=n:r.length--,r.strip()}(this,e,t):b(this,e,t),r},g.prototype.makeRBT=function(e){for(var t=new Array(e),r=s.prototype._countBits(e)-1,n=0;n<e;n++)t[n]=this.revBin(n,r,e);return t},g.prototype.revBin=function(e,t,r){if(0===e||e===r-1)return e;for(var n=0,i=0;i<t;i++)n|=(1&e)<<t-i-1,e>>=1;return n},g.prototype.permute=function(e,t,r,n,i,s){for(var a=0;a<s;a++)n[a]=t[e[a]],i[a]=r[e[a]]},g.prototype.transform=function(e,t,r,n,i,s){t