!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).AddressValidation={})}(this,(function(t){"use strict";window;
/*! *****************************************************************************
    Copyright (c) Microsoft Corporation.

    Permission to use, copy, modify, and/or distribute this software for any
    purpose with or without fee is hereby granted.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
    REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
    INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
    LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
    OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
    PERFORMANCE OF THIS SOFTWARE.
    ***************************************************************************** */var e=function(){return e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var s in e=arguments[r])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t},e.apply(this,arguments)};var r="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var n=t=>{if(!t||"string"!=typeof t)throw new Error(`Expected base58 string but got “${t}”`);if(t.match(/[IOl0]/gmu))throw new Error(`Invalid base58 character “${t.match(/[IOl0]/gmu)}”`);const e=t.match(/^1+/gmu),n=e?e[0].length:0,s=(t.length-n)*(Math.log(58)/Math.log(256))+1>>>0;return new Uint8Array([...new Uint8Array(n),...t.match(/.{1}/gmu).map((t=>r.indexOf(t))).reduce(((t,e)=>t=t.map((t=>{const r=58*t+e;return e=r>>8,r}))),new Uint8Array(s)).reverse().filter((o=!1,t=>o=o||t))]);var o};(()=>{const t=Array(256).fill(-1);for(let e=0;e<r.length;++e)t[r.charCodeAt(e)]=e})();var s=n;var o,i=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.bech32m=e.bech32=void 0;const r="qpzry9x8gf2tvdw0s3jn54khce6mua7l",n={};for(let t=0;t<32;t++){const e=r.charAt(t);n[e]=t}function s(t){const e=t>>25;return(33554431&t)<<5^996825010&-(e>>0&1)^642813549&-(e>>1&1)^513874426&-(e>>2&1)^1027748829&-(e>>3&1)^705979059&-(e>>4&1)}function o(t){let e=1;for(let r=0;r<t.length;++r){const n=t.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+t+")";e=s(e)^n>>5}e=s(e);for(let r=0;r<t.length;++r){const n=t.charCodeAt(r);e=s(e)^31&n}return e}function i(t,e,r,n){let s=0,o=0;const i=(1<<r)-1,h=[];for(let n=0;n<t.length;++n)for(s=s<<e|t[n],o+=e;o>=r;)o-=r,h.push(s>>o&i);if(n)o>0&&h.push(s<<r-o&i);else{if(o>=e)return"Excess padding";if(s<<r-o&i)return"Non-zero padding"}return h}function h(t){return i(t,8,5,!0)}function c(t){const e=i(t,5,8,!1);if(Array.isArray(e))return e}function f(t){const e=i(t,5,8,!1);if(Array.isArray(e))return e;throw new Error(e)}function a(t){let e;function i(t,r){if(r=r||90,t.length<8)return t+" too short";if(t.length>r)return"Exceeds length limit";const i=t.toLowerCase(),h=t.toUpperCase();if(t!==i&&t!==h)return"Mixed-case string "+t;const c=(t=i).lastIndexOf("1");if(-1===c)return"No separator character for "+t;if(0===c)return"Missing prefix for "+t;const f=t.slice(0,c),a=t.slice(c+1);if(a.length<6)return"Data too short";let d=o(f);if("string"==typeof d)return d;const u=[];for(let t=0;t<a.length;++t){const e=a.charAt(t),r=n[e];if(void 0===r)return"Unknown character "+e;d=s(d)^r,t+6>=a.length||u.push(r)}return d!==e?"Invalid checksum for "+t:{prefix:f,words:u}}return e="bech32"===t?1:734539939,{decodeUnsafe:function(t,e){const r=i(t,e);if("object"==typeof r)return r},decode:function(t,e){const r=i(t,e);if("object"==typeof r)return r;throw new Error(r)},encode:function(t,n,i){if(i=i||90,t.length+7+n.length>i)throw new TypeError("Exceeds length limit");let h=o(t=t.toLowerCase());if("string"==typeof h)throw new Error(h);let c=t+"1";for(let t=0;t<n.length;++t){const e=n[t];if(e>>5!=0)throw new Error("Non 5-bit word");h=s(h)^e,c+=r.charAt(e)}for(let t=0;t<6;++t)h=s(h);h^=e;for(let t=0;t<6;++t){c+=r.charAt(h>>5*(5-t)&31)}return c},toWords:h,fromWordsUnsafe:c,fromWords:f}}e.bech32=a("bech32"),e.bech32m=a("bech32m")}));(o=i)&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")&&o.default;var h=i.bech32m,c=i.bech32;const f=[1116352408,1899447441,-1245643825,-373957723,961987163,1508970993,-1841331548,-1424204075,-670586216,310598401,607225278,1426881987,1925078388,-2132889090,-1680079193,-1046744716,-459576895,-272742522,264347078,604807628,770255983,1249150122,1555081692,1996064986,-1740746414,-1473132947,-1341970488,-1084653625,-958395405,-710438585,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,-2117940946,-1838011259,-1564481375,-1474664885,-1035236496,-949202525,-778901479,-694614492,-200395387,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,-2067236844,-1933114872,-1866530822,-1538233109,-1090935817,-965641998],a={sha256:1};class d{constructor(){this.A=1779033703,this.B=-1150833019,this.C=1013904242,this.D=-1521486534,this.E=1359893119,this.F=-1694144372,this.G=528734635,this.H=1541459225,this._size=0,this._sp=0,(!l||p>=8e3)&&(l=new ArrayBuffer(8e3),p=0),this._byte=new Uint8Array(l,p,80),this._word=new Int32Array(l,p,20),p+=80}update(t){if("string"==typeof t)return this._utf8(t);if(null==t)throw new TypeError("Invalid type: "+typeof t);const e=t.byteOffset,r=t.byteLength;let n=r/64|0,s=0;if(n&&!(3&e)&&!(this._size%64)){const r=new Int32Array(t.buffer,e,16*n);for(;n--;)this._int32(r,s>>2),s+=64;this._size+=s}if(1!==t.BYTES_PER_ELEMENT&&t.buffer){const n=new Uint8Array(t.buffer,e+s,r-s);return this._uint8(n)}return s===r?this:this._uint8(t,s)}_uint8(t,e){const{_byte:r,_word:n}=this,s=t.length;for(e|=0;e<s;){const o=this._size%64;let i=o;for(;e<s&&i<64;)r[i++]=t[e++];i>=64&&this._int32(n),this._size+=i-o}return this}_utf8(t){const{_byte:e,_word:r}=this,n=t.length;let s=this._sp;for(let o=0;o<n;){const i=this._size%64;let h=i;for(;o<n&&h<64;){let r=0|t.charCodeAt(o++);r<128?e[h++]=r:r<2048?(e[h++]=192|r>>>6,e[h++]=128|63&r):r<55296||r>57343?(e[h++]=224|r>>>12,e[h++]=128|r>>>6&63,e[h++]=128|63&r):s?(r=((1023&s)<<10)+(1023&r)+65536,e[h++]=240|r>>>18,e[h++]=128|r>>>12&63,e[h++]=128|r>>>6&63,e[h++]=128|63&r,s=0):s=r}h>=64&&(this._int32(r),r[0]=r[16]),this._size+=h-i}return this._sp=s,this}_int32(t,e){let{A:r,B:n,C:s,D:o,E:i,F:h,G:c,H:a}=this,d=0;for(e|=0;d<16;)u[d++]=y(t[e++]);for(d=16;d<64;d++)u[d]=m(u[d-2])+u[d-7]+v(u[d-15])+u[d-16]|0;for(d=0;d<64;d++){const t=a+A(i)+b(i,h,c)+f[d]+u[d]|0,e=_(r)+g(r,n,s)|0;a=c,c=h,h=i,i=o+t|0,o=s,s=n,n=r,r=t+e|0}this.A=r+this.A|0,this.B=n+this.B|0,this.C=s+this.C|0,this.D=o+this.D|0,this.E=i+this.E|0,this.F=h+this.F|0,this.G=c+this.G|0,this.H=a+this.H|0}digest(t){const{_byte:e,_word:r}=this;let n=this._size%64|0;for(e[n++]=128;3&n;)e[n++]=0;if(n>>=2,n>14){for(;n<16;)r[n++]=0;n=0,this._int32(r)}for(;n<16;)r[n++]=0;const s=8*this._size,o=(4294967295&s)>>>0,i=(s-o)/4294967296;return i&&(r[14]=y(i)),o&&(r[15]=y(o)),this._int32(r),"hex"===t?this._hex():this._bin()}_hex(){const{A:t,B:e,C:r,D:n,E:s,F:o,G:i,H:h}=this;return w(t)+w(e)+w(r)+w(n)+w(s)+w(o)+w(i)+w(h)}_bin(){const{A:t,B:e,C:r,D:n,E:s,F:o,G:i,H:h,_byte:c,_word:f}=this;return f[0]=y(t),f[1]=y(e),f[2]=y(r),f[3]=y(n),f[4]=y(s),f[5]=y(o),f[6]=y(i),f[7]=y(h),c.slice(0,32)}}const u=new Int32Array(64);let l,p=0;const w=t=>(t+4294967296).toString(16).substr(-8),y=254===new Uint8Array(new Uint16Array([65279]).buffer)[0]?t=>t:t=>t<<24&4278190080|t<<8&16711680|t>>8&65280|t>>24&255,b=(t,e,r)=>r^t&(e^r),g=(t,e,r)=>t&e|r&(t|e),_=t=>(t>>>2|t<<30)^(t>>>13|t<<19)^(t>>>22|t<<10),A=t=>(t>>>6|t<<26)^(t>>>11|t<<21)^(t>>>25|t<<7),v=t=>(t>>>7|t<<25)^(t>>>18|t<<14)^t>>>3,m=t=>(t>>>17|t<<15)^(t>>>19|t<<13)^t>>>10;var E,k,x=function(t){return function(t){if(t&&!a[t]&&!a[t.toLowerCase()])throw new Error("Digest method not supported");return new d}().update(t).digest()};t.Network=void 0,(E=t.Network||(t.Network={})).mainnet="mainnet",E.testnet="testnet",E.regtest="regtest",t.AddressType=void 0,(k=t.AddressType||(t.AddressType={})).p2pkh="p2pkh",k.p2sh="p2sh",k.p2wpkh="p2wpkh",k.p2wsh="p2wsh",k.p2tr="p2tr";var I={0:{type:t.AddressType.p2pkh,network:t.Network.mainnet},111:{type:t.AddressType.p2pkh,network:t.Network.testnet},5:{type:t.AddressType.p2sh,network:t.Network.mainnet},196:{type:t.AddressType.p2sh,network:t.Network.testnet}},T=function(r){var n,o=r.substr(0,2).toLowerCase();if("bc"===o||"tb"===o)return function(e){var r;try{r=e.startsWith("bc1p")||e.startsWith("tb1p")||e.startsWith("bcrt1p")?h.decode(e):c.decode(e)}catch(t){throw new Error("Invalid address")}var n={bc:t.Network.mainnet,tb:t.Network.testnet,bcrt:t.Network.regtest}[r.prefix];if(void 0===n)throw new Error("Invalid address");var s=r.words[0];if(s<0||s>16)throw new Error("Invalid address");return{bech32:!0,network:n,address:e,type:20===c.fromWords(r.words.slice(1)).length?t.AddressType.p2wpkh:1===s?t.AddressType.p2tr:t.AddressType.p2wsh}}(r);try{n=s(r)}catch(t){throw new Error("Invalid address")}var i=n.length;if(25!==i)throw new Error("Invalid address");var f=n[0],a=n.slice(i-4,i),d=n.slice(0,i-4),u=x(x(d)).slice(0,4);if(a.some((function(t,e){return t!==u[e]})))throw new Error("Invalid address");if(!Object.keys(I).map(Number).includes(f))throw new Error("Invalid address");return e(e({},I[f]),{address:r,bech32:!1})},C=function(t,e){try{var r=T(t);return!e||e===r.network}catch(t){return!1}};t.default=C,t.getAddressInfo=T,t.validate=C,Object.defineProperty(t,"__esModule",{value:!0})}));
