import{aW as x}from"./index-DGZk149v.js";import{e as m}from"./vendor-react-DX7tU9aY.js";class w{constructor(e,r,o){this.name=e,this.prefix=r,this.baseEncode=o}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class g{constructor(e,r,o){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=o}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return l(this,e)}}class y{constructor(e){this.decoders=e}or(e){return l(this,e)}decode(e){const r=e[0],o=this.decoders[r];if(o)return o.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const l=(t,e)=>new y({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class E{constructor(e,r,o,s){this.name=e,this.prefix=r,this.baseEncode=o,this.baseDecode=s,this.encoder=new w(e,r,o),this.decoder=new g(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const A=({name:t,prefix:e,encode:r,decode:o})=>new E(t,e,r,o),C=(t,e,r,o)=>{const s={};for(let p=0;p<e.length;++p)s[e[p]]=p;let i=t.length;for(;t[i-1]==="=";)--i;const a=new Uint8Array(i*r/8|0);let n=0,c=0,h=0;for(let p=0;p<i;++p){const u=s[t[p]];if(u===void 0)throw new SyntaxError(`Non-${o} character`);c=c<<r|u,n+=r,n>=8&&(n-=8,a[h++]=255&c>>n)}if(n>=r||255&c<<8-n)throw new SyntaxError("Unexpected end of data");return a},P=(t,e,r)=>{const o=e[e.length-1]==="=",s=(1<<r)-1;let i="",a=0,n=0;for(let c=0;c<t.length;++c)for(n=n<<8|t[c],a+=8;a>r;)a-=r,i+=e[s&n>>a];if(a&&(i+=e[s&n<<r-a]),o)for(;i.length*r&7;)i+="=";return i},d=({name:t,prefix:e,bitsPerChar:r,alphabet:o})=>A({prefix:e,name:t,encode(s){return P(s,o,r)},decode(s){return C(s,o,r,t)}}),$=d({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),v=d({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),S=d({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),U=d({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),q=d({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),B=d({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),O=d({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),j=d({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),k=d({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5}),D=Object.freeze(Object.defineProperty({__proto__:null,base32:$,base32hex:q,base32hexpad:O,base32hexpadupper:j,base32hexupper:B,base32pad:S,base32padupper:U,base32upper:v,base32z:k},Symbol.toStringTag,{value:"Module"})),N=m(D);var f,b;function R(){if(b)return f;b=1;const{toBuffer:t,toAddress:e,toBase58:r,toHex:o}=x(),{base32:s}=N;return f={encode:n=>{if(!n)return n;const c=t(e(n));return s.encode(c)},decode:n=>{if(!n)return n;const c=s.decode(n),h=r(c);return h.length>30?h:o(c)}},f}export{R as r};
