UNPKG

@woleet/woleet-weblibs

Version:
1 lines 321 kB
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).woleet=e()}}(function(){return function(){return function e(t,r,n){function i(a,s){if(!r[a]){if(!t[a]){var f="function"==typeof require&&require;if(!s&&f)return f(a,!0);if(o)return o(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var h=r[a]={exports:{}};t[a][0].call(h.exports,function(e){return i(t[a][1][e]||e)},h,h.exports,e,t,r,n)}return r[a].exports}for(var o="function"==typeof require&&require,a=0;a<n.length;a++)i(n[a]);return i}}()({1:[function(e,t,r){"use strict";t.exports=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(function(r,n){var i=new XMLHttpRequest;i.onload=function(){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))})}},{}],2:[function(e,t,r){"use strict";if("undefined"==typeof window)throw new Error("This module is not meant to be used by node");var n=e("./get-json"),i=e("../common/woleet-api")(n);i.crypto=e("./woleet-crypto"),i.file=e("./woleet-hashfile"),i.receipt.validate=e("../common/woleet-chainpoint")(i.crypto),i.signature=e("../common/woleet-signature")(i.identity.get),i.verify=e("../common/woleet-verify")(i),t.exports=i},{"../common/woleet-api":5,"../common/woleet-chainpoint":6,"../common/woleet-signature":7,"../common/woleet-verify":8,"./get-json":1,"./woleet-crypto":3,"./woleet-hashfile":4}],3:[function(e,t,r){(function(r){(function(){"use strict";if("undefined"==typeof _in_worker&&"undefined"==typeof window)throw new Error("This module is not meant to be used by node");var n=function(t){return r=e("crypto-js/core"),e("crypto-js/sha224"),e("crypto-js/sha256"),e("crypto-js/sha384"),e("crypto-js/sha512"),e("crypto-js/lib-typedarrays"),r;var r}(),i=n.lib.WordArray;function o(e){var t=n.algo[e].create(),o={update:function(e,a){var s=void 0;if(e instanceof Uint8Array)s=i.create(e);else if(i.isPrototypeOf(e))s=e;else if(a)switch(a){case"binary":for(var f=e.length,u=new Uint8Array(f),h=0;h<f;h++)u[h]=e.charCodeAt(h);s=i.create(u);break;case"hex":s=n.enc.Hex.parse(e);break;case"utf8":s=e;break;case"base64":default:s=i.create(new r(e,a))}else if(e){if("string"!=typeof e)throw new TypeError;s=e}else s=i.create();return t.update(s),o},digest:function(e){var i=n.enc.Hex.stringify(t.finalize());if(e&&"hex"===e)return i;var o=new r(i,"hex");return e?o.toString(e):o}};return o}function a(e){switch(e){case"sha224":return o("SHA224");case"sha256":return o("SHA256");case"sha384":return o("SHA384");case"sha512":return o("SHA512");default:throw new Error("Hash algorithm not supported")}}t.exports={createHash:a,CryptoJS:n,Buffer:r,sha256:function(){return a("sha256")},sha224:function(){return a("sha224")},sha384:function(){return a("sha384")},sha512:function(){return a("sha512")}}}).call(this)}).call(this,e("buffer").Buffer)},{buffer:20,"crypto-js/core":24,"crypto-js/lib-typedarrays":25,"crypto-js/sha224":26,"crypto-js/sha256":27,"crypto-js/sha384":28,"crypto-js/sha512":29}],4:[function(e,t,r){"use strict";if("undefined"==typeof window)throw new Error("This module is not meant to be used by node");var n,i,o,a=function(e){return/^[a-f0-9]{64}$/i.test(e)},s=e("./woleet-crypto"),f=window,u=f.crypto&&f.crypto.subtle&&f.crypto.subtle.digest,h=(n=document.getElementsByTagName("script"),i=n[n.length-1].src.split("?")[0].split("/").slice(0,-1).join("/")+"/",(o=f.woleet&&f.woleet.workerScriptPath?f.woleet.workerScriptPath:i?i+"woleet-hashfile-worker.min.js":null)?(console.log("Woleet WebLibs' default worker script will be loaded from: ",o),o):(console.error("Cannot find Woleet WebLibs' default worker script woleet-hashfile-worker.min.js"),null));function c(e){var t=new XMLHttpRequest;return new Promise(function(r){t.onload=function(){return r(200===t.status)},t.onerror=function(){return r(!1)},t.open("GET",e,!0),t.send()}).catch(function(){return!1})}function d(e){e||(e=h);var t=!0,r=null,n=null,i={},o="start",a="progress",d="error",l="result",p="cancel",b="skip",g=function(e,t){return i[e]&&i[e](t)},m=function(e){return i[e]},y=function(e){return r=e},v=function(e){return n=e},_="__cancel__",w="__skip__",E=134217728,S=1073741824;function A(e){var t=new Worker(e);this.hash=function(e){return new Promise(function(r,n){var i=!1,s=!1,f=new FileReader;y(function(){i=!0,t.terminate(),f.abort(),t=null,g(p,{file:e}),n(_)}),v(function(){s=!0,f.abort(),t.postMessage({action:"reset"})});var u=e.size,h=0,c=0;t.onmessage=function(p){if(!i){if(p.data.reset)return g(b,{file:e}),void n(w);if(!s){if(p.data.result)return g(l,{result:p.data.result,file:e}),r();if(p.data.error){var y=p.data.error;if(f.abort(),!m(d))return n(new Error(y));g(d,{error:new Error(y),file:e})}else p.data.start?g(o,{start:p.data.start,file:e}):p.data.progress?g(a,{progress:c/u,file:e}):console.trace("Unexpected worker message: ",p);var v,_;c!==u?(h=c,c=(v=c+1048575)>(_=u)?_:v,f.readAsArrayBuffer(e.slice(h,c))):t.postMessage({action:"finalize"})}}},f.onload=function(e){t.postMessage({chunk:e.target.result,action:"update"})},t.postMessage({action:"start"})})},this.worker=t}function M(e,r,n){if(e.size>r){t=!0;var i=new Error("file_too_big_to_be_hashed_without_worker");return m(d)?g(d,{error:i,file:e}):(n(i),!1)}return!0}function I(e){return new Promise(function(t,r){if(M(e,E,r)){var n=0,i=!1,f=!1,u=!1,h=s.sha256(),c=new FileReader;y(function(){i=!0,c.abort(),g(p,{file:e})}),v(function(){f=!0,c.abort(),g(b,{file:e})}),c.onloadstart=function(){i||f||g(o,{start:!0,file:e})},c.onload=function(r){if(!i&&!f){u&&d(r.target.result,r.loaded,r.total);var n=h.digest("hex");g(l,{result:n,file:e}),t()}},c.onprogress=function(t){if(!i&&!f){var r=t.target.result;if(g(a,{progress:t.loaded/t.total,file:e}),!r)return u=!0;d(r,t.loaded,t.total)}},c.onabort=function(){r(i?_:f?w:new Error("Unhandled abort exception"))},c.readAsArrayBuffer(e)}function d(e,t){var r=e.slice(n,t),i=new Uint8Array(r);h.update(i),n=t}})}function x(e){return new Promise(function(t,r){if(M(e,S,r)){var n=!1,s=!1,u=new FileReader;y(function(){n=!0,u.abort(),g(p,{file:e})}),v(function(){s=!0,u.abort(),g(b,{file:e})}),u.onloadstart=function(){n||s||g(o,{start:!0,file:e})},u.onprogress=function(t){n||s||g(a,{progress:t.loaded/t.total,file:e})},u.onload=function(o){if(!n&&!s){var a=o.target.result;f.crypto.subtle.digest("SHA-256",a).then(function(r){if(!n&&!s){var i=new Uint8Array(r).reduce(function(e,t){return e+("00"+t.toString(16)).slice(-2)},"");g(l,{result:i,file:e}),t()}}).catch(function(t){return i[d]?g(d,{error:t,file:e}):r(t)})}},u.onabort=function(){r(n?_:s?w:new Error("Unhandled abort exception"))},u.readAsArrayBuffer(e)}})}this.on=function(e,t){switch(e){case o:case a:case d:case l:case b:case p:i[e]=t;break;default:throw new Error('Invalid event name "'+e+'"')}},this.start=function(r){var n=null;if(!t)throw new Error("not_ready");if(t=!1,!(r instanceof FileList||r instanceof File||Array.isArray(r)&&r.every(function(e){return e instanceof File})))throw new Error("invalid_parameter");(function(){if(!e)return Promise.resolve(!1);var t=c(e),r=c(e.split("/").slice(0,-1).join("/")+"/woleet-crypto.min.js");var n=new Promise(function(e){try{var t=function(e){var t=f.URL||window.webkitURL,r=f.Blob,n=f.Worker;if(!(t&&r&&n&&e))return null;var i=new r([e]);return new n(t.createObjectURL(i))}("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(function(e){return e.every(function(e){return!0===e})})})().then(function(e){return e||console.warn("Failed to load worker."),e}).then(function(i){function o(r,a,s){if(r>=a)return t=!0,n&&n.worker&&(n.worker.terminate(),n.worker=null),Promise.resolve();var f=void 0;return 0===s[r].size?f=I:u&&s[r].size<=S?f=x:i&&s[r].size>E?(n||(n=new A(e)),f=n.hash):f=I,f(s[r]).then(function(){return o(r+1,a,s)}).catch(function(e){if(e===w)return o(r+1,a,s);if(e!==_)throw e})}return r instanceof FileList?o(0,r.length,r):r instanceof File?o(0,1,[r]):o(0,r.length,r)})},this.cancel=function(){r&&(r(),r=null,t=!0)},this.skip=function(){r&&(n(),n=null)},this.isReady=function(){return t}}t.exports={Hasher:d,hashFileOrCheckHash:function(e,t){return new Promise(function(r,n){if(e instanceof File){var i=new d;i.on("result",function(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(e)?r(e):n(new Error("parameter_string_not_a_sha256_hash")):n(new Error("invalid_parameter"))})}}},{"./woleet-crypto":3}],5:[function(e,t,r){"use strict";var n=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],n=!0,i=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(n=(a=s.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){i=!0,o=e}finally{try{!n&&s.return&&s.return()}finally{if(i)throw o}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();t.exports=function(e){var t={receipt:{},identity:{}};function r(e){if(!e||0===Object.keys(e).length)return"";var t=[];for(var r in e)e[r]&&t.push([encodeURIComponent(r),encodeURIComponent(e[r])].join("="));return"?"+t.join("&")}function i(e,t,r,n,i){return"Invalid Date"===r.toString()&&(r=null),{txId:e,confirmations:t,timestamp:r,blockHash:n,opReturn:i}}var o="https://api.woleet.io/v1",a="woleet.io";t.config={setDefaultTransactionProvider:function(e){switch(e){case"blockcypher.com":case"blockstream.info":case"woleet.io":a=e;break;default:a="woleet.io"}},setDefaultWoleetApiUrl:function(e){o=e}},t.transaction={get:function(t){switch(a){case"woleet.io":return e(o+"/bitcoin/transaction/"+t).then(function(e){if(!e.time||!e.confirmations)throw new Error("tx_not_confirmed");return i(e.txid,e.confirmations,new Date(1e3*e.time),e.blockhash,(t=(e.vout||[]).find(function(e){return e.hasOwnProperty("scriptPubKey")&&e.scriptPubKey.hasOwnProperty("asm")&&e.scriptPubKey.asm.startsWith("OP_RETURN")}))?t.scriptPubKey.asm.split(" ")[1]:null);var t}).catch(function(){throw new Error("tx_not_found")});case"blockstream.info":return e("https://blockstream.info/api/tx/"+t).then(function(r){if(!r.status.block_hash)throw new Error("tx_not_confirmed");return e("https://blockstream.info/api/blocks/tip/height").then(function(n){return e("https://blockstream.info/api/block/"+r.status.block_hash).then(function(e){return i(t,n-e.height,new Date(1e3*e.timestamp),e.id,(o=(r.vout||[]).find(function(e){return e.hasOwnProperty("scriptpubkey")&&e.scriptpubkey_asm&&e.scriptpubkey_asm.startsWith("OP_RETURN")}))?o.scriptpubkey_asm.split(" ")[2]:null);var o}).catch(function(e){throw new Error("Failed to get block")})}).catch(function(e){throw new Error("Failed to get current block height")})}).catch(function(e){throw new Error("tx_not_found")});case"blockcypher.com":return e("https://api.blockcypher.com/v1/btc/main/txs/"+t).then(function(e){if(e.error)throw new Error("tx_not_found");if(!e.confirmed||!e.confirmations)throw new Error("tx_not_confirmed");return i(e.hash,e.confirmations,new Date(e.confirmed),e.block_hash,(t=(e.outputs||[]).find(function(e){return e.hasOwnProperty("data_hex")}))?t.data_hex:null);var t}).catch(function(){throw new Error("tx_not_found")})}}};var s={DATA:1,SIGNATURE:2,BOTH:3};return t.anchor={types:s,getAnchorIDs:function(i,a,f){switch(a){case s.SIGNATURE:return e(o+"/anchorids"+r({signedHash:i,size:f})).then(function(e){return e.content||[]}).catch(function(e){throw new Error("http_error")});case s.DATA:return e(o+"/anchorids"+r({hash:i,size:f})).then(function(e){return e.content||[]}).catch(function(e){throw new Error("http_error")});case s.BOTH:default:var u=t.anchor.getAnchorIDs(i,s.SIGNATURE,f),h=t.anchor.getAnchorIDs(i,s.DATA,f);return Promise.all([u,h]).then(function(e){var t=n(e,2),r=t[0],i=t[1];if(r instanceof Error||i instanceof Error)throw new Error("http_error");return[].concat(r,i)})}}},t.receipt.get=function(t){return e(o+"/receipt/"+t).catch(function(e){throw 404===e.code?new Error("not_found"):new Error(e.code)})},t.identity.get=function(t,n,i,o){return e(t+r({pubKey:n,signedIdentity:i,leftData:o})).catch(function(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=function(e){return/^[a-f0-9]{64}$/i.test(e)},t.getJSON=e,t}},{}],6:[function(e,t,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t.exports=function(e){var t="invalid_receipt_format",r="invalid_target_proof",i="invalid_type",o="non_sha256_target_proof_element",a="merkle_root_mismatch",s="invalid_parent_in_proof_element",f="unsupported_algorithm",u=function(e){var t=new RegExp("^[a-f0-9]{"+e+"}$","i");return function(e){return t.test(e)}},h=u(64),c=e.sha224,d=e.sha256,l=e.sha384,p=e.sha512;function b(e){var t=this;this.branches=[],this.target=e,this.add=function(e){t.branches.push(e)},this.is_valid=function(e){var r=t.target;if(!t.branches.length)return!1;for(var n,i=0;i<t.branches.length;i++){if(r!==(n=t.branches[i]).left&&r!==n.right)return!1;r=n.parent}return r.toLowerCase()===e.toLowerCase()},this.getJSON=function(){return t.branches.map(function(e){return e.getJSON()})}}function g(e){for(var t=arguments.length,r=Array(t>1?t-1:0),i=1;i<t;i++)r[i-1]=arguments[i];var o=!0,a=!1,s=void 0;try{for(var f,u=r[Symbol.iterator]();!(o=(f=u.next()).done);o=!0){var h=f.value;if(h instanceof Array){if(!e.hasOwnProperty(h[0]))return!1;if("string"==typeof h[1]){if(n(e[h[0]])!==h[1])return!1}else if(!(e[h[0]]instanceof h[1]))return!1}else if(!e.hasOwnProperty(h)||"string"!=typeof e[h])return!1}}catch(e){a=!0,s=e}finally{try{!o&&u.return&&u.return()}finally{if(a)throw s}}return!0}return function(e){if(!e||"object"!==(void 0===e?"undefined":n(e)))throw new Error(t);return e.hasOwnProperty("header")?function(e){if(!g(e,["header","object"],["target","object"]))throw new Error(t);if(!g(e.header,"chainpoint_version","hash_type","merkle_root","tx_id",["timestamp","number"]))throw new Error(t);if(!g(e.target,"target_hash",["target_proof",Array]))throw new Error(t);if(!e.target.target_proof.every(function(e){return g(e,"left","right","parent")}))throw new Error(r);if(!e.target.target_proof.every(function(e){return h(e.left)&&h(e.right)&&h(e.parent)}))throw new Error(o);if(0===e.target.target_proof.length){if(e.target.target_hash.toLowerCase()===e.header.merkle_root.toLowerCase())return!0;throw new Error(a)}var n=new b(e.target.target_hash);if(e.target.target_proof.forEach(function(e){var t=d().update(e.left+e.right,"utf8").digest("hex");if(t!==e.parent)throw new Error(s);n.add({left:e.left,right:e.right,parent:t})}),n.is_valid(e.header.merkle_root))return!0;throw new Error(a)}(e):function(e){if(!g(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);var n=e.type||e["@type"];if("string"!=typeof n||!/^ChainpointSHA([0-9]-)?[0-9]{3}v2$/.test(n))throw new Error(t);var s=null,h=null;switch(n){case"ChainpointSHA224v2":s=c,h=u(56);break;case"ChainpointSHA256v2":s=d,h=u(64);break;case"ChainpointSHA384v2":s=l,h=u(96);break;case"ChainpointSHA512v2":s=p,h=u(128);break;case"ChainpointSHA3-224v2":case"ChainpointSHA3-256v2":case"ChainpointSHA3-384v2":case"ChainpointSHA3-512v2":throw new Error(f);default:throw new Error(i)}if(!e.proof.every(function(e){return t=e.hasOwnProperty("left"),r=e.hasOwnProperty("right"),t?!r:r;var t,r}))throw new Error(r);if(!e.proof.every(function(e){return h(e.left||e.right)}))throw new Error(o);if(0===e.proof.length){if(e.targetHash.toLowerCase()===e.merkleRoot.toLowerCase())return!0;throw new Error(a)}var m=new b(e.targetHash),y=e.targetHash;if(e.proof.forEach(function(e){var t=void 0,r=void 0;e.left?(t=e.left,r=y):(t=y,r=e.right);var n=s().update(t+r,"hex").digest("hex");y=n,m.add({left:t,right:r,parent:n})}),m.is_valid(e.merkleRoot))return!0;throw new Error(a)}(e)}}},{}],7:[function(e,t,r){(function(r){(function(){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t.exports=function(t){var i="Bitcoin Signed Message:\n",o=e("bitcoinjs-message").verify;function a(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){for(var r=[],n=void 0,i=0,o=0;o<t.length;o++){var a=t.charAt(o);a===e&&"\\"!==n&&(r.push(t.slice(i,o)),i=++o),o>=t.length-1&&r.push(t.slice(i,o+1)),n=a}return r}var r={};return t(",",e).forEach(function(e){var n=t("=",e),i=n[0],o=n[1].replace("\\ "," ").replace("\\=","=").replace('\\"','"').replace("\\,",",").replace("\\;",";").replace("\\+","+");switch(i.toUpperCase().trim()){case"CN":r.commonName=o;break;case"EMAILADDRESS":r.emailAddress=o;break;case"O":r.organization=o;break;case"OU":r.organizationalUnit=o;break;case"L":r.locality=o;break;case"C":r.country=o}}),r}function f(e,t,r){try{return Promise.resolve({valid:o(e,t,r,i)})}catch(e){return Promise.resolve({valid:!1,reason:e.message})}}return{validateSignature:f,validateIdentity:function(e,i,o,u){if(!e)return o?Promise.resolve({valid:!0,signedIdentity:s(o)}):Promise.resolve({valid:!1});if(u&&!new URL(e).hostname.includes(u))return Promise.resolve({valid:!1,reason:"identity_mismatch"});var h=function(e){for(var t=0,n=[];t++<e;)n.push(Math.floor(255*Math.random()));return new r(n).toString("hex")}(16);return t(e,i,o,h).then(function(t){return t&&"object"==(void 0===t?"undefined":n(t))?t.signature?t.rightData.startsWith(e)?f(h+t.rightData,i,t.signature).then(function(e){return e.valid?a(t.identity,o):e}):{valid:!1,reason:"'rightData' should start with '"+e+"'"}:t.identity?a(t.identity,o):{valid:!1,reason:"'identity' should be provided'"}:{valid:!1,reason:"invalid response"}}).catch(function(e){return"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}}}).call(this)}).call(this,e("buffer").Buffer)},{"bitcoinjs-message":13,buffer:20}],8:[function(e,t,r){"use strict";t.exports=function(e){function t(t){return Promise.resolve(t).then(function(t){var r=t.receipt.signature;if(!r)return t;if(!r.signature||!r.signedHash||!r.pubKey)throw new Error("invalid_receipt_signature_format");var 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(function(n){if(!n.valid)throw new Error("invalid_receipt_signature");return e.signature.validateIdentity(r.identityURL,r.pubKey,r.signedIdentity,r.signedIssuerDomain).then(function(e){return 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(function(e){return t.identityVerificationStatus={code:e.message},t})})})}function r(r,n){return Promise.resolve().then(function(){return e.receipt.validate(r)}).then(function(){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(){return function(t){return e.transaction.get(function(e){return e.header&&e.header.tx_id||e.anchors&&e.anchors.find(function(e){return"BTCOpReturn"===e.type}).sourceId}(t)).then(function(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(function(e){return{receipt:r,code:e.message}})}return{WoleetDAB:function(t,n){return e.file.hashFileOrCheckHash(t,n).then(function(t){return e.anchor.getAnchorIDs(t,e.anchor.types.BOTH)}).then(function(t){var r=[];return t.reduce(function(t,n){return t.then(function(){return e.receipt.get(n).then(function(e){r.push(e)}).catch(function(e){if("202"!==e.message)throw e})})},Promise.resolve()).then(function(){if(t.length&&!r.length)throw new Error("file_matched_but_anchor_not_yet_processed");return r})}).then(function(e){var t=[];return e.reduce(function(e,n){return e.then(function(){return r(n).then(function(e){t.push(e)}).catch(function(e){t.push({receipt:n,code:e.message})})})},Promise.resolve()).then(function(){return t.sort(function(e,t){return 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(function(e){return r(n,e)})},receipt:r}}},{}],9:[function(e,t,r){"use strict";var n=e("safe-buffer").Buffer;t.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 o=e.charAt(i),a=o.charCodeAt(0);if(255!==t[a])throw new TypeError(o+" is ambiguous");t[a]=i}var s=e.length,f=e.charAt(0),u=Math.log(s)/Math.log(256),h=Math.log(256)/Math.log(s);function c(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return n.alloc(0);for(var r=0,i=0,o=0;e[r]===f;)i++,r++;for(var a=(e.length-r)*u+1>>>0,h=new Uint8Array(a);e[r];){var c=t[e.charCodeAt(r)];if(255===c)return;for(var d=0,l=a-1;(0!==c||d<o)&&-1!==l;l--,d++)c+=s*h[l]>>>0,h[l]=c%256>>>0,c=c/256>>>0;if(0!==c)throw new Error("Non-zero carry");o=d,r++}for(var p=a-o;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,o=0,a=t.length;o!==a&&0===t[o];)o++,r++;for(var u=(a-o)*h+1>>>0,c=new Uint8Array(u);o!==a;){for(var d=t[o],l=0,p=u-1;(0!==d||l<i)&&-1!==p;p--,l++)d+=256*c[p]>>>0,c[p]=d%s>>>0,d=d/s>>>0;if(0!==d)throw new Error("Non-zero carry");i=l,o++}for(var b=u-i;b!==u&&0===c[b];)b++;for(var g=f.repeat(r);b<u;++b)g+=e.charAt(c[b]);return g},decodeUnsafe:c,decode:function(e){var t=c(e);if(t)return t;throw new Error("Non-base"+s+" character")}}}},{"safe-buffer":103}],10:[function(e,t,r){"use strict";r.byteLength=function(e){var t=u(e),r=t[0],n=t[1];return 3*(r+n)/4-n},r.toByteArray=function(e){var t,r,n=u(e),a=n[0],s=n[1],f=new o(function(e,t,r){return 3*(t+r)/4-r}(0,a,s)),h=0,c=s>0?a-4:a;for(r=0;r<c;r+=4)t=i[e.charCodeAt(r)]<<18|i[e.charCodeAt(r+1)]<<12|i[e.charCodeAt(r+2)]<<6|i[e.charCodeAt(r+3)],f[h++]=t>>16&255,f[h++]=t>>8&255,f[h++]=255&t;2===s&&(t=i[e.charCodeAt(r)]<<2|i[e.charCodeAt(r+1)]>>4,f[h++]=255&t);1===s&&(t=i[e.charCodeAt(r)]<<10|i[e.charCodeAt(r+1)]<<4|i[e.charCodeAt(r+2)]>>2,f[h++]=t>>8&255,f[h++]=255&t);return f},r.fromByteArray=function(e){for(var t,r=e.length,i=r%3,o=[],a=0,s=r-i;a<s;a+=16383)o.push(h(e,a,a+16383>s?s:a+16383));1===i?(t=e[r-1],o.push(n[t>>2]+n[t<<4&63]+"==")):2===i&&(t=(e[r-2]<<8)+e[r-1],o.push(n[t>>10]+n[t>>4&63]+n[t<<2&63]+"="));return o.join("")};for(var n=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0,f=a.length;s<f;++s)n[s]=a[s],i[a.charCodeAt(s)]=s;function u(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 h(e,t,r){for(var i,o,a=[],s=t;s<r;s+=3)i=(e[s]<<16&16711680)+(e[s+1]<<8&65280)+(255&e[s+2]),a.push(n[(o=i)>>18&63]+n[o>>12&63]+n[o>>6&63]+n[63&o]);return a.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},{}],11:[function(e,t,r){"use strict";for(var n="qpzry9x8gf2tvdw0s3jn54khce6mua7l",i={},o=0;o<n.length;o++){var a=n.charAt(o);if(void 0!==i[a])throw new TypeError(a+" is ambiguous");i[a]=o}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 f(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 u(e,t){if(t=t||90,e.length<8)return e+" too short";if(e.length>t)return"Exceeds length limit";var r=e.toLowerCase(),n=e.toUpperCase();if(e!==r&&e!==n)return"Mixed-case string "+e;var o=(e=r).lastIndexOf("1");if(-1===o)return"No separator character for "+e;if(0===o)return"Missing prefix for "+e;var a=e.slice(0,o),u=e.slice(o+1);if(u.length<6)return"Data too short";var h=f(a);if("string"==typeof h)return h;for(var c=[],d=0;d<u.length;++d){var l=u.charAt(d),p=i[l];if(void 0===p)return"Unknown character "+l;h=s(h)^p,d+6>=u.length||c.push(p)}return 1!==h?"Invalid checksum for "+e:{prefix:a,words:c}}function h(e,t,r,n){for(var i=0,o=0,a=(1<<r)-1,s=[],f=0;f<e.length;++f)for(i=i<<t|e[f],o+=t;o>=r;)o-=r,s.push(i>>o&a);if(n)o>0&&s.push(i<<r-o&a);else{if(o>=t)return"Excess padding";if(i<<r-o&a)return"Non-zero padding"}return s}t.exports={decodeUnsafe:function(){var e=u.apply(null,arguments);if("object"==typeof e)return e},decode:function(e){var t=u.apply(null,arguments);if("object"==typeof t)return t;throw new Error(t)},encode:function(e,t,r){if(r=r||90,e.length+7+t.length>r)throw new TypeError("Exceeds length limit");var i=f(e=e.toLowerCase());if("string"==typeof i)throw new Error(i);for(var o=e+"1",a=0;a<t.length;++a){var u=t[a];if(u>>5!=0)throw new Error("Non 5-bit word");i=s(i)^u,o+=n.charAt(u)}for(a=0;a<6;++a)i=s(i);for(i^=1,a=0;a<6;++a){var h=i>>5*(5-a)&31;o+=n.charAt(h)}return o},toWordsUnsafe:function(e){var t=h(e,8,5,!0);if(Array.isArray(t))return t},toWords:function(e){var t=h(e,8,5,!0);if(Array.isArray(t))return t;throw new Error(t)},fromWordsUnsafe:function(e){var t=h(e,5,8,!1);if(Array.isArray(t))return t},fromWords:function(e){var t=h(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}}},{}],12:[function(e,t,r){var n=e("safe-buffer").Buffer;t.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 o=n.allocUnsafe(6+r+i);return o[0]=48,o[1]=o.length-2,o[2]=2,o[3]=e.length,e.copy(o,4),o[4+r]=2,o[5+r]=t.length,t.copy(o,6+r),o}}},{"safe-buffer":103}],13:[function(e,t,r){(function(r){(function(){const n=e("bs58check"),i=e("bech32"),o=e("buffer-equals"),a=e("create-hash"),s=e("secp256k1"),f=e("varuint-bitcoin"),u={P2WPKH:"p2wpkh",P2SH_P2WPKH:"p2sh(p2wpkh)"};function h(e){return a("sha256").update(e).digest()}function c(e){return a("ripemd160").update(h(e)).digest()}function d(e,t){t=t||"Bitcoin Signed Message:\n",r.isBuffer(t)||(t=r.from(t,"utf8")),r.isBuffer(e)||(e=r.from(e,"utf8"));const n=f.encodingLength(e.length),i=r.allocUnsafe(t.length+n+e.length);return t.copy(i,0),f.encode(e.length,i,t.length),e.copy(i,t.length+n),function(e){return h(h(e))}(i)}function l(e){return c(r.concat([r.from("0014","hex"),e]))}function p(e){const t=i.decode(e),n=i.fromWords(t.words.slice(1));return r.from(n)}t.exports={magicHash:d,sign:function(e,t,n,i,o){"object"==typeof i&&void 0===o&&(o=i,i=void 0);let{segwitType:a,extraEntropy:f}=o||{};if(a&&("string"==typeof a||a instanceof String)&&(a=a.toLowerCase()),a&&a!==u.P2SH_P2WPKH&&a!==u.P2WPKH)throw new Error('Unrecognized segwitType: use "'+u.P2SH_P2WPKH+'" or "'+u.P2WPKH+'"');const h=d(e,i),c=s.sign(h,t,{data:f});return function(e,t,n,i){return void 0!==i?(t+=8,i===u.P2WPKH&&(t+=4)):n&&(t+=4),r.concat([r.alloc(1,t+27),e])}(c.signature,c.recovery,n,a)},verify:function(e,t,i,a,f){r.isBuffer(i)||(i=r.from(i,"base64"));const h=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?u.P2WPKH:u.P2SH_P2WPKH:null,recovery:3&t,signature:e.slice(1)}}(i);if(f&&!h.compressed)throw new Error("checkSegwitAlways can only be used with a compressed pubkey signature flagbyte");const b=d(e,a),g=c(s.recover(b,h.signature,h.recovery,h.compressed));let m,y;if(h.segwitType)h.segwitType===u.P2SH_P2WPKH?(m=l(g),y=n.decode(t).slice(1)):h.segwitType===u.P2WPKH&&(m=g,y=p(t));else if(f)try{return y=p(t),o(g,y)}catch(e){const r=l(g);return y=n.decode(t).slice(1),o(g,y)||o(r,y)}else m=g,y=n.decode(t).slice(1);return o(m,y)}}}).call(this)}).call(this,e("buffer").Buffer)},{bech32:11,bs58check:18,buffer:20,"buffer-equals":19,"create-hash":23,secp256k1:104,"varuint-bitcoin":123}],14:[function(e,t,r){var n;function i(e){this.rand=e}if(t.exports=function(e){return n||(n=new i(null)),n.generate(e)},t.exports.Rand=i,i.prototype.generate=function(e){return this._rand(e)},i.prototype._rand=function(e){if(this.rand.getBytes)return this.rand.getBytes(e);for(var t=new Uint8Array(e),r=0;r<t.length;r++)t[r]=this.rand.getByte();return t},"object"==typeof self)self.crypto&&self.crypto.getRandomValues?i.prototype._rand=function(e){var t=new Uint8Array(e);return self.crypto.getRandomValues(t),t}:self.msCrypto&&self.msCrypto.getRandomValues?i.prototype._rand=function(e){var t=new Uint8Array(e);return self.msCrypto.getRandomValues(t),t}:"object"==typeof window&&(i.prototype._rand=function(){throw new Error("Not implemented yet")});else try{var o=e("crypto");if("function"!=typeof o.randomBytes)throw new Error("Not supported");i.prototype._rand=function(e){return o.randomBytes(e)}}catch(e){}},{crypto:15}],15:[function(e,t,r){},{}],16:[function(e,t,r){var n=e("base-x");t.exports=n("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")},{"base-x":9}],17:[function(e,t,r){"use strict";var n=e("bs58"),i=e("safe-buffer").Buffer;t.exports=function(e){function t(t){var r=t.slice(0,-4),n=t.slice(-4),i=e(r);if(!(n[0]^i[0]|n[1]^i[1]|n[2]^i[2]|n[3]^i[3]))return r}return{encode:function(t){var r=e(t);return n.encode(i.concat([t,r],t.length+4))},decode:function(e){var r=t(n.decode(e));if(!r)throw new Error("Invalid checksum");return r},decodeUnsafe:function(e){var r=n.decodeUnsafe(e);if(r)return t(r)}}}},{bs58:16,"safe-buffer":103}],18:[function(e,t,r){"use strict";var n=e("create-hash"),i=e("./base");t.exports=i(function(e){var t=n("sha256").update(e).digest();return n("sha256").update(t).digest()})},{"./base":17,"create-hash":23}],19:[function(e,t,r){(function(e){(function(){"use strict";t.exports=function(t,r){if(!e.isBuffer(t)||!e.isBuffer(r))throw new TypeError("Arguments must be Buffers");if(t===r)return!0;if("function"==typeof t.equals)return t.equals(r);if(t.length!==r.length)return!1;for(var n=0;n<t.length;n++)if(t[n]!==r[n])return!1;return!0}}).call(this)}).call(this,{isBuffer:e("../is-buffer/index.js")})},{"../is-buffer/index.js":80}],20:[function(e,t,r){(function(t){(function(){"use strict";var t=e("base64-js"),n=e("ieee754");r.Buffer=a,r.SlowBuffer=function(e){+e!=e&&(e=0);return a.alloc(+e)},r.INSPECT_MAX_BYTES=50;var i=2147483647;function o(e){if(e>i)throw new RangeError('The value "'+e+'" is invalid for option "size"');var t=new Uint8Array(e);return t.__proto__=a.prototype,t}function a(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return u(e)}return s(e,t,r)}function s(e,t,r){if("string"==typeof e)return function(e,t){"string"==typeof t&&""!==t||(t="utf8");if(!a.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var r=0|d(e,t),n=o(r),i=n.write(e,t);i!==r&&(n=n.slice(0,i));return n}(e,t);if(ArrayBuffer.isView(e))return h(e);if(null==e)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(U(e,ArrayBuffer)||e&&U(e.buffer,ArrayBuffer))return function(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');var n;n=void 0===t&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,t):new Uint8Array(e,t,r);return n.__proto__=a.prototype,n}(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');var n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return a.from(n,t,r);var i=function(e){if(a.isBuffer(e)){var t=0|c(e.length),r=o(t);return 0===r.length?r:(e.copy(r,0,0,t),r)}if(void 0!==e.length)return"number"!=typeof e.length||q(e.length)?o(0):h(e);if("Buffer"===e.type&&Array.isArray(e.data))return h(e.data)}(e);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return a.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function f(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function u(e){return f(e),o(e<0?0:0|c(e))}function h(e){for(var t=e.length<0?0:0|c(e.length),r=o(t),n=0;n<t;n+=1)r[n]=255&e[n];return r}function c(e){if(e>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|e}function d(e,t){if(a.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||U(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);var r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;for(var i=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return j(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return D(e).length;default:if(i)return n?-1:j(e).length;t=(""+t).toLowerCase(),i=!0}}function l(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function p(e,t,r,n,i){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),q(r=+r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=a.from(t,n)),a.isBuffer(t))return 0===t.length?-1:b(e,t,r,n,i);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):b(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function b(e,t,r,n,i){var o,a=1,s=e.length,f=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;a=2,s/=2,f/=2,r/=2}function u(e,t){return 1===a?e[t]:e.readUInt16BE(t*a)}if(i){var h=-1;for(o=r;o<s;o++)if(u(e,o)===u(t,-1===h?0:o-h)){if(-1===h&&(h=o),o-h+1===f)return h*a}else-1!==h&&(o-=o-h),h=-1}else for(r+f>s&&(r=s-f),o=r;o>=0;o--){for(var c=!0,d=0;d<f;d++)if(u(e,o+d)!==u(t,d)){c=!1;break}if(c)return o}return-1}function g(e,t,r,n){r=Number(r)||0;var i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;var o=t.length;n>o/2&&(n=o/2);for(var a=0;a<n;++a){var s=parseInt(t.substr(2*a,2),16);if(q(s))return a;e[r+a]=s}return a}function m(e,t,r,n){return O(j(t,e.length-r),e,r,n)}function y(e,t,r,n){return O(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function v(e,t,r,n){return y(e,t,r,n)}function _(e,t,r,n){return O(D(t),e,r,n)}function w(e,t,r,n){return O(function(e,t){for(var r,n,i,o=[],a=0;a<e.length&&!((t-=2)<0);++a)r=e.charCodeAt(a),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(t,e.length-r),e,r,n)}function E(e,r,n){return 0===r&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(r,n))}function S(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i<r;){var o,a,s,f,u=e[i],h=null,c=u>239?4:u>223?3:u>191?2:1;if(i+c<=r)switch(c){case 1:u<128&&(h=u);break;case 2:128==(192&(o=e[i+1]))&&(f=(31&u)<<6|63&o)>127&&(h=f);break;case 3:o=e[i+1],a=e[i+2],128==(192&o)&&128==(192&a)&&(f=(15&u)<<12|(63&o)<<6|63&a)>2047&&(f<55296||f>57343)&&(h=f);break;case 4:o=e[i+1],a=e[i+2],s=e[i+3],128==(192&o)&&128==(192&a)&&128==(192&s)&&(f=(15&u)<<18|(63&o)<<12|(63&a)<<6|63&s)>65535&&f<1114112&&(h=f)}null===h?(h=65533,c=1):h>65535&&(h-=65536,n.push(h>>>10&1023|55296),h=56320|1023&h),n.push(h),i+=c}return function(e){var t=e.length;if(t<=A)return String.fromCharCode.apply(String,e);var r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=A));return r}(n)}r.kMaxLength=i,a.TYPED_ARRAY_SUPPORT=function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()}catch(e){return!1}}(),a.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(a.prototype,"parent",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.buffer}}),Object.defineProperty(a.prototype,"offset",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.byteOffset}}),"undefined"!=typeof Symbol&&null!=Symbol.species&&a[Symbol.species]===a&&Object.defineProperty(a,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),a.poolSize=8192,a.from=function(e,t,r){return s(e,t,r)},a.prototype.__proto__=Uint8Array.prototype,a.__proto__=Uint8Array,a.alloc=function(e,t,r){return function(e,t,r){return f(e),e<=0?o(e):void 0!==t?"string"==typeof r?o(e).fill(t,r):o(e).fill(t):o(e)}(e,t,r)},a.allocUnsafe=function(e){return u(e)},a.allocUnsafeSlow=function(e){return u(e)},a.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==a.prototype},a.compare=function(e,t){if(U(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),U(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),!a.isBuffer(e)||!a.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;for(var r=e.length,n=t.length,i=0,o=Math.min(r,n);i<o;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?1:0},a.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return a.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=a.allocUnsafe(t),i=0;for(r=0;r<e.length;++r){var o=e[r];if(U(o,Uint8Array)&&(o=a.from(o)),!a.isBuffer(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,i),i+=o.length}return n},a.byteLength=d,a.prototype._isBuffer=!0,a.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)l(this,t,t+1);return this},a.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)l(this,t,t+3),l(this,t+1,t+2);return this},a.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)l(this,t,t+7),l(this,t+1,t+6),l(this,t+2,t+5),l(this,t+3,t+4);return this},a.prototype.toString=function(){var e=this.length;return 0===e?"":0===arguments.length?S(this,0,e):function(e,t,r){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return x(this,t,r);case"utf8":case"utf-8":return S(this,t,r);case"ascii":return M(this,t,r);case"latin1":case"binary":return I(this,t,r);case"base64":return E(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return L(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(e){if(!a.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===a.compare(this,e)},a.prototype.inspect=function(){var e="",t=r.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},a.prototype.compare=function(e,t,r,n,i){if(U(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),!a.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;for(var o=(i>>>=0)-(n>>>=0),s=(r>>>=0)-(t>>>=0),f=Math.min(o,s),u=this.slice(n,i),h=e.slice(t,r),c=0;c<f;++c)if(u[c]!==h[c]){o=u[c],s=h[c];break}return o<s?-1:s<o?1:0},a.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},a.prototype.indexOf=function(e,t,r){return p(this,e,t,r,!0)},a.prototype.lastIndexOf=function(e,t,r){return p(this,e,t,r,!1)},a.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return g(this,e,t,r);case"utf8":case"utf-8":return m(this,e,t,r);case"ascii":return y(this,e,t,r);case"latin1":case"binary":return v(this,e,t,r);case"base64":return _(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return w(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var A=4096;function M(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function I(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function x(e,t,r){var n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);for(var i="",o=t;o<r;++o)i+=N(e[o]);return i}function L(e,t,r){for(var n=e.slice(t,r),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function R(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function k(e,t,r,n,i,o){if(!a.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<o)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function T(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function P(e,t,r,i,o){return t=+t,r>>>=0,o||T(e,0,r,4),n.write(e,t,r,i,23,4),r+4}function B(e,t,r,i,o){return t=+t,r>>>=0,o||T(e,0,r,8),n.write(e,t,r,i,52,8),r+8}a.prototype.slice=function(e,t){var r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e);var n=this.subarray(e,t);return n.__proto__=a.prototype,n},a.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||R(e,t,this.length);for(var n=this[e],i=1,o=0;++o<t&&(i*=256);)n+=this[e+o]*i;return n},a.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||R(e,t,this.length);for(var n=this[e+--t],i=1;t>0&&(i*=256);)n+=this[e+--t]*i;return n},a.prototype.readUInt8=function(e,t){return e>>>=0,t||R(e,1,this.length),this[e]},a.prototype.readUInt16LE=function(e,t){return e>>>=0,t||R(e,2,this.length),this[e]|this[e+1]<<8},a.prototype.readUInt16BE=function(e,t){return e>>>=0,t||R(e,2,this.length),this[e]<<8|this[e+1]},a.prototype.readUInt32LE=function(e,t){return e>>>=0,t||R(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},a.prototype.readUInt32BE=function(e,t){return e>>>=0,t||R(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},a.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||R(e,t,this.length);for(var n=this[e],i=1,o=0;++o<t&&(i*=256);)n+=this[e+o]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*t)),n},a.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||R(e,t,this.length);for(var n=t,i=1,o=this[e+--n];n>0&&(i*=256);)o+=this[e+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*t)),o},a.prototype.readInt8=function(e,t){return e>>>=0,t||R(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},a.prototype.readInt16LE=function(e,t){e>>>=0,t||R(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},a.prototype.readInt16BE=function(e,t){e>>>=0,t||R(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},a.prototype.readInt32LE=function(e,t){return e>>>=0,t||R(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},a.prototype.readInt32BE=function(e,t){return e>>>=0,t||R(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},a.prototype.readFloatLE=function(e,t){return e>>>=0,t||R(e,4,this.length),n.read(this,e,!0,23,4)},a.prototype.readFloatBE=function(e,t){return e>>>=0,t||R(e,4,this.length),n.read(this,e,!1,23,4)},a.prototype.readDoubleLE=function(e,t){return e>>>=0,t||R(e,8,this.length),n.read(this,e,!0,52,8)},a.prototype.readDoubleBE=function(e,t){return e>>>=0,t||R(e,8,this.length),n.read(this,e,!1,52,8)},a.prototype.writeUIntLE=function(e,t,r,n){(e=+e,t>>>=0,r>>>=0,n)||k(this,e,t,r,Math.pow(2,8*r)-1,0);var i=1,o=0;for(this[t]=255&e;++o<r&&(i*=256);)this[t+o]=e/i&255;return t+r},a.prototype.writeUIntBE=function(e,t,r,n){(e=+e,t>>>=0,r>>>=0,n)||k(this,e,t,r,Math.pow(2,8*r)-1,0);var i=r-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+r},a.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||k(this,e,t,1,255,0),this[t]=255&e,t+1},a.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||k(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},a.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||k(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},a.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||k(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},a.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||k(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},a.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){var i=Math.pow(2,8*r-1);k(this,e,t,r,i-1,-i)}var o=0,a=1,s=0;for(this[t]=255&e;++o<r&&(a*=256);)e<0&&0===s&&0!==this[t+o-1]&&(s=1),this[t+o]=(e/a>>0)-s&255;return t+r},a.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){var i=Math.pow(2,8*r-1);k(this,e,t,r,i-1,-i)}var o=r-1,a=1,s=0;for(this[t+o]=255&e;--o>=0&&(a*=256);)e<0&&0===s&&0!==this[t+o+1]&&(s=1),this[t+o]=(e/a>>0)-s&255;return t+r},a.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||k(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=