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