UNPKG

@2waychain/2wayjs

Version:

API wrapper to access the AIBlock 2 Way Chain

1 lines 85.9 kB
var e=require("axios"),r=require("bitcore-mnemonic"),t=require("byte-base64"),n=require("js-sha3"),o=require("neverthrow"),s=require("tweetnacl"),i=require("uuid"),a=require("joi"),u=require("bitcore-lib");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function l(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 f,p,h,d=/*#__PURE__*/c(e),y=/*#__PURE__*/c(r),g=/*#__PURE__*/c(s),I=/*#__PURE__*/c(a),v=/*#__PURE__*/l(u);function m(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 E(){return E=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},E.apply(this,arguments)}function P(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 O(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 P(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)?P(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.")}exports.IErrorAll=void 0,(f=exports.IErrorAll||(exports.IErrorAll={}))[f.IErrorInternal=0]="IErrorInternal",f[f.IErrorNetwork=1]="IErrorNetwork",exports.IErrorNetwork=void 0,(p=exports.IErrorNetwork||(exports.IErrorNetwork={})).InternalServerError="Internal Server Error",p.InvalidPassphrase="Invalid passphrase",p.BlankPassphrase="New passphrase cannot be blank",p.InvalidRequestBody="Invalid request body",p.CannotParseAddress="Cannot parse address",p.CannotAccessWallet="Cannot access wallet",p.CannotAccessUserNode="Cannot access user node",p.CannotAccessMempoolNode="Cannot access mempool node",p.CannotAccessPeerUserNode="Cannot access peer user node",p.CannotSaveAddressesToWallet="Cannot save address to wallet",p.CannotFetchBalance="Cannot fetch balance",p.NoDataFoundForKey="No data found for key",p.InternalError="Internal Error",p.Unauthorized="Unauthorized",p.MethodNotFound="Method not found",p.MethodNotAllowed="Method not allowed",p.BadRequest="Bad request",exports.IErrorInternal=void 0,(h=exports.IErrorInternal||(exports.IErrorInternal={})).InsufficientFunds="Insufficient funds",h.NoInputs="No inputs for transaction",h.InvalidInputs="Some inputs are invalid",h.UnableToGenerateDruid="Unable to generate DRUID",h.UnableToConstructTxIns="Unable to construct tx ins",h.UnableToConstructSignature="Unable to construct signature",h.UnableToGetKeypairFromMap="Unable to retrieve key-pair from map",h.InvalidAddressVersion="Unable to determine address version",h.InvalidParametersProvided="Invalid parameters provided",h.UnableToConstructOldAddress="Unable to construct old address",h.UnableToConstructTempAddress="Unable to construct temp address",h.UnableToConstructDefaultAddress="Unable to construct default address",h.UnableToGenerateSeed="Unable to generate seed",h.UnableToGetExistingSeed="Unable to get existing seed phrase",h.UnableToGetExistingMasterKey="Unable to get existing master key",h.UnableToGetPassphraseBuffer="Unable to get passphrase buffer",h.UnableToGetKeypair="Unable to get key-pair",h.UnableToGenerateMasterKey="Unable to generate master key",h.UnableToGenerateKeypair="Unable to generate key-pair",h.UnableToDeriveNextKeypair="Unable to derive next key-pair",h.UnableToEncryptKeypair="Unable to encrypt key-pair",h.UnableToSaveKeypairLocal="Unable to save key-pair to local storage",h.UnableToGetLocalKeypair="Unable to get key-pair from local storage",h.UnableToEncryptMasterKey="Unable to encrypt master key",h.UnableToDecryptKeypair="Unable to decrypt keypair",h.UnableToDecryptMasterKey="Unable to decrypt master key",h.MasterKeyCorrupt="Master key is corrupt",h.UnableToRegenAddresses="Unable to regenerate addresses",h.UnableToEncryptTransaction="Unable to encrypt transaction",h.UnableToDecryptTransaction="Unable to decrypt transaction",h.InvalidSeedPhrase="Invalid seed phrase",h.InvalidDRUIDProvided="Invalid DRUID value provided",h.UnableToFilterValenceData="Unable to filter valence data",h.ClientNotInitialized="Client not initialized",h.StorageNotInitialized="Storage host not initialized",h.ValenceNotInitialized="Valence host not initialized",h.FetchBalanceResponseEmpty="Balance object is empty",h.NoDRUIDValues="DRUID values are null",h.AssetsIncompatible="Assets are incompatible",h.KeyValuePairNotSingle="Key-value pair does not only have one element",h.UnableToFindNonEmptyAddresses="Unable to find addresses that contain assets",h.InvalidNetworkResponse="Invalid network response",h.UnableToSignMessage="Unable to sign message",h.UnableToVerifyMessage="Unable to verify message",h.NoHostsProvided="No hosts provided",h.NoKeypairsProvided="No key-pairs provided",h.NoPassPhraseProvided="No passphrase provided",h.NoComputeHostProvided="No compute host provided",h.NoContentReturned="No content returned",h.UnknownError="Unknown Error";var b,w,_,x,A,T,R=/*#__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}();exports.Op=void 0,(b=exports.Op||(exports.Op={}))[b.OP_0=0]="OP_0",b[b.OP_PUSHDATA1=76]="OP_PUSHDATA1",b[b.OP_PUSHDATA2=77]="OP_PUSHDATA2",b[b.OP_PUSHDATA4=78]="OP_PUSHDATA4",b[b.OP_1NEGATE=79]="OP_1NEGATE",b[b.OP_RESERVED=80]="OP_RESERVED",b[b.OP_1=81]="OP_1",b[b.OP_2=82]="OP_2",b[b.OP_3=83]="OP_3",b[b.OP_4=84]="OP_4",b[b.OP_5=85]="OP_5",b[b.OP_6=86]="OP_6",b[b.OP_7=87]="OP_7",b[b.OP_8=88]="OP_8",b[b.OP_9=89]="OP_9",b[b.OP_10=90]="OP_10",b[b.OP_11=91]="OP_11",b[b.OP_12=92]="OP_12",b[b.OP_13=93]="OP_13",b[b.OP_14=94]="OP_14",b[b.OP_15=95]="OP_15",b[b.OP_16=96]="OP_16",b[b.OP_NOP=97]="OP_NOP",b[b.OP_VER=98]="OP_VER",b[b.OP_IF=99]="OP_IF",b[b.OP_NOTIF=100]="OP_NOTIF",b[b.OP_VERIF=101]="OP_VERIF",b[b.OP_VERNOTIF=102]="OP_VERNOTIF",b[b.OP_ELSE=103]="OP_ELSE",b[b.OP_ENDIF=104]="OP_ENDIF",b[b.OP_VERIFY=105]="OP_VERIFY",b[b.OP_RETURN=106]="OP_RETURN",b[b.OP_TOALTSTACK=107]="OP_TOALTSTACK",b[b.OP_FROMALTSTACK=108]="OP_FROMALTSTACK",b[b.OP_2DROP=109]="OP_2DROP",b[b.OP_2DUP=110]="OP_2DUP",b[b.OP_3DUP=111]="OP_3DUP",b[b.OP_2OVER=112]="OP_2OVER",b[b.OP_2ROT=113]="OP_2ROT",b[b.OP_2SWAP=114]="OP_2SWAP",b[b.OP_IFDUP=115]="OP_IFDUP",b[b.OP_DEPTH=116]="OP_DEPTH",b[b.OP_DROP=117]="OP_DROP",b[b.OP_DUP=118]="OP_DUP",b[b.OP_NIP=119]="OP_NIP",b[b.OP_OVER=120]="OP_OVER",b[b.OP_PICK=121]="OP_PICK",b[b.OP_ROLL=122]="OP_ROLL",b[b.OP_ROT=123]="OP_ROT",b[b.OP_SWAP=124]="OP_SWAP",b[b.OP_TUCK=125]="OP_TUCK",b[b.OP_CAT=126]="OP_CAT",b[b.OP_SUBSTR=127]="OP_SUBSTR",b[b.OP_LEFT=128]="OP_LEFT",b[b.OP_RIGHT=129]="OP_RIGHT",b[b.OP_SIZE=130]="OP_SIZE",b[b.OP_INVERT=131]="OP_INVERT",b[b.OP_AND=132]="OP_AND",b[b.OP_OR=133]="OP_OR",b[b.OP_XOR=134]="OP_XOR",b[b.OP_EQUAL=135]="OP_EQUAL",b[b.OP_EQUALVERIFY=136]="OP_EQUALVERIFY",b[b.OP_RESERVED1=137]="OP_RESERVED1",b[b.OP_RESERVED2=138]="OP_RESERVED2",b[b.OP_1ADD=139]="OP_1ADD",b[b.OP_1SUB=140]="OP_1SUB",b[b.OP_2MUL=141]="OP_2MUL",b[b.OP_2DIV=142]="OP_2DIV",b[b.OP_NEGATE=143]="OP_NEGATE",b[b.OP_ABS=144]="OP_ABS",b[b.OP_NOT=145]="OP_NOT",b[b.OP_0NOTEQUAL=146]="OP_0NOTEQUAL",b[b.OP_ADD=147]="OP_ADD",b[b.OP_SUB=148]="OP_SUB",b[b.OP_MUL=149]="OP_MUL",b[b.OP_DIV=150]="OP_DIV",b[b.OP_MOD=151]="OP_MOD",b[b.OP_LSHIFT=152]="OP_LSHIFT",b[b.OP_RSHIFT=153]="OP_RSHIFT",b[b.OP_BOOLAND=154]="OP_BOOLAND",b[b.OP_BOOLOR=155]="OP_BOOLOR",b[b.OP_NUMEQUAL=156]="OP_NUMEQUAL",b[b.OP_NUMEQUALVERIFY=157]="OP_NUMEQUALVERIFY",b[b.OP_NUMNOTEQUAL=158]="OP_NUMNOTEQUAL",b[b.OP_LESSTHAN=159]="OP_LESSTHAN",b[b.OP_GREATERTHAN=160]="OP_GREATERTHAN",b[b.OP_LESSTHANOREQUAL=161]="OP_LESSTHANOREQUAL",b[b.OP_GREATERTHANOREQUAL=162]="OP_GREATERTHANOREQUAL",b[b.OP_MIN=163]="OP_MIN",b[b.OP_MAX=164]="OP_MAX",b[b.OP_WITHIN=165]="OP_WITHIN",b[b.OP_SHA256=168]="OP_SHA256",b[b.OP_HASH160=169]="OP_HASH160",b[b.OP_HASH256=170]="OP_HASH256",b[b.OP_CODESEPARATOR=171]="OP_CODESEPARATOR",b[b.OP_CHECKSIG=172]="OP_CHECKSIG",b[b.OP_CHECKSIGVERIFY=173]="OP_CHECKSIGVERIFY",b[b.OP_CHECKMULTISIG=174]="OP_CHECKMULTISIG",b[b.OP_CHECKMULTISIGVERIFY=175]="OP_CHECKMULTISIGVERIFY",b[b.OP_NOP1=176]="OP_NOP1",b[b.OP_CHECKLOCKTIMEVERIFY=177]="OP_CHECKLOCKTIMEVERIFY",b[b.OP_CHECKSEQUENCEVERIFY=178]="OP_CHECKSEQUENCEVERIFY",b[b.OP_NOP4=179]="OP_NOP4",b[b.OP_NOP5=180]="OP_NOP5",b[b.OP_NOP6=181]="OP_NOP6",b[b.OP_NOP7=182]="OP_NOP7",b[b.OP_NOP8=183]="OP_NOP8",b[b.OP_NOP9=184]="OP_NOP9",b[b.OP_NOP10=185]="OP_NOP10",b[b.OP_CREATE=192]="OP_CREATE",b[b.OP_INVALIDOPCODE=255]="OP_INVALIDOPCODE",b[b.OP_HASH256_V0=193]="OP_HASH256_V0",b[b.OP_HASH256_TEMP=194]="OP_HASH256_TEMP",exports.IAPIRoute=void 0,(w=exports.IAPIRoute||(exports.IAPIRoute={})).DebugData="/debug_data",w.FetchBalance="/fetch_balance",w.CreateTransactions="/create_transactions",w.CreateItemAsset="/create_item_asset",w.FetchPending="/fetch_pending",w.BlockchainEntry="/blockchain_entry",w.ValenceSet="/set_data",w.ValenceGet="/get_data",w.ValenceDel="/del_data",exports.IGenesisHashSpecification=void 0,(_=exports.IGenesisHashSpecification||(exports.IGenesisHashSpecification={})).Create="Create",_.Default="Default",exports.ISuccessAll=void 0,(x=exports.ISuccessAll||(exports.ISuccessAll={}))[x.IErrorInternal=0]="IErrorInternal",exports.ISuccessNetwork=void 0,(A=exports.ISuccessNetwork||(exports.ISuccessNetwork={})).FetchWalletInfo="Wallet info successfully fetched",A.ExportKeypairs="Key-pairs successfully exported",A.ImportKeypairs="Key-pairs successfully imported",A.GetPaymentAddress="New payment address generated",A.GetDebugData="Debug data successfully retrieved",A.GetLatestBlock="Current mining block successfully retrieved",A.UTXOAddressesRetrieved="UTXO addresses successfully retrieved",A.DataBaseItemsRetrieved="Database item(s) successfully retrieved",A.PaymentProcessing="Payment processing",A.IpPaymentProcessing="IP payment processing",A.DonationRequestSent="Donation request sent",A.RunningTotalUpdated="Running total updated",A.FetchBalance="Balance successfully fetched",A.FetchPendingTransactions="Pending transactions successfully fetched",A.CreateItemAssets="Item asset(s) created",A.CreateTransactions="Transaction(s) processing",A.ChangeWalletPassphrase="Passphrase changed successfully",A.ConstructAddress="Address successfully constructed",exports.ISuccessInternal=void 0,(T=exports.ISuccessInternal||(exports.ISuccessInternal={})).ClientInitialized="Client initialized",T.MessageSigned="Successfully signed message",T.MessageVirified="Successfully verified message",T.TwoWayPaymentProcessing="2-Way payment processing",T.Pending2WPaymentsFetched="Succesfully fetched pending 2 way transactions",T.AddressesReconstructed="Addresses have successfully been reconstructed",T.NewAddressGenerated="Successfully generated new address",T.SeedPhraseObtained="Successfully obtained seed phrase",T.MasterKeyObtained="Successfully obtained master key",T.KeypairDecrypted="Successfully decrypted key-pair",T.KeypairSaved="Successfully saved key-pair to local storage",T.KeypairObtained="Successfully retreived key-pair from local storage",T.RespondedTo2WPayment="Successfully responded to 2 way payment";for(var S=[],U=[],k="undefined"!=typeof Uint8Array?Uint8Array:Array,N="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",B=0;B<64;++B)S[B]=N[B],U[N.charCodeAt(B)]=B;function K(e,r,t){for(var n,o=[],s=r;s<t;s+=3)o.push(S[(n=(e[s]<<16&16711680)+(e[s+1]<<8&65280)+(255&e[s+2]))>>18&63]+S[n>>12&63]+S[n>>6&63]+S[63&n]);return o.join("")}U["-".charCodeAt(0)]=62,U["_".charCodeAt(0)]=63;var C,M,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,p=t?-1:1,h=e[r+f];for(f+=p,s=h&(1<<-l)-1,h>>=-l,l+=a;l>0;s=256*s+e[r+f],f+=p,l-=8);for(i=s&(1<<-l)-1,s>>=-l,l+=n;l>0;i=256*i+e[r+f],f+=p,l-=8);if(0===s)s=1-c;else{if(s===u)return i?NaN:Infinity*(h?-1:1);i+=Math.pow(2,n),s-=c}return(h?-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,p=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,h=n?0:s-1,d=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?p/u:p*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+h]=255&a,h+=d,a/=256,o-=8);for(i=i<<o|a,c+=o;c>0;e[t+h]=255&i,h+=d,i/=256,c-=8);e[t+h-d]|=128*y},L=(C=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|p(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 p(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 h(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 A(this,r,t);case"utf8":case"utf-8":return b(this,r,t);case"ascii":return _(this,r,t);case"latin1":case"binary":return x(this,r,t);case"base64":return O(this,r,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,r,t);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function d(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(K(e,i,i+s>a?a:i+s));return 1===n?o.push(S[(r=e[t-1])>>2]+S[r<<4&63]+"=="):2===n&&o.push(S[(r=(e[t-2]<<8)+e[t-1])>>10]+S[r>>4&63]+S[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=p,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)d(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)d(this,r,r+3),d(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)d(this,r,r+7),d(this,r+1,r+6),d(this,r+2,r+5),d(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):h.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 x(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 A(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 T(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 R(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 N(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 B(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 M(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||M(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||M(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||R(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||R(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||R(e,1,this.length),this[e]},s.prototype.readUint16LE=s.prototype.readUInt16LE=function(e,r){return e>>>=0,r||R(e,2,this.length),this[e]|this[e+1]<<8},s.prototype.readUint16BE=s.prototype.readUInt16BE=function(e,r){return e>>>=0,r||R(e,2,this.length),this[e]<<8|this[e+1]},s.prototype.readUint32LE=s.prototype.readUInt32LE=function(e,r){return e>>>=0,r||R(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||R(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||R(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||R(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||R(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},s.prototype.readInt16LE=function(e,r){e>>>=0,r||R(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||R(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||R(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||R(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||R(e,4,this.length),D(this,e,!0,23,4)},s.prototype.readFloatBE=function(e,r){return e>>>=0,r||R(e,4,this.length),D(this,e,!1,23,4)},s.prototype.readDoubleLE=function(e,r){return e>>>=0,r||R(e,8,this.length),D(this,e,!0,52,8)},s.prototype.readDoubleBE=function(e,r){return e>>>=0,r||R(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||N(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||N(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||N(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||N(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||N(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||N(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||N(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 B(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);N(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);N(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||N(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||N(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||N(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||N(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||N(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 B(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 k(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=U[e.charCodeAt(t)]<<18|U[e.charCodeAt(t+1)]<<12|U[e.charCodeAt(t+2)]<<6|U[e.charCodeAt(t+3)],i[a++]=r>>16&255,i[a++]=r>>8&255,i[a++]=255&r;return 2===s&&(r=U[e.charCodeAt(t)]<<2|U[e.charCodeAt(t+1)]>>4,i[a++]=255&r),1===s&&(r=U[e.charCodeAt(t)]<<10|U[e.charCodeAt(t+1)]<<4|U[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")}},C(M={exports:{}},M.exports),M.exports),j=2,F=1e3,V=1e10,G=1,W=null,z=99999,q=1e3,$="default_genesis_hash_spec",Y={headers:{"Content-Type":"application/json"}},Q="2WayJS_KeypairLocalStorage";function J(e){switch(e){case"Success":return"success";case"Error":return"error";case"InProgress":return"pending";default:return"unknown"}}function X(e){return(new TextEncoder).encode(e)}function Z(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 ee(e){return Array.from(e,function(e){return("0"+(255&e).toString(16)).slice(-2)}).join("")}function re(e){return new TextDecoder("utf-8").decode(e)}function te(e,r){for(var t=function(e){return decodeURI(encodeURIComponent(e))}(e).substring(0,r);;){try{return oe(t)}catch(e){}t=t.substring(0,t.length-1)}}function ne(e,r){var t=new e.constructor(e.length+r.length);return t.set(e,0),t.set(r,e.length),t}function oe(e){return decodeURIComponent(encodeURI(e))}function se(e){if(e.isErr())throw new Error(e.error);return e.value}function ie(e,r){for(var t=0,o=L.Buffer.from(n.sha3_256(t+"-"+r),"hex");!Array.from(o).slice(0,e).every(function(e){return 0===e});)t++,o=L.Buffer.from(n.sha3_256(t+"-"+r),"hex");return t}function ae(e){var r=ue();return{headers:{"x-cache-id":r,"x-nonce":e?ie(e,r):0}}}var ue=function(){return i.v4().replace(/-/gi,"").toString().substring(0,32)};function ce(e,r,t){if(e&&r){var n=ye(e,z);if(n.isErr())return o.err(n.error);var s=ye(e,W);if(s.isErr())return o.err(s.error);switch(r){case n.value:return o.ok(z);case s.value:return o.ok(null);default:return o.err(exports.IErrorInternal.InvalidAddressVersion)}}else{if(null==t)return o.err(exports.IErrorInternal.InvalidParametersProvided);switch(t){case z:return o.ok(z);case W:return o.ok(W);default:return o.err(exports.IErrorInternal.InvalidAddressVersion)}}}function le(){try{var e=new y.default;return o.ok(e.toString())}catch(e){return o.err(exports.IErrorInternal.UnableToGenerateSeed)}}function fe(e){if(void 0===e)return o.err(exports.IErrorInternal.NoPassPhraseProvided);try{var r=te(n.sha3_256(e),32);return o.ok(X(r))}catch(e){return o.err(exports.IErrorInternal.UnableToGetPassphraseBuffer)}}function pe(e,r){try{var t=e||y.default.Words.ENGLISH.join(" "),n=new y.default(t);return o.ok({secret:n.toHDPrivateKey(r||""),seed:e||n.toString()})}catch(e){return o.err(exports.IErrorInternal.InvalidSeedPhrase)}}function he(e,r){void 0===e&&(e=W);try{r&&32!==r.length&&(r=r.slice(0,32));var t=r?g.default.sign.keyPair.fromSeed(r):g.default.sign.keyPair(),n=se(ye(t.publicKey,e));return o.ok({address:n,secretKey:t.secretKey,publicKey:t.publicKey,version:e})}catch(e){return o.err(exports.IErrorInternal.UnableToGenerateKeypair)}}function de(e,r,t){void 0===t&&(t=W);try{return he(t,X(e.secret.deriveChild(r,!0).xprivkey))}catch(e){return o.err(exports.IErrorInternal.UnableToDeriveNextKeypair)}}function ye(e,r){switch(r){case G:return ge(e);case z:return me(e);case W:return ve(e);default:return o.err(exports.IErrorInternal.InvalidAddressVersion)}}function ge(e){try{var r=new Uint8Array([32,0,0,0,0,0,0,0]),t=e,s=new Uint8Array(r.length+t.length);s.set(r),s.set(t,r.length);var i=n.sha3_256(s);return Ie(i,i.length-16),o.ok(Ie(i,i.length-16))}catch(e){return o.err(exports.IErrorInternal.UnableToConstructDefaultAddress)}}var Ie=function(e,r){return void 0===e&&(e=""),void 0===r&&(r=50),e.length>r?""+e.substring(0,r):e};function ve(e){try{return o.ok(n.sha3_256(e))}catch(e){return o.err(exports.IErrorInternal.UnableToConstructDefaultAddress)}}function me(e){try{return o.ok(n.sha3_256(Z(t.bytesToBase64(e))))}catch(e){return o.err(exports.IErrorInternal.UnableToConstructTempAddress)}}function Ee(e,r){return g.default.sign.detached(r,e)}function Pe(e,r,t){void 0===r&&(r=W);var n=t.length,s=de(e,n);if(s.isErr())return o.err(s.error);var i=ye(s.value.publicKey,r);if(i.isErr())return o.err(i.error);for(;-1!=t.indexOf(i.value);){if((s=de(e,++n)).isErr())return o.err(s.error);if((i=ye(s.value.publicKey,r)).isErr())return o.err(i.error)}return o.ok({address:i.value,secretKey:s.value.secretKey,publicKey:s.value.publicKey,version:r})}function Oe(e){return E({},{Token:0},e)}function be(e){return E({},{Item:{amount:0,genesis_hash:$,metadata:null}},e)}function we(e){return E({},{from:"",to:"",asset:Oe()},e)}function _e(e){return E({},{druid:"",senderExpectation:we(),receiverExpectation:we(),status:"pending",mempoolHost:""},e)}var xe=function(e,r){return Ue(e)&&Ue(r)?o.ok({Token:e.Token+r.Token}):ke(e)&&ke(r)&&e.Item.genesis_hash===r.Item.genesis_hash?o.ok({Item:{amount:e.Item.amount+r.Item.amount,genesis_hash:e.Item.genesis_hash,metadata:e.Item.metadata}}):o.err(exports.IErrorInternal.AssetsIncompatible)},Ae=function(e,r){var t=Te(e,r);return t.isErr()?o.err(exports.IErrorInternal.AssetsIncompatible):(t.isOk()&&!t.value&&o.err(exports.IErrorInternal.AssetsIncompatible),Ue(e)&&Ue(r)&&t.value?o.ok({Token:e.Token-r.Token}):ke(e)&&ke(r)&&e.Item.genesis_hash===r.Item.genesis_hash&&t.value?o.ok({Item:{amount:e.Item.amount-r.Item.amount,genesis_hash:e.Item.genesis_hash,metadata:null}}):o.err(exports.IErrorInternal.AssetsIncompatible))},Te=function(e,r){return Ue(e)&&Ue(r)?o.ok(e.Token>=r.Token):ke(e)&&ke(r)&&e.Item.genesis_hash===r.Item.genesis_hash?o.ok(e.Item.amount>=r.Item.amount):o.err(exports.IErrorInternal.AssetsIncompatible)},Re=function(e,r){return Ue(e)&&Ue(r)?o.ok(e.Token>r.Token):ke(e)&&ke(r)&&e.Item.genesis_hash===r.Item.genesis_hash?o.ok(e.Item.amount>r.Item.amount):o.err(exports.IErrorInternal.AssetsIncompatible)},Se=function(e,r){return Ue(e)&&Ue(r)?o.ok(e.Token<r.Token):ke(e)&&ke(r)&&e.Item.genesis_hash===r.Item.genesis_hash?o.ok(e.Item.amount<r.Item.amount):o.err(exports.IErrorInternal.AssetsIncompatible)},Ue=function(e){return Ne(e,Oe())},ke=function(e){return Ne(e,be())},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(e,r){return Ue(e)&&Ue(r)?o.ok([e,r]):o.err(exports.IErrorInternal.AssetsIncompatible)},Ke=function(e,r){return ke(e)&&ke(r)&&e.Item.genesis_hash===r.Item.genesis_hash?o.ok([e,r]):o.err(exports.IErrorInternal.AssetsIncompatible)},Ce=function(e,r){return Be(e,r).isOk()||Ke(e,r).isOk()},Me=function(e,r){try{var t=Object.keys(r).pop();if(void 0===t)return o.err(exports.IErrorInternal.InvalidNetworkResponse);var n=[r[t][0],r[t][1]],s=n[1];return o.ok({transactionHash:t,paymentAddress:n[0],asset:s.asset,metadata:s.metadata,usedAddresses:e})}catch(e){return o.err(exports.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(/,$/,"")}},Le=function(e){return Object.prototype.hasOwnProperty.call(e,"Item")?je(e):Fe(e)},je=function(e){return I.default.object({Item:I.default.object({amount:I.default.number().required(),genesis_hash:I.default.string().required(),metadata:I.default.string().allow(null).required()}).required()}).validate(e)},Fe=function(e){return I.default.object({Token:I.default.number().required()}).validate(e)},Ve=function(e){return I.default.string().required().validate(e)},Ge=function(e){return I.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)},We=function(e){return I.default.string().pattern(new RegExp("(^g[a-f0-9]{31}$)|(^(000000)$)")).validate(e)},ze=function(e){return I.default.string().pattern(new RegExp("^[a-f0-9]{64}$")).validate(e)},qe=function(e){return I.default.string().uri(De).validate(e)},$e=function(e){return I.default.object({mempoolHost:I.default.string().uri(De).optional(),storageHost:I.default.string().uri(De).optional(),valenceHost:I.default.string().uri(De).optional(),passphrase:I.default.string().pattern(new RegExp("^[a-zA-Z0-9]{0,30}$")).required()}).validate(e)},Ye=function(e){return I.default.object({address:I.default.string().pattern(new RegExp("^[a-f0-9]{64}$")).required(),nonce:I.default.string().required(),save:I.default.string().required(),version:I.default.number().allow(null).required()}).validate(e)},Qe=function(e){return I.default.object({nonce:I.default.string().required(),save:I.default.string().required()}).validate(e)},Je=function(e){return I.default.string().regex(/^(\w+\s){11}\w+$/).required().validate(e)};function Xe(e,r,t){return{address:e,data:r,data_id:t}}function Ze(e,r){return{headers:E({},Y.headers,{address:e,signature:Buffer.from(Ee(r.secretKey,Uint8Array.from(Buffer.from(e)))).toString("hex"),public_key:Buffer.from(r.publicKey).toString("hex")})}}function er(e,r){try{var t=g.default.sign.detached(e,r);return o.ok(Buffer.from(t).toString("hex"))}catch(e){return o.err(exports.IErrorInternal.UnableToConstructSignature)}}function rr(e){return e?e.n+"-"+e.t_hash:null}function tr(){try{var e=i.v4().replace(/-/gi,"");return e=te(n.sha3_256(e),32),o.ok("DRUID0x"+e)}catch(e){return o.err(exports.IErrorInternal.UnableToGenerateDruid)}}function nr(e){return Object.values(e.stack).map(function(e){return e.toString()}).join("-")}function or(e){var r=X(e.map(function(e){var r=e.script_signature;if(r){var t=e.previous_out,n=cr(r.Pay2PkH.signable_data,r.Pay2PkH.signature,r.Pay2PkH.public_key,r.Pay2PkH.address_version);return n.isErr()?o.err(n.error):null!==t?rr(t)+"-"+nr(n.value):"null-"+nr(n.value)}return o.err(exports.IErrorInternal.UnableToConstructTxIns)}).join("-"));return o.ok(n.sha3_256(r))}function sr(e){return Ne(e,Oe())?n.sha3_256(X("Token:"+e.Token)):n.sha3_256(X("Item:"+e.Item.amount))}function ir(e,r){var t=JSON.stringify(e)||"",o=r.map(function(e){return JSON.stringify(e)||""}).join("");return n.sha3_256(""+o+t)}function ar(e,r,t){return e.createTx.inputs.map(function(n){if(n.script_signature&&n.previous_out){var s=ur(r,n.previous_out.t_hash),i=t.get(s);if(!i)return o.err(exports.IErrorInternal.UnableToGetKeypair);var a=ir(n.previous_out,e.createTx.outputs);if(null===a)return o.err(exports.IErrorInternal.UnableToConstructSignature);var u=er(X(a),i.secretKey);if(u.isErr())return o.err(u.error);n.script_signature.Pay2PkH.signable_data=a,n.script_signature.Pay2PkH.signature=u.value}return n}),o.ok(e)}function ur(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 cr(e,r,t,n){var s=[];s.push(new R("Bytes",e)),s.push(new R("Signature",r)),s.push(new R("PubKey",t)),s.push(new R("Op","OP_DUP")),s.push(new R("Op",1===n||null===n?"OP_HASH256":"OP_HASH256_TEMP"));var i=ye(Z(t),n);return i.isErr()?o.err(i.error):(s.push(new R("Bytes",i.value)),s.push(new R("Op","OP_EQUALVERIFY")),s.push(new R("Op","OP_CHECKSIG")),o.ok({stack:s}))}function lr(e,r,t){if(Le(e).error)return o.err(exports.IErrorInternal.InvalidInputs);var n=Ne(e,Oe());if(n?e.Token<=r.total.tokens:e.Item.amount<=r.total.items[e.Item.genesis_hash]){var s=n?Oe():be({Item:{amount:0,genesis_hash:e.Item.genesis_hash||"",metadata