@2waychain/2wayjs
Version:
API wrapper to access the AIBlock 2 Way Chain
1 lines • 80.8 kB
JavaScript
import e from"axios";import t from"bitcore-mnemonic";import{bytesToBase64 as r,base64ToBytes as n}from"byte-base64";import{sha3_256 as o}from"js-sha3";import{ok as i,err as s}from"neverthrow";import a from"tweetnacl";import{v4 as u}from"uuid";import c from"joi";import*as f from"bitcore-lib";function l(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:String(t)}function h(){return h=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},h.apply(this,arguments)}function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function d(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return p(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?p(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var y,g,v;!function(e){e[e.IErrorInternal=0]="IErrorInternal",e[e.IErrorNetwork=1]="IErrorNetwork"}(y||(y={})),function(e){e.InternalServerError="Internal Server Error",e.InvalidPassphrase="Invalid passphrase",e.BlankPassphrase="New passphrase cannot be blank",e.InvalidRequestBody="Invalid request body",e.CannotParseAddress="Cannot parse address",e.CannotAccessWallet="Cannot access wallet",e.CannotAccessUserNode="Cannot access user node",e.CannotAccessMempoolNode="Cannot access mempool node",e.CannotAccessPeerUserNode="Cannot access peer user node",e.CannotSaveAddressesToWallet="Cannot save address to wallet",e.CannotFetchBalance="Cannot fetch balance",e.NoDataFoundForKey="No data found for key",e.InternalError="Internal Error",e.Unauthorized="Unauthorized",e.MethodNotFound="Method not found",e.MethodNotAllowed="Method not allowed",e.BadRequest="Bad request"}(g||(g={})),function(e){e.InsufficientFunds="Insufficient funds",e.NoInputs="No inputs for transaction",e.InvalidInputs="Some inputs are invalid",e.UnableToGenerateDruid="Unable to generate DRUID",e.UnableToConstructTxIns="Unable to construct tx ins",e.UnableToConstructSignature="Unable to construct signature",e.UnableToGetKeypairFromMap="Unable to retrieve key-pair from map",e.InvalidAddressVersion="Unable to determine address version",e.InvalidParametersProvided="Invalid parameters provided",e.UnableToConstructOldAddress="Unable to construct old address",e.UnableToConstructTempAddress="Unable to construct temp address",e.UnableToConstructDefaultAddress="Unable to construct default address",e.UnableToGenerateSeed="Unable to generate seed",e.UnableToGetExistingSeed="Unable to get existing seed phrase",e.UnableToGetExistingMasterKey="Unable to get existing master key",e.UnableToGetPassphraseBuffer="Unable to get passphrase buffer",e.UnableToGetKeypair="Unable to get key-pair",e.UnableToGenerateMasterKey="Unable to generate master key",e.UnableToGenerateKeypair="Unable to generate key-pair",e.UnableToDeriveNextKeypair="Unable to derive next key-pair",e.UnableToEncryptKeypair="Unable to encrypt key-pair",e.UnableToSaveKeypairLocal="Unable to save key-pair to local storage",e.UnableToGetLocalKeypair="Unable to get key-pair from local storage",e.UnableToEncryptMasterKey="Unable to encrypt master key",e.UnableToDecryptKeypair="Unable to decrypt keypair",e.UnableToDecryptMasterKey="Unable to decrypt master key",e.MasterKeyCorrupt="Master key is corrupt",e.UnableToRegenAddresses="Unable to regenerate addresses",e.UnableToEncryptTransaction="Unable to encrypt transaction",e.UnableToDecryptTransaction="Unable to decrypt transaction",e.InvalidSeedPhrase="Invalid seed phrase",e.InvalidDRUIDProvided="Invalid DRUID value provided",e.UnableToFilterValenceData="Unable to filter valence data",e.ClientNotInitialized="Client not initialized",e.StorageNotInitialized="Storage host not initialized",e.ValenceNotInitialized="Valence host not initialized",e.FetchBalanceResponseEmpty="Balance object is empty",e.NoDRUIDValues="DRUID values are null",e.AssetsIncompatible="Assets are incompatible",e.KeyValuePairNotSingle="Key-value pair does not only have one element",e.UnableToFindNonEmptyAddresses="Unable to find addresses that contain assets",e.InvalidNetworkResponse="Invalid network response",e.UnableToSignMessage="Unable to sign message",e.UnableToVerifyMessage="Unable to verify message",e.NoHostsProvided="No hosts provided",e.NoKeypairsProvided="No key-pairs provided",e.NoPassPhraseProvided="No passphrase provided",e.NoComputeHostProvided="No compute host provided",e.NoContentReturned="No content returned",e.UnknownError="Unknown Error"}(v||(v={}));var m,P,E,O,b,w,I=/*#__PURE__*/function(){function e(e,t){this.type=void 0,this.value=void 0,this.type=e,this.value=t}return e.prototype.toString=function(){return this.type+":"+this.value},e}();!function(e){e[e.OP_0=0]="OP_0",e[e.OP_PUSHDATA1=76]="OP_PUSHDATA1",e[e.OP_PUSHDATA2=77]="OP_PUSHDATA2",e[e.OP_PUSHDATA4=78]="OP_PUSHDATA4",e[e.OP_1NEGATE=79]="OP_1NEGATE",e[e.OP_RESERVED=80]="OP_RESERVED",e[e.OP_1=81]="OP_1",e[e.OP_2=82]="OP_2",e[e.OP_3=83]="OP_3",e[e.OP_4=84]="OP_4",e[e.OP_5=85]="OP_5",e[e.OP_6=86]="OP_6",e[e.OP_7=87]="OP_7",e[e.OP_8=88]="OP_8",e[e.OP_9=89]="OP_9",e[e.OP_10=90]="OP_10",e[e.OP_11=91]="OP_11",e[e.OP_12=92]="OP_12",e[e.OP_13=93]="OP_13",e[e.OP_14=94]="OP_14",e[e.OP_15=95]="OP_15",e[e.OP_16=96]="OP_16",e[e.OP_NOP=97]="OP_NOP",e[e.OP_VER=98]="OP_VER",e[e.OP_IF=99]="OP_IF",e[e.OP_NOTIF=100]="OP_NOTIF",e[e.OP_VERIF=101]="OP_VERIF",e[e.OP_VERNOTIF=102]="OP_VERNOTIF",e[e.OP_ELSE=103]="OP_ELSE",e[e.OP_ENDIF=104]="OP_ENDIF",e[e.OP_VERIFY=105]="OP_VERIFY",e[e.OP_RETURN=106]="OP_RETURN",e[e.OP_TOALTSTACK=107]="OP_TOALTSTACK",e[e.OP_FROMALTSTACK=108]="OP_FROMALTSTACK",e[e.OP_2DROP=109]="OP_2DROP",e[e.OP_2DUP=110]="OP_2DUP",e[e.OP_3DUP=111]="OP_3DUP",e[e.OP_2OVER=112]="OP_2OVER",e[e.OP_2ROT=113]="OP_2ROT",e[e.OP_2SWAP=114]="OP_2SWAP",e[e.OP_IFDUP=115]="OP_IFDUP",e[e.OP_DEPTH=116]="OP_DEPTH",e[e.OP_DROP=117]="OP_DROP",e[e.OP_DUP=118]="OP_DUP",e[e.OP_NIP=119]="OP_NIP",e[e.OP_OVER=120]="OP_OVER",e[e.OP_PICK=121]="OP_PICK",e[e.OP_ROLL=122]="OP_ROLL",e[e.OP_ROT=123]="OP_ROT",e[e.OP_SWAP=124]="OP_SWAP",e[e.OP_TUCK=125]="OP_TUCK",e[e.OP_CAT=126]="OP_CAT",e[e.OP_SUBSTR=127]="OP_SUBSTR",e[e.OP_LEFT=128]="OP_LEFT",e[e.OP_RIGHT=129]="OP_RIGHT",e[e.OP_SIZE=130]="OP_SIZE",e[e.OP_INVERT=131]="OP_INVERT",e[e.OP_AND=132]="OP_AND",e[e.OP_OR=133]="OP_OR",e[e.OP_XOR=134]="OP_XOR",e[e.OP_EQUAL=135]="OP_EQUAL",e[e.OP_EQUALVERIFY=136]="OP_EQUALVERIFY",e[e.OP_RESERVED1=137]="OP_RESERVED1",e[e.OP_RESERVED2=138]="OP_RESERVED2",e[e.OP_1ADD=139]="OP_1ADD",e[e.OP_1SUB=140]="OP_1SUB",e[e.OP_2MUL=141]="OP_2MUL",e[e.OP_2DIV=142]="OP_2DIV",e[e.OP_NEGATE=143]="OP_NEGATE",e[e.OP_ABS=144]="OP_ABS",e[e.OP_NOT=145]="OP_NOT",e[e.OP_0NOTEQUAL=146]="OP_0NOTEQUAL",e[e.OP_ADD=147]="OP_ADD",e[e.OP_SUB=148]="OP_SUB",e[e.OP_MUL=149]="OP_MUL",e[e.OP_DIV=150]="OP_DIV",e[e.OP_MOD=151]="OP_MOD",e[e.OP_LSHIFT=152]="OP_LSHIFT",e[e.OP_RSHIFT=153]="OP_RSHIFT",e[e.OP_BOOLAND=154]="OP_BOOLAND",e[e.OP_BOOLOR=155]="OP_BOOLOR",e[e.OP_NUMEQUAL=156]="OP_NUMEQUAL",e[e.OP_NUMEQUALVERIFY=157]="OP_NUMEQUALVERIFY",e[e.OP_NUMNOTEQUAL=158]="OP_NUMNOTEQUAL",e[e.OP_LESSTHAN=159]="OP_LESSTHAN",e[e.OP_GREATERTHAN=160]="OP_GREATERTHAN",e[e.OP_LESSTHANOREQUAL=161]="OP_LESSTHANOREQUAL",e[e.OP_GREATERTHANOREQUAL=162]="OP_GREATERTHANOREQUAL",e[e.OP_MIN=163]="OP_MIN",e[e.OP_MAX=164]="OP_MAX",e[e.OP_WITHIN=165]="OP_WITHIN",e[e.OP_SHA256=168]="OP_SHA256",e[e.OP_HASH160=169]="OP_HASH160",e[e.OP_HASH256=170]="OP_HASH256",e[e.OP_CODESEPARATOR=171]="OP_CODESEPARATOR",e[e.OP_CHECKSIG=172]="OP_CHECKSIG",e[e.OP_CHECKSIGVERIFY=173]="OP_CHECKSIGVERIFY",e[e.OP_CHECKMULTISIG=174]="OP_CHECKMULTISIG",e[e.OP_CHECKMULTISIGVERIFY=175]="OP_CHECKMULTISIGVERIFY",e[e.OP_NOP1=176]="OP_NOP1",e[e.OP_CHECKLOCKTIMEVERIFY=177]="OP_CHECKLOCKTIMEVERIFY",e[e.OP_CHECKSEQUENCEVERIFY=178]="OP_CHECKSEQUENCEVERIFY",e[e.OP_NOP4=179]="OP_NOP4",e[e.OP_NOP5=180]="OP_NOP5",e[e.OP_NOP6=181]="OP_NOP6",e[e.OP_NOP7=182]="OP_NOP7",e[e.OP_NOP8=183]="OP_NOP8",e[e.OP_NOP9=184]="OP_NOP9",e[e.OP_NOP10=185]="OP_NOP10",e[e.OP_CREATE=192]="OP_CREATE",e[e.OP_INVALIDOPCODE=255]="OP_INVALIDOPCODE",e[e.OP_HASH256_V0=193]="OP_HASH256_V0",e[e.OP_HASH256_TEMP=194]="OP_HASH256_TEMP"}(m||(m={})),function(e){e.DebugData="/debug_data",e.FetchBalance="/fetch_balance",e.CreateTransactions="/create_transactions",e.CreateItemAsset="/create_item_asset",e.FetchPending="/fetch_pending",e.BlockchainEntry="/blockchain_entry",e.ValenceSet="/set_data",e.ValenceGet="/get_data",e.ValenceDel="/del_data"}(P||(P={})),function(e){e.Create="Create",e.Default="Default"}(E||(E={})),function(e){e[e.IErrorInternal=0]="IErrorInternal"}(O||(O={})),function(e){e.FetchWalletInfo="Wallet info successfully fetched",e.ExportKeypairs="Key-pairs successfully exported",e.ImportKeypairs="Key-pairs successfully imported",e.GetPaymentAddress="New payment address generated",e.GetDebugData="Debug data successfully retrieved",e.GetLatestBlock="Current mining block successfully retrieved",e.UTXOAddressesRetrieved="UTXO addresses successfully retrieved",e.DataBaseItemsRetrieved="Database item(s) successfully retrieved",e.PaymentProcessing="Payment processing",e.IpPaymentProcessing="IP payment processing",e.DonationRequestSent="Donation request sent",e.RunningTotalUpdated="Running total updated",e.FetchBalance="Balance successfully fetched",e.FetchPendingTransactions="Pending transactions successfully fetched",e.CreateItemAssets="Item asset(s) created",e.CreateTransactions="Transaction(s) processing",e.ChangeWalletPassphrase="Passphrase changed successfully",e.ConstructAddress="Address successfully constructed"}(b||(b={})),function(e){e.ClientInitialized="Client initialized",e.MessageSigned="Successfully signed message",e.MessageVirified="Successfully verified message",e.TwoWayPaymentProcessing="2-Way payment processing",e.Pending2WPaymentsFetched="Succesfully fetched pending 2 way transactions",e.AddressesReconstructed="Addresses have successfully been reconstructed",e.NewAddressGenerated="Successfully generated new address",e.SeedPhraseObtained="Successfully obtained seed phrase",e.MasterKeyObtained="Successfully obtained master key",e.KeypairDecrypted="Successfully decrypted key-pair",e.KeypairSaved="Successfully saved key-pair to local storage",e.KeypairObtained="Successfully retreived key-pair from local storage",e.RespondedTo2WPayment="Successfully responded to 2 way payment"}(w||(w={}));for(var _=[],A=[],U="undefined"!=typeof Uint8Array?Uint8Array:Array,T="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",R=0;R<64;++R)_[R]=T[R],A[T.charCodeAt(R)]=R;function S(e,t,r){for(var n,o=[],i=t;i<r;i+=3)o.push(_[(n=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]))>>18&63]+_[n>>12&63]+_[n>>6&63]+_[63&n]);return o.join("")}A["-".charCodeAt(0)]=62,A["_".charCodeAt(0)]=63;var N,B,K=function(e,t,r,n,o){var i,s,a=8*o-n-1,u=(1<<a)-1,c=u>>1,f=-7,l=r?o-1:0,h=r?-1:1,p=e[t+l];for(l+=h,i=p&(1<<-f)-1,p>>=-f,f+=a;f>0;i=256*i+e[t+l],l+=h,f-=8);for(s=i&(1<<-f)-1,i>>=-f,f+=n;f>0;s=256*s+e[t+l],l+=h,f-=8);if(0===i)i=1-c;else{if(i===u)return s?NaN:Infinity*(p?-1:1);s+=Math.pow(2,n),i-=c}return(p?-1:1)*s*Math.pow(2,i-n)},k=function(e,t,r,n,o,i){var s,a,u,c=8*i-o-1,f=(1<<c)-1,l=f>>1,h=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,d=n?1:-1,y=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||Infinity===t?(a=isNaN(t)?1:0,s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+l>=1?h/u:h*Math.pow(2,1-l))*u>=2&&(s++,u/=2),s+l>=f?(a=0,s=f):s+l>=1?(a=(t*u-1)*Math.pow(2,o),s+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,o),s=0));o>=8;e[r+p]=255&a,p+=d,a/=256,o-=8);for(s=s<<o|a,c+=o;c>0;e[r+p]=255&s,p+=d,s/=256,c-=8);e[r+p-d]|=128*y},C=(N=function(e,t){const r="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;t.Buffer=i,t.SlowBuffer=function(e){return+e!=e&&(e=0),i.alloc(+e)},t.INSPECT_MAX_BYTES=50;const n=2147483647;function o(e){if(e>n)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new Uint8Array(e);return Object.setPrototypeOf(t,i.prototype),t}function i(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){if("string"==typeof t&&""!==t||(t="utf8"),!i.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const r=0|h(e,t);let n=o(r);const s=n.write(e,t);return s!==r&&(n=n.slice(0,s)),n}(e,t);if(ArrayBuffer.isView(e))return function(e){if(X(e,Uint8Array)){const t=new Uint8Array(e);return f(t.buffer,t.byteOffset,t.byteLength)}return c(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(X(e,ArrayBuffer)||e&&X(e.buffer,ArrayBuffer))return f(e,t,r);if("undefined"!=typeof SharedArrayBuffer&&(X(e,SharedArrayBuffer)||e&&X(e.buffer,SharedArrayBuffer)))return f(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return i.from(n,t,r);const s=function(e){if(i.isBuffer(e)){const t=0|l(e.length),r=o(t);return 0===r.length||e.copy(r,0,0,t),r}return void 0!==e.length?"number"!=typeof e.length||Z(e.length)?o(0):c(e):"Buffer"===e.type&&Array.isArray(e.data)?c(e.data):void 0}(e);if(s)return s;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return i.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 a(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 a(e),o(e<0?0:0|l(e))}function c(e){const t=e.length<0?0:0|l(e.length),r=o(t);for(let n=0;n<t;n+=1)r[n]=255&e[n];return r}function f(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');let n;return n=void 0===t&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,t):new Uint8Array(e,t,r),Object.setPrototypeOf(n,i.prototype),n}function l(e){if(e>=n)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n.toString(16)+" bytes");return 0|e}function h(e,t){if(i.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||X(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);const r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let o=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return Y(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Q(e).length;default:if(o)return n?-1:Y(e).length;t=(""+t).toLowerCase(),o=!0}}function p(e,t,r){let 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 N(this,t,r);case"utf8":case"utf-8":return w(this,t,r);case"ascii":return T(this,t,r);case"latin1":case"binary":return R(this,t,r);case"base64":return b(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function d(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function y(e,t,r,n,o){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),Z(r=+r)&&(r=o?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(o)return-1;r=e.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof t&&(t=i.from(t,n)),i.isBuffer(t))return 0===t.length?-1:g(e,t,r,n,o);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):g(e,[t],r,n,o);throw new TypeError("val must be string, number or Buffer")}function g(e,t,r,n,o){let i,s=1,a=e.length,u=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;s=2,a/=2,u/=2,r/=2}function c(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(o){let n=-1;for(i=r;i<a;i++)if(c(e,i)===c(t,-1===n?0:i-n)){if(-1===n&&(n=i),i-n+1===u)return n*s}else-1!==n&&(i-=i-n),n=-1}else for(r+u>a&&(r=a-u),i=r;i>=0;i--){let r=!0;for(let n=0;n<u;n++)if(c(e,i+n)!==c(t,n)){r=!1;break}if(r)return i}return-1}function v(e,t,r,n){r=Number(r)||0;const o=e.length-r;n?(n=Number(n))>o&&(n=o):n=o;const i=t.length;let s;for(n>i/2&&(n=i/2),s=0;s<n;++s){const n=parseInt(t.substr(2*s,2),16);if(Z(n))return s;e[r+s]=n}return s}function m(e,t,r,n){return J(Y(t,e.length-r),e,r,n)}function P(e,t,r,n){return J(function(e){const t=[];for(let r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function E(e,t,r,n){return J(Q(t),e,r,n)}function O(e,t,r,n){return J(function(e,t){let r,n,o;const i=[];for(let s=0;s<e.length&&!((t-=2)<0);++s)r=e.charCodeAt(s),n=r>>8,o=r%256,i.push(o),i.push(n);return i}(t,e.length-r),e,r,n)}function b(e,t,r){return function(e){for(var t,r=e.length,n=r%3,o=[],i=16383,s=0,a=r-n;s<a;s+=i)o.push(S(e,s,s+i>a?a:s+i));return 1===n?o.push(_[(t=e[r-1])>>2]+_[t<<4&63]+"=="):2===n&&o.push(_[(t=(e[r-2]<<8)+e[r-1])>>10]+_[t>>4&63]+_[t<<2&63]+"="),o.join("")}(0===t&&r===e.length?e:e.slice(t,r))}function w(e,t,r){r=Math.min(e.length,r);const n=[];let o=t;for(;o<r;){const t=e[o];let i=null,s=t>239?4:t>223?3:t>191?2:1;if(o+s<=r){let r,n,a,u;switch(s){case 1:t<128&&(i=t);break;case 2:r=e[o+1],128==(192&r)&&(u=(31&t)<<6|63&r,u>127&&(i=u));break;case 3:r=e[o+1],n=e[o+2],128==(192&r)&&128==(192&n)&&(u=(15&t)<<12|(63&r)<<6|63&n,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:r=e[o+1],n=e[o+2],a=e[o+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(u=(15&t)<<18|(63&r)<<12|(63&n)<<6|63&a,u>65535&&u<1114112&&(i=u))}}null===i?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|1023&i),n.push(i),o+=s}return function(e){const t=e.length;if(t<=I)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=I));return r}(n)}t.kMaxLength=n,(i.TYPED_ARRAY_SUPPORT=function(){try{const e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch(e){return!1}}())||"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(i.prototype,"parent",{enumerable:!0,get:function(){if(i.isBuffer(this))return this.buffer}}),Object.defineProperty(i.prototype,"offset",{enumerable:!0,get:function(){if(i.isBuffer(this))return this.byteOffset}}),i.poolSize=8192,i.from=function(e,t,r){return s(e,t,r)},Object.setPrototypeOf(i.prototype,Uint8Array.prototype),Object.setPrototypeOf(i,Uint8Array),i.alloc=function(e,t,r){return function(e,t,r){return a(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)},i.allocUnsafe=function(e){return u(e)},i.allocUnsafeSlow=function(e){return u(e)},i.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==i.prototype},i.compare=function(e,t){if(X(e,Uint8Array)&&(e=i.from(e,e.offset,e.byteLength)),X(t,Uint8Array)&&(t=i.from(t,t.offset,t.byteLength)),!i.isBuffer(e)||!i.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let r=e.length,n=t.length;for(let o=0,i=Math.min(r,n);o<i;++o)if(e[o]!==t[o]){r=e[o],n=t[o];break}return r<n?-1:n<r?1:0},i.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}},i.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return i.alloc(0);let r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;const n=i.allocUnsafe(t);let o=0;for(r=0;r<e.length;++r){let t=e[r];if(X(t,Uint8Array))o+t.length>n.length?(i.isBuffer(t)||(t=i.from(t)),t.copy(n,o)):Uint8Array.prototype.set.call(n,t,o);else{if(!i.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(n,o)}o+=t.length}return n},i.byteLength=h,i.prototype._isBuffer=!0,i.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)d(this,t,t+1);return this},i.prototype.swap32=function(){const e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)d(this,t,t+3),d(this,t+1,t+2);return this},i.prototype.swap64=function(){const e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)d(this,t,t+7),d(this,t+1,t+6),d(this,t+2,t+5),d(this,t+3,t+4);return this},i.prototype.toString=function(){const e=this.length;return 0===e?"":0===arguments.length?w(this,0,e):p.apply(this,arguments)},i.prototype.toLocaleString=i.prototype.toString,i.prototype.equals=function(e){if(!i.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===i.compare(this,e)},i.prototype.inspect=function(){let e="";const r=t.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"},r&&(i.prototype[r]=i.prototype.inspect),i.prototype.compare=function(e,t,r,n,o){if(X(e,Uint8Array)&&(e=i.from(e,e.offset,e.byteLength)),!i.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===o&&(o=this.length),t<0||r>e.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&t>=r)return 0;if(n>=o)return-1;if(t>=r)return 1;if(this===e)return 0;let s=(o>>>=0)-(n>>>=0),a=(r>>>=0)-(t>>>=0);const u=Math.min(s,a),c=this.slice(n,o),f=e.slice(t,r);for(let e=0;e<u;++e)if(c[e]!==f[e]){s=c[e],a=f[e];break}return s<a?-1:a<s?1:0},i.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},i.prototype.indexOf=function(e,t,r){return y(this,e,t,r,!0)},i.prototype.lastIndexOf=function(e,t,r){return y(this,e,t,r,!1)},i.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)}const o=this.length-t;if((void 0===r||r>o)&&(r=o),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let i=!1;for(;;)switch(n){case"hex":return v(this,e,t,r);case"utf8":case"utf-8":return m(this,e,t,r);case"ascii":case"latin1":case"binary":return P(this,e,t,r);case"base64":return E(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O(this,e,t,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},i.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const I=4096;function T(e,t,r){let n="";r=Math.min(e.length,r);for(let o=t;o<r;++o)n+=String.fromCharCode(127&e[o]);return n}function R(e,t,r){let n="";r=Math.min(e.length,r);for(let o=t;o<r;++o)n+=String.fromCharCode(e[o]);return n}function N(e,t,r){const n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);let o="";for(let n=t;n<r;++n)o+=ee[e[n]];return o}function B(e,t,r){const n=e.slice(t,r);let o="";for(let e=0;e<n.length-1;e+=2)o+=String.fromCharCode(n[e]+256*n[e+1]);return o}function C(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 M(e,t,r,n,o,s){if(!i.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||t<s)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function D(e,t,r,n,o){W(t,n,o,e,r,7);let i=Number(t&BigInt(4294967295));e[r++]=i,i>>=8,e[r++]=i,i>>=8,e[r++]=i,i>>=8,e[r++]=i;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,r}function H(e,t,r,n,o){W(t,n,o,e,r,7);let i=Number(t&BigInt(4294967295));e[r+7]=i,i>>=8,e[r+6]=i,i>>=8,e[r+5]=i,i>>=8,e[r+4]=i;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=s,s>>=8,e[r+2]=s,s>>=8,e[r+1]=s,s>>=8,e[r]=s,r+8}function x(e,t,r,n,o,i){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function L(e,t,r,n,o){return t=+t,r>>>=0,o||x(e,0,r,4),k(e,t,r,n,23,4),r+4}function j(e,t,r,n,o){return t=+t,r>>>=0,o||x(e,0,r,8),k(e,t,r,n,52,8),r+8}i.prototype.slice=function(e,t){const 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);const n=this.subarray(e,t);return Object.setPrototypeOf(n,i.prototype),n},i.prototype.readUintLE=i.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||C(e,t,this.length);let n=this[e],o=1,i=0;for(;++i<t&&(o*=256);)n+=this[e+i]*o;return n},i.prototype.readUintBE=i.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||C(e,t,this.length);let n=this[e+--t],o=1;for(;t>0&&(o*=256);)n+=this[e+--t]*o;return n},i.prototype.readUint8=i.prototype.readUInt8=function(e,t){return e>>>=0,t||C(e,1,this.length),this[e]},i.prototype.readUint16LE=i.prototype.readUInt16LE=function(e,t){return e>>>=0,t||C(e,2,this.length),this[e]|this[e+1]<<8},i.prototype.readUint16BE=i.prototype.readUInt16BE=function(e,t){return e>>>=0,t||C(e,2,this.length),this[e]<<8|this[e+1]},i.prototype.readUint32LE=i.prototype.readUInt32LE=function(e,t){return e>>>=0,t||C(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},i.prototype.readUint32BE=i.prototype.readUInt32BE=function(e,t){return e>>>=0,t||C(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},i.prototype.readBigUInt64LE=te(function(e){z(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||$(e,this.length-8);const n=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,o=this[++e]+256*this[++e]+65536*this[++e]+r*2**24;return BigInt(n)+(BigInt(o)<<BigInt(32))}),i.prototype.readBigUInt64BE=te(function(e){z(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||$(e,this.length-8);const n=t*2**24+65536*this[++e]+256*this[++e]+this[++e],o=this[++e]*2**24+65536*this[++e]+256*this[++e]+r;return(BigInt(n)<<BigInt(32))+BigInt(o)}),i.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||C(e,t,this.length);let n=this[e],o=1,i=0;for(;++i<t&&(o*=256);)n+=this[e+i]*o;return o*=128,n>=o&&(n-=Math.pow(2,8*t)),n},i.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||C(e,t,this.length);let n=t,o=1,i=this[e+--n];for(;n>0&&(o*=256);)i+=this[e+--n]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*t)),i},i.prototype.readInt8=function(e,t){return e>>>=0,t||C(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},i.prototype.readInt16LE=function(e,t){e>>>=0,t||C(e,2,this.length);const r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},i.prototype.readInt16BE=function(e,t){e>>>=0,t||C(e,2,this.length);const r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},i.prototype.readInt32LE=function(e,t){return e>>>=0,t||C(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},i.prototype.readInt32BE=function(e,t){return e>>>=0,t||C(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},i.prototype.readBigInt64LE=te(function(e){z(e>>>=0,"offset");const t=this[e],r=this[e+7];return void 0!==t&&void 0!==r||$(e,this.length-8),(BigInt(this[e+4]+256*this[e+5]+65536*this[e+6]+(r<<24))<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)}),i.prototype.readBigInt64BE=te(function(e){z(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||$(e,this.length-8);const n=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(n)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+r)}),i.prototype.readFloatLE=function(e,t){return e>>>=0,t||C(e,4,this.length),K(this,e,!0,23,4)},i.prototype.readFloatBE=function(e,t){return e>>>=0,t||C(e,4,this.length),K(this,e,!1,23,4)},i.prototype.readDoubleLE=function(e,t){return e>>>=0,t||C(e,8,this.length),K(this,e,!0,52,8)},i.prototype.readDoubleBE=function(e,t){return e>>>=0,t||C(e,8,this.length),K(this,e,!1,52,8)},i.prototype.writeUintLE=i.prototype.writeUIntLE=function(e,t,r,n){e=+e,t>>>=0,r>>>=0,n||M(this,e,t,r,Math.pow(2,8*r)-1,0);let o=1,i=0;for(this[t]=255&e;++i<r&&(o*=256);)this[t+i]=e/o&255;return t+r},i.prototype.writeUintBE=i.prototype.writeUIntBE=function(e,t,r,n){e=+e,t>>>=0,r>>>=0,n||M(this,e,t,r,Math.pow(2,8*r)-1,0);let o=r-1,i=1;for(this[t+o]=255&e;--o>=0&&(i*=256);)this[t+o]=e/i&255;return t+r},i.prototype.writeUint8=i.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,1,255,0),this[t]=255&e,t+1},i.prototype.writeUint16LE=i.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},i.prototype.writeUint16BE=i.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},i.prototype.writeUint32LE=i.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||M(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},i.prototype.writeUint32BE=i.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||M(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},i.prototype.writeBigUInt64LE=te(function(e,t=0){return D(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),i.prototype.writeBigUInt64BE=te(function(e,t=0){return H(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),i.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);M(this,e,t,r,n-1,-n)}let o=0,i=1,s=0;for(this[t]=255&e;++o<r&&(i*=256);)e<0&&0===s&&0!==this[t+o-1]&&(s=1),this[t+o]=(e/i|0)-s&255;return t+r},i.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);M(this,e,t,r,n-1,-n)}let o=r-1,i=1,s=0;for(this[t+o]=255&e;--o>=0&&(i*=256);)e<0&&0===s&&0!==this[t+o+1]&&(s=1),this[t+o]=(e/i|0)-s&255;return t+r},i.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},i.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},i.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},i.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},i.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},i.prototype.writeBigInt64LE=te(function(e,t=0){return D(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),i.prototype.writeBigInt64BE=te(function(e,t=0){return H(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),i.prototype.writeFloatLE=function(e,t,r){return L(this,e,t,!0,r)},i.prototype.writeFloatBE=function(e,t,r){return L(this,e,t,!1,r)},i.prototype.writeDoubleLE=function(e,t,r){return j(this,e,t,!0,r)},i.prototype.writeDoubleBE=function(e,t,r){return j(this,e,t,!1,r)},i.prototype.copy=function(e,t,r,n){if(!i.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);const o=n-r;return this===e&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(t,r,n):Uint8Array.prototype.set.call(e,this.subarray(r,n),t),o},i.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!i.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===e.length){const t=e.charCodeAt(0);("utf8"===n&&t<128||"latin1"===n)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;let o;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(o=t;o<r;++o)this[o]=e;else{const s=i.isBuffer(e)?e:i.from(e,n),a=s.length;if(0===a)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<r-t;++o)this[o+t]=s[o%a]}return this};const F={};function V(e,t,r){F[e]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function G(e){let t="",r=e.length;const n="-"===e[0]?1:0;for(;r>=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function W(e,t,r,n,o,i){if(e>r||e<t){const n="bigint"==typeof t?"n":"";let o;throw o=i>3?0===t||t===BigInt(0)?`>= 0${n} and < 2${n} ** ${8*(i+1)}${n}`:`>= -(2${n} ** ${8*(i+1)-1}${n}) and < 2 ** ${8*(i+1)-1}${n}`:`>= ${t}${n} and <= ${r}${n}`,new F.ERR_OUT_OF_RANGE("value",o,e)}!function(e,t,r){z(t,"offset"),void 0!==e[t]&&void 0!==e[t+r]||$(t,e.length-(r+1))}(n,o,i)}function z(e,t){if("number"!=typeof e)throw new F.ERR_INVALID_ARG_TYPE(t,"number",e)}function $(e,t,r){if(Math.floor(e)!==e)throw z(e,r),new F.ERR_OUT_OF_RANGE(r||"offset","an integer",e);if(t<0)throw new F.ERR_BUFFER_OUT_OF_BOUNDS;throw new F.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${t}`,e)}V("ERR_BUFFER_OUT_OF_BOUNDS",function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),V("ERR_INVALID_ARG_TYPE",function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError),V("ERR_OUT_OF_RANGE",function(e,t,r){let n=`The value of "${e}" is out of range.`,o=r;return Number.isInteger(r)&&Math.abs(r)>2**32?o=G(String(r)):"bigint"==typeof r&&(o=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(o=G(o)),o+="n"),n+=` It must be ${t}. Received ${o}`,n},RangeError);const q=/[^+/0-9A-Za-z-_]/g;function Y(e,t){let r;t=t||Infinity;const n=e.length;let o=null;const i=[];for(let s=0;s<n;++s){if(r=e.charCodeAt(s),r>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function Q(e){return function(e){var t,r,n=function(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]}(e),o=n[0],i=n[1],s=new U(function(e,t,r){return 3*(t+r)/4-r}(0,o,i)),a=0,u=i>0?o-4:o;for(r=0;r<u;r+=4)t=A[e.charCodeAt(r)]<<18|A[e.charCodeAt(r+1)]<<12|A[e.charCodeAt(r+2)]<<6|A[e.charCodeAt(r+3)],s[a++]=t>>16&255,s[a++]=t>>8&255,s[a++]=255&t;return 2===i&&(t=A[e.charCodeAt(r)]<<2|A[e.charCodeAt(r+1)]>>4,s[a++]=255&t),1===i&&(t=A[e.charCodeAt(r)]<<10|A[e.charCodeAt(r+1)]<<4|A[e.charCodeAt(r+2)]>>2,s[a++]=t>>8&255,s[a++]=255&t),s}(function(e){if((e=(e=e.split("=")[0]).trim().replace(q,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function J(e,t,r,n){let o;for(o=0;o<n&&!(o+r>=t.length||o>=e.length);++o)t[o+r]=e[o];return o}function X(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function Z(e){return e!=e}const ee=function(){const e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let o=0;o<16;++o)t[n+o]=e[r]+e[o]}return t}();function te(e){return"undefined"==typeof BigInt?re:e}function re(){throw new Error("BigInt not supported")}},N(B={exports:{}},B.exports),B.exports),M=2,D=1e3,H=1e10,x=1,L=null,j=99999,F=1e3,V=72072e3,G="default_genesis_hash_spec",W={headers:{"Content-Type":"application/json"}},z="2WayJS_KeypairLocalStorage";function $(e){switch(e){case"Success":return"success";case"Error":return"error";case"InProgress":return"pending";default:return"unknown"}}function q(e){return(new TextEncoder).encode(e)}function Y(e){for(var t=[];e.length>=2;)t.push(parseInt(e.substring(0,2),16)),e=e.substring(2,e.length);return new Uint8Array(t)}function Q(e){return Array.from(e,function(e){return("0"+(255&e).toString(16)).slice(-2)}).join("")}function J(e,t){return t=t||1,e<0||e>H*t?"N/A":0===e?e.toFixed(6):(void 0!==t?e/t:e).toFixed(6).replace(/\d(?=(\d{3})+\.)/g,"$&,")}function X(e){return new TextDecoder("utf-8").decode(e)}function Z(e,t){for(var r=function(e){return decodeURI(encodeURIComponent(e))}(e).substring(0,t);;){try{return re(r)}catch(e){}r=r.substring(0,r.length-1)}}function ee(e){return e.buffer.slice(e.byteOffset,e.byteLength+e.byteOffset)}function te(e,t){var r=new e.constructor(e.length+t.length);return r.set(e,0),r.set(t,e.length),r}function re(e){return decodeURIComponent(encodeURI(e))}function ne(e){if(e.isErr())throw new Error(e.error);return e.value}function oe(e){if("error"===e.status)throw new Error(e.reason?e.reason:v.UnknownError);return e}function ie(e,t){for(var r=0,n=C.Buffer.from(o(r+"-"+t),"hex");!Array.from(n).slice(0,e).every(function(e){return 0===e});)r++,n=C.Buffer.from(o(r+"-"+t),"hex");return r}function se(e){var t=ae();return{headers:{"x-cache-id":t,"x-nonce":e?ie(e,t):0}}}var ae=function(){return u().replace(/-/gi,"").toString().substring(0,32)},ue=function(e){var t={amount:0,genesis_hash:null,metadata:null};if("Item"in e.senderExpectation.asset){var r=e.senderExpectation.asset.Item;Object.assign.apply(Object,[r].concat(Object.entries(t).filter(function(e){return!(e[0]in r)}).map(function(e){var t;return(t={})[e[0]]=e[1],t}))),r.metadata=null,e.senderExpectation.asset.Item=r}if("Item"in e.receiverExpectation.asset){var n=e.receiverExpectation.asset.Item;Object.assign.apply(Object,[n].concat(Object.entries(t).filter(function(e){return!(e[0]in n)}).map(function(e){var t;return(t={})[e[0]]=e[1],t}))),n.metadata=null,e.receiverExpectation.asset.Item=n}return i(e)};function ce(e,t,r){if(e&&t){var n=ye(e,j);if(n.isErr())return s(n.error);var o=ye(e,L);if(o.isErr())return s(o.error);switch(t){case n.value:return i(j);case o.value:return i(null);default:return s(v.InvalidAddressVersion)}}else{if(null==r)return s(v.InvalidParametersProvided);switch(r){case j:return i(j);case L:return i(L);default:return s(v.InvalidAddressVersion)}}}function fe(){try{var e=new t;return i(e.toString())}catch(e){return s(v.UnableToGenerateSeed)}}function le(e){if(void 0===e)return s(v.NoPassPhraseProvided);try{var t=Z(o(e),32);return i(q(t))}catch(e){return s(v.UnableToGetPassphraseBuffer)}}function he(e,r){try{var n=e||t.Words.ENGLISH.join(" "),o=new t(n);return i({secret:o.toHDPrivateKey(r||""),seed:e||o.toString()})}catch(e){return s(v.InvalidSeedPhrase)}}function pe(e,t){void 0===e&&(e=L);try{t&&32!==t.length&&(t=t.slice(0,32));var r=t?a.sign.keyPair.fromSeed(t):a.sign.keyPair(),n=ne(ye(r.publicKey,e));return i({address:n,secretKey:r.secretKey,publicKey:r.publicKey,version:e})}catch(e){return s(v.UnableToGenerateKeypair)}}function de(e,t,r){void 0===r&&(r=L);try{return pe(r,q(e.secret.deriveChild(t,!0).xprivkey))}catch(e){return s(v.UnableToDeriveNextKeypair)}}function ye(e,t){switch(t){case x:return ge(e);case j:return Pe(e);case L:return me(e);default:return s(v.InvalidAddressVersion)}}function ge(e){try{var t=new Uint8Array([32,0,0,0,0,0,0,0]),r=e,n=new Uint8Array(t.length+r.length);n.set(t),n.set(r,t.length);var a=o(n);return ve(a,a.length-16),i(ve(a,a.length-16))}catch(e){return s(v.UnableToConstructDefaultAddress)}}var ve=function(e,t){return void 0===e&&(e=""),void 0===t&&(t=50),e.length>t?""+e.substring(0,t):e};function me(e){try{return i(o(e))}catch(e){return s(v.UnableToConstructDefaultAddress)}}function Pe(e){try{return i(o(Y(r(e))))}catch(e){return s(v.UnableToConstructTempAddress)}}function Ee(e,t){return a.sign.detached(t,e)}function Oe(e,t,r){void 0===t&&(t=L);var n=r.length,o=de(e,n);if(o.isErr())return s(o.error);var a=ye(o.value.publicKey,t);if(a.isErr())return s(a.error);for(;-1!=r.indexOf(a.value);){if((o=de(e,++n)).isErr())return s(o.error);if((a=ye(o.value.publicKey,t)).isErr())return s(a.error)}return i({address:a.value,secretKey:o.value.secretKey,publicKey:o.value.publicKey,version:t})}function be(e){return!he(e).isErr()}function we(){return fe().unwrapOr("")}function Ie(e){return h({},{Token:0},e)}function _e(e){return h({},{Item:{amount:0,genesis_hash:G,metadata:null}},e)}function Ae(e){return h({},{from:"",to:"",asset:Ie()},e)}function Ue(e){return h({},{druid:"",senderExpectation:Ae(),receiverExpectation:Ae(),status:"pending",mempoolHost:""},e)}var Te=function(e,t){return Ke(e)&&Ke(t)?i({Token:e.Token+t.Token}):ke(e)&&ke(t)&&e.Item.genesis_hash===t.Item.genesis_hash?i({Item:{amount:e.Item.amount+t.Item.amount,genesis_hash:e.Item.genesis_hash,metadata:e.Item.metadata}}):s(v.AssetsIncompatible)},Re=function(e,t){var r=Se(e,t);return r.isErr()?s(v.AssetsIncompatible):(r.isOk()&&!r.value&&s(v.AssetsIncompatible),Ke(e)&&Ke(t)&&r.value?i({Token:e.Token-t.Token}):ke(e)&&ke(t)&&e.Item.genesis_hash===t.Item.genesis_hash&&r.value?i({Item:{amount:e.Item.amount-t.Item.amount,genesis_hash:e.Item.genesis_hash,metadata:null}}):s(v.AssetsIncompatible))},Se=function(e,t){return Ke(e)&&Ke(t)?i(e.Token>=t.Token):ke(e)&&ke(t)&&e.Item.genesis_hash===t.Item.genesis_hash?i(e.Item.amount>=t.Item.amount):s(v.AssetsIncompatible)},Ne=function(e,t){return Ke(e)&&Ke(t)?i(e.Token>t.Token):ke(e)&&ke(t)&&e.Item.genesis_hash===t.Item.genesis_hash?i(e.Item.amount>t.Item.amount):s(v.AssetsIncompatible)},Be=function(e,t){return Ke(e)&&Ke(t)?i(e.Token<t.Token):ke(e)&&ke(t)&&e.Item.genesis_hash===t.Item.genesis_hash?i(e.Item.amount<t.Item.amount):s(v.AssetsIncompatible)},Ke=function(e){return Me(e,Ie())},ke=function(e){return Me(e,_e())},Ce=function(e){return Me(e,Ue())},Me=function(e,t){return Object.entries(t).every(function(r){var n=r[0];return n in e&&typeof e[n]==typeof t[n]})},De=function(e,t){return Ke(e)&&Ke(t)?i([e,t]):s(v.AssetsIncompatible)},He=function(e,t){return ke(e)&&ke(t)&&e.Item.genesis_hash===t.Item.genesis_hash?i([e,t]):s(v.AssetsIncompatible)},xe=function(e,t){return De(e,t).isOk()||He(e,t).isOk()},Le=function(e,t){try{var r=Object.keys(t).pop();if(void 0===r)return s(v.InvalidNetworkResponse);var n=[t[r][0],t[r][1]],o=n[1];return i({transactionHash:r,paymentAddress:n[0],asset:o.asset,metadata:o.metadata,usedAddresses:e})}catch(e){return s(v.InvalidNetworkResponse)}},je={scheme:["http","https"]},Fe=function(e){return{status:"error",reason:e.reduce(function(e,t){return t?e+t.message+", ":e},"").trim().replace(/,$/,"")}},Ve=function(e){return Object.prototype.hasOwnProperty.call(e,"Item")?Ge(e):We(e)},Ge=function(e){return c.object({Item:c.object({amount:c.number().required(),genesis_hash:c.string().required(),metadata:c.string().allow(null).required()}).required()}).validate(e)},We=function(e){return c.object({Token:c.number().required()}).validate(e)},ze=function(e){return c.string().required().validate(e)},$e=function(e){return c.string().custom(function(e,t){return Buffer.byteLength(e,"utf-8")>800?t.error("string.byteLength",{length:800}):e},"Byte Length Validation").validate(e)},qe=function(e){return c.string().pattern(new RegExp("(^g[a-f0-9]{31}$)|(^(000000)$)")).validate(e)},Ye=function(e){return c.string().pattern(new RegExp("^[a-f0-9]{64}$")).validate(e)},Qe=function(e){return c.string().pattern(new RegExp("^[a-zA-Z0-9-_]{0,30}$")).validate(e)},Je=function(e){return c.string().uri(je).validate(e)},Xe=function(e){return c.object({mempoolHost:c.string().uri(je).optional(),storageHost:c.string().uri(je).optional(),valenceHost:c.string().uri(je).optional(),passphrase:c.string().pattern(new RegExp("^[a-zA-Z0-9]{0,30}$")).required()}).validate(e)},Ze=function(e){return c.object({address:c.string().pattern(new RegExp("^[a-f0-9]{64}$")).required(),nonce:c.string().required(),save:c.string().required(),version:c.number().allow(null).required()}).validate(e)},et=function(e){return c.object({nonce:c.string().required(),save:c.string().required()}).validate(e)},tt=function(e){return c.string().regex(/^(\w+\s){11}\w+$/).required().validate(e)};function rt(e,t,r){return{address:e,data:t,data_id:r}}function nt(e,t){return{headers:h({},W.headers,{address:e,signature:Buffer.from(Ee(t.secretKey,Uint8Array.from(Buffer.from(e)))).toString("hex"),public_key:Buffer.from(t.publicKey).toString("hex")})}}function ot(e,t){try{var r=a.sign.detached(e,t);return i(Buffer.from(r).toString("hex"))}catch(e){return s(v.UnableToConstructSignature)}}function it(e){return o(st(e))}function st(e){return e?e.n+"-"+e.t_hash:null}function at(){try{var e=u().replace(/-/gi,"");return e=Z(o(e),32),i("DRUID0x"+e)}catch(e){return s(v.UnableToGenerateDruid)}}function ut(e){return Object.values(e.stack).map(function(e){return e.toString()}).join("-")}function ct(e){var t=q(e.map(function(e){var t=e.script_signature;if(t){var r=e.previous_out,n=dt(t.Pay2PkH.signable_data,t.Pay2PkH.signature,t.Pay2PkH.public_key,t.Pay2PkH.address_version);return n.isErr()?s(n.error):null!==r?st(r)+"-"+ut(n.value):"null-"+ut(n.value)}return s(v.UnableToConstructTxIns)}).join("-"));return i(o(t))}function ft(e){return Me(e,Ie())?o(q("Token:"+e.Token)):o(q("Item:"+e.Item.amount))}function lt(e,t){var r=JSON.stringify(e)||"",n=t.map(function(e){return JSON.stringify(e)||""}).join("");return o(""+n+r)}function ht(e,t,r){return e.createTx.inputs.map(function(n){if(n.script_signature&&n.previous_out){var o=pt(t,n.previous_out.t_hash),i=r.get(o);if(!i)return s(v.UnableToGetKeypair);var a=lt(n.previous_out,e.createTx.outputs);if(null===a)return s(v.UnableToConstructSignature);var u=ot(q(a),i.secretKey);if(u.isErr())return s(u.error);n.script_signature.Pay2PkH.signable_data=a,n.script_signature.Pay2PkH.signature=u.value}return n}),i(e)}function pt(e,t){return Object.keys(e.address_list).filter(function(r){return e.address_list[r].some(function(e){return e.out_point.t_hash===t})})[0]}function dt(e,t,r,n){var o=[];o.push(new I("Bytes",e)),o.push(new I("Signature",t)),o.push(new I("PubKey",r)),o.push(new I("Op","OP_DUP")),o.push(new I("Op",1===n||null===n?"OP_HASH256":"OP_HASH256_TEMP"));var a=ye(Y(r),n);return a.isErr()?s(a.error):(o.push(new I("Bytes",a.value)),o.push(new I("Op","OP_EQUALVERIFY")),o.push(new I("Op","OP_CHECKSIG")),i({stack:o}))}function yt(e,t,r){if(Ve(e).error)return s(v.InvalidInputs);var n=Me(e,Ie());if(n?e.Token<=t.total.tokens:e.Item.amount<=t.total.items[e.Item.genesis_hash]){var o=n?Ie():_e({Item:{amount:0,genesis_hash:e.Item.genesis_hash||"",metadata:e.Item.metadata||null}}),a=[],u=[],c=Object.entries(t.address_list).map(function(t){var n=t[0],c=t[1],f=[],l=r.get(n);if(!l)return s(v.UnableToGetKeypair);var h=0;return c.forEach(function(t){var r=t.out_point,p=t.value,d=Be(o,e);if(d.isErr())return s(d.error);var y=xe(e,p);if(d.value&&y){var g=lt(r,[]);if(null===g)return s(v.UnableToConstructSignature);var m=ot(q(g),l.secretKey);if(m.isErr())return s(m.error);var P=ce(l.publicKey,n);if(P.isErr())return s(P.error);var E={Pay2PkH:{signable_data:g||"",signature:m.value,public_key:Buffer.from(l.publicKey).toString("hex"),address_version:P.value}};f.push({previous_out:r,script_signature:E});var O=Te(p,o);if(O.isErr())return s(O.error);o=O.value,a.includes(n)||a.push(n),h++,c.length===h&&u.push(n)}return i([])}),i(f)});if(c.every(function(e){return e.isOk()})){var f=c.filter(function(e){return!!e}).reduce(function(e,t){return e.concat(t.value)},[]).filter(function(e){return!!e});return i({i