"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
/*! *****************************************************************************
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 t=function(){return t=Object.assign||function(t){for(var r,e=1,s=arguments.length;e<s;e++)for(var n in r=arguments[e])Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n]);return t},t.apply(this,arguments)};var r="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var e=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),s=e?e[0].length:0,n=(t.length-s)*(Math.log(58)/Math.log(256))+1>>>0;return new Uint8Array([...new Uint8Array(s),...t.match(/.{1}/gmu).map((t=>r.indexOf(t))).reduce(((t,r)=>t=t.map((t=>{const e=58*t+r;return r=e>>8,e}))),new Uint8Array(n)).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=e;var n,o,i,h=(n=function(t,r){Object.defineProperty(r,"__esModule",{value:!0}),r.bech32m=r.bech32=void 0;const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l",s={};for(let t=0;t<32;t++){const r=e.charAt(t);s[r]=t}function n(t){const r=t>>25;return(33554431&t)<<5^996825010&-(r>>0&1)^642813549&-(r>>1&1)^513874426&-(r>>2&1)^1027748829&-(r>>3&1)^705979059&-(r>>4&1)}function o(t){let r=1;for(let e=0;e<t.length;++e){const s=t.charCodeAt(e);if(s<33||s>126)return"Invalid prefix ("+t+")";r=n(r)^s>>5}r=n(r);for(let e=0;e<t.length;++e){const s=t.charCodeAt(e);r=n(r)^31&s}return r}function i(t,r,e,s){let n=0,o=0;const i=(1<<e)-1,h=[];for(let s=0;s<t.length;++s)for(n=n<<r|t[s],o+=r;o>=e;)o-=e,h.push(n>>o&i);if(s)o>0&&h.push(n<<e-o&i);else{if(o>=r)return"Excess padding";if(n<<e-o&i)return"Non-zero padding"}return h}function h(t){return i(t,8,5,!0)}function c(t){const r=i(t,5,8,!1);if(Array.isArray(r))return r}function a(t){const r=i(t,5,8,!1);if(Array.isArray(r))return r;throw new Error(r)}function f(t){let r;function i(t,e){if(e=e||90,t.length<8)return t+" too short";if(t.length>e)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 a=t.slice(0,c),f=t.slice(c+1);if(f.length<6)return"Data too short";let p=o(a);if("string"==typeof p)return p;const d=[];for(let t=0;t<f.length;++t){const r=f.charAt(t),e=s[r];if(void 0===e)return"Unknown character "+r;p=n(p)^e,t+6>=f.length||d.push(e)}return p!==r?"Invalid checksum for "+t:{prefix:a,words:d}}return r="bech32"===t?1:734539939,{decodeUnsafe:function(t,r){const e=i(t,r);if("object"==typeof e)return e},decode:function(t,r){const e=i(t,r);if("object"==typeof e)return e;throw new Error(e)},encode:function(t,s,i){if(i=i||90,t.length+7+s.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<s.length;++t){const r=s[t];if(r>>5!=0)throw new Error("Non 5-bit word");h=n(h)^r,c+=e.charAt(r)}for(let t=0;t<6;++t)h=n(h);h^=r;for(let t=0;t<6;++t)c+=e.charAt(h>>5*(5-t)&31);return c},toWords:h,fromWordsUnsafe:c,fromWords:a}}r.bech32=f("bech32"),r.bech32m=f("bech32m")},n(o={exports:{}},o.exports),o.exports);(i=h)&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")&&i.default;var c=h.bech32m,a=h.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],p={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||w>=8e3)&&(l=new ArrayBuffer(8e3),w=0),this._byte=new Uint8Array(l,w,80),this._word=new Int32Array(l,w,20),w+=80}update(t){if("string"==typeof t)return this._utf8(t);if(null==t)throw new TypeError("Invalid type: "+typeof t);const r=t.byteOffset,e=t.byteLength;let s=e/64|0,n=0;if(s&&!(3&r)&&!(this._size%64)){const e=new Int32Array(t.buffer,r,16*s);for(;s--;)this._int32(e,n>>2),n+=64;this._size+=n}if(1!==t.BYTES_PER_ELEMENT&&t.buffer){const s=new Uint8Array(t.buffer,r+n,e-n);return this._uint8(s)}return n===e?this:this._uint8(t,n)}_uint8(t,r){const{_byte:e,_word:s}=this,n=t.length;for(r|=0;r<n;){const o=this._size%64;let i=o;for(;r<n&&i<64;)e[i++]=t[r++];i>=64&&this._int32(s),this._size+=i-o}return this}_utf8(t){const{_byte:r,_word:e}=this,s=t.length;let n=this._sp;for(let o=0;o<s;){const i=this._size%64;let h=i;for(;o<s&&h<64;){let e=0|t.charCodeAt(o++);e<128?r[h++]=e:e<2048?(r[h++]=192|e>>>6,r[h++]=128|63&e):e<55296||e>57343?(r[h++]=224|e>>>12,r[h++]=128|e>>>6&63,r[h++]=128|63&e):n?(e=((1023&n)<<10)+(1023&e)+65536,r[h++]=240|e>>>18,r[h++]=128|e>>>12&63,r[h++]=128|e>>>6&63,r[h++]=128|63&e,n=0):n=e}h>=64&&(this._int32(e),e[0]=e[16]),this._size+=h-i}return this._sp=n,this}_int32(t,r){let{A:e,B:s,C:n,D:o,E:i,F:h,G:c,H:a}=this,p=0;for(r|=0;p<16;)u[p++]=g(t[r++]);for(p=16;p<64;p++)u[p]=E(u[p-2])+u[p-7]+v(u[p-15])+u[p-16]|0;for(p=0;p<64;p++){const t=a+A(i)+b(i,h,c)+f[p]+u[p]|0,r=x(e)+_(e,s,n)|0;a=c,c=h,h=i,i=o+t|0,o=n,n=s,s=e,e=t+r|0}this.A=e+this.A|0,this.B=s+this.B|0,this.C=n+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:r,_word:e}=this;let s=this._size%64|0;for(r[s++]=128;3&s;)r[s++]=0;if(s>>=2,s>14){for(;s<16;)e[s++]=0;s=0,this._int32(e)}for(;s<16;)e[s++]=0;const n=8*this._size,o=(4294967295&n)>>>0,i=(n-o)/4294967296;return i&&(e[14]=g(i)),o&&(e[15]=g(o)),this._int32(e),"hex"===t?this._hex():this._bin()}_hex(){const{A:t,B:r,C:e,D:s,E:n,F:o,G:i,H:h}=this;return y(t)+y(r)+y(e)+y(s)+y(n)+y(o)+y(i)+y(h)}_bin(){const{A:t,B:r,C:e,D:s,E:n,F:o,G:i,H:h,_byte:c,_word:a}=this;return a[0]=g(t),a[1]=g(r),a[2]=g(e),a[3]=g(s),a[4]=g(n),a[5]=g(o),a[6]=g(i),a[7]=g(h),c.slice(0,32)}}const u=new Int32Array(64);let l,w=0;const y=t=>(t+4294967296).toString(16).substr(-8),g=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,r,e)=>e^t&(r^e),_=(t,r,e)=>t&r|e&(t|r),x=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,E=t=>(t>>>17|t<<15)^(t>>>19|t<<13)^t>>>10;var m,k,I=function(t){return function(t){if(t&&!p[t]&&!p[t.toLowerCase()])throw new Error("Digest method not supported");return new d}().update(t).digest()};exports.Network=void 0,(m=exports.Network||(exports.Network={})).mainnet="mainnet",m.testnet="testnet",m.regtest="regtest",exports.AddressType=void 0,(k=exports.AddressType||(exports.AddressType={})).p2pkh="p2pkh",k.p2sh="p2sh",k.p2wpkh="p2wpkh",k.p2wsh="p2wsh",k.p2tr="p2tr";var C={0:{type:exports.AddressType.p2pkh,network:exports.Network.mainnet},111:{type:exports.AddressType.p2pkh,network:exports.Network.testnet},5:{type:exports.AddressType.p2sh,network:exports.Network.mainnet},196:{type:exports.AddressType.p2sh,network:exports.Network.testnet}},N=function(r){var e,n=r.substr(0,2).toLowerCase();if("bc"===n||"tb"===n)return function(t){var r;try{r=t.startsWith("bc1p")||t.startsWith("tb1p")||t.startsWith("bcrt1p")?c.decode(t):a.decode(t)}catch(t){throw new Error("Invalid address")}var e={bc:exports.Network.mainnet,tb:exports.Network.testnet,bcrt:exports.Network.regtest}[r.prefix];if(void 0===e)throw new Error("Invalid address");var s=r.words[0];if(s<0||s>16)throw new Error("Invalid address");return{bech32:!0,network:e,address:t,type:20===a.fromWords(r.words.slice(1)).length?exports.AddressType.p2wpkh:1===s?exports.AddressType.p2tr:exports.AddressType.p2wsh}}(r);try{e=s(r)}catch(t){throw new Error("Invalid address")}var o=e.length;if(25!==o)throw new Error("Invalid address");var i=e[0],h=e.slice(o-4,o),f=e.slice(0,o-4),p=I(I(f)).slice(0,4);if(h.some((function(t,r){return t!==p[r]})))throw new Error("Invalid address");if(!Object.keys(C).map(Number).includes(i))throw new Error("Invalid address");return t(t({},C[i]),{address:r,bech32:!1})},T=function(t,r){try{var e=N(t);return!r||r===e.network}catch(t){return!1}};exports.default=T,exports.getAddressInfo=N,exports.validate=T;
