UNPKG

@2waychain/2wayjs

Version:

API wrapper to access the AIBlock 2 Way Chain

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