@omnisat/lasereyes 0.0.89 → 0.0.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +16 -12
- package/dist/index.umd.cjs +2 -2
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -12531,7 +12531,7 @@ let I6 = class extends jn {
|
|
|
12531
12531
|
)), fe(this, "removeSubscriber");
|
|
12532
12532
|
}
|
|
12533
12533
|
get library() {
|
|
12534
|
-
return window.BitcoinProvider;
|
|
12534
|
+
return window == null ? void 0 : window.BitcoinProvider;
|
|
12535
12535
|
}
|
|
12536
12536
|
get network() {
|
|
12537
12537
|
return this.$network.get();
|
|
@@ -13881,7 +13881,8 @@ class h5 extends jn {
|
|
|
13881
13881
|
)), fe(this, "removeSubscriber");
|
|
13882
13882
|
}
|
|
13883
13883
|
get library() {
|
|
13884
|
-
|
|
13884
|
+
var t;
|
|
13885
|
+
return (t = window == null ? void 0 : window.magicEden) == null ? void 0 : t.bitcoin;
|
|
13885
13886
|
}
|
|
13886
13887
|
get network() {
|
|
13887
13888
|
return this.$network.get();
|
|
@@ -13900,11 +13901,11 @@ class h5 extends jn {
|
|
|
13900
13901
|
}
|
|
13901
13902
|
initialize() {
|
|
13902
13903
|
typeof window < "u" && typeof document < "u" && (this.observer = new window.MutationObserver(() => {
|
|
13903
|
-
var t;
|
|
13904
|
-
window
|
|
13904
|
+
var t, r;
|
|
13905
|
+
(t = window == null ? void 0 : window.magicEden) != null && t.bitcoin && (this.$store.setKey("hasProvider", {
|
|
13905
13906
|
...this.$store.get().hasProvider,
|
|
13906
13907
|
[Bi]: !0
|
|
13907
|
-
}), (
|
|
13908
|
+
}), (r = this.observer) == null || r.disconnect());
|
|
13908
13909
|
}), this.observer.observe(document, { childList: !0, subtree: !0 })), bn(this.$store, ["provider"], (t) => {
|
|
13909
13910
|
t.provider !== Bi ? this.removeSubscriber && (this.$valueStore.set({
|
|
13910
13911
|
address: "",
|
|
@@ -14102,7 +14103,8 @@ class f5 extends jn {
|
|
|
14102
14103
|
super(...arguments), fe(this, "observer");
|
|
14103
14104
|
}
|
|
14104
14105
|
get library() {
|
|
14105
|
-
|
|
14106
|
+
var t;
|
|
14107
|
+
return (t = window == null ? void 0 : window.phantom) == null ? void 0 : t.bitcoin;
|
|
14106
14108
|
}
|
|
14107
14109
|
get network() {
|
|
14108
14110
|
return this.$network.get();
|
|
@@ -27047,7 +27049,7 @@ class Y$ extends Dn {
|
|
|
27047
27049
|
)), de(this, "removeSubscriber");
|
|
27048
27050
|
}
|
|
27049
27051
|
get library() {
|
|
27050
|
-
return window.BitcoinProvider;
|
|
27052
|
+
return window == null ? void 0 : window.BitcoinProvider;
|
|
27051
27053
|
}
|
|
27052
27054
|
get network() {
|
|
27053
27055
|
return this.$network.get();
|
|
@@ -28398,7 +28400,8 @@ class N7 extends Dn {
|
|
|
28398
28400
|
)), de(this, "removeSubscriber");
|
|
28399
28401
|
}
|
|
28400
28402
|
get library() {
|
|
28401
|
-
|
|
28403
|
+
var t;
|
|
28404
|
+
return (t = window == null ? void 0 : window.magicEden) == null ? void 0 : t.bitcoin;
|
|
28402
28405
|
}
|
|
28403
28406
|
get network() {
|
|
28404
28407
|
return this.$network.get();
|
|
@@ -28417,11 +28420,11 @@ class N7 extends Dn {
|
|
|
28417
28420
|
}
|
|
28418
28421
|
initialize() {
|
|
28419
28422
|
typeof window < "u" && typeof document < "u" && (this.observer = new window.MutationObserver(() => {
|
|
28420
|
-
var t;
|
|
28421
|
-
window
|
|
28423
|
+
var t, r;
|
|
28424
|
+
(t = window == null ? void 0 : window.magicEden) != null && t.bitcoin && (this.$store.setKey("hasProvider", {
|
|
28422
28425
|
...this.$store.get().hasProvider,
|
|
28423
28426
|
[Zn]: !0
|
|
28424
|
-
}), (
|
|
28427
|
+
}), (r = this.observer) == null || r.disconnect());
|
|
28425
28428
|
}), this.observer.observe(document, { childList: !0, subtree: !0 })), An(this.$store, ["provider"], (t) => {
|
|
28426
28429
|
t.provider !== Zn ? this.removeSubscriber && (this.$valueStore.set({
|
|
28427
28430
|
address: "",
|
|
@@ -28619,7 +28622,8 @@ class B7 extends Dn {
|
|
|
28619
28622
|
super(...arguments), de(this, "observer");
|
|
28620
28623
|
}
|
|
28621
28624
|
get library() {
|
|
28622
|
-
|
|
28625
|
+
var t;
|
|
28626
|
+
return (t = window == null ? void 0 : window.phantom) == null ? void 0 : t.bitcoin;
|
|
28623
28627
|
}
|
|
28624
28628
|
get network() {
|
|
28625
28629
|
return this.$network.get();
|
package/dist/index.umd.cjs
CHANGED
|
@@ -26,7 +26,7 @@ PROCEED WITH CAUTION!
|
|
|
26
26
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
27
27
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
28
28
|
PERFORMANCE OF THIS SOFTWARE.
|
|
29
|
-
***************************************************************************** */var og="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";(()=>{const e=Array(256).fill(-1);for(let t=0;t<og.length;++t)e[og.charCodeAt(t)]=t})();var ag,Gh,zc,Xh=(ag=function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.bech32m=t.bech32=void 0;const r="qpzry9x8gf2tvdw0s3jn54khce6mua7l",n={};for(let d=0;d<32;d++){const g=r.charAt(d);n[g]=d}function i(d){const g=d>>25;return(33554431&d)<<5^996825010&-(g>>0&1)^642813549&-(g>>1&1)^513874426&-(g>>2&1)^1027748829&-(g>>3&1)^705979059&-(g>>4&1)}function o(d){let g=1;for(let v=0;v<d.length;++v){const E=d.charCodeAt(v);if(E<33||E>126)return"Invalid prefix ("+d+")";g=i(g)^E>>5}g=i(g);for(let v=0;v<d.length;++v){const E=d.charCodeAt(v);g=i(g)^31&E}return g}function s(d,g,v,E){let T=0,x=0;const N=(1<<v)-1,I=[];for(let k=0;k<d.length;++k)for(T=T<<g|d[k],x+=g;x>=v;)x-=v,I.push(T>>x&N);if(E)x>0&&I.push(T<<v-x&N);else{if(x>=g)return"Excess padding";if(T<<v-x&N)return"Non-zero padding"}return I}function a(d){return s(d,8,5,!0)}function u(d){const g=s(d,5,8,!1);if(Array.isArray(g))return g}function f(d){const g=s(d,5,8,!1);if(Array.isArray(g))return g;throw new Error(g)}function h(d){let g;function v(E,T){if(T=T||90,E.length<8)return E+" too short";if(E.length>T)return"Exceeds length limit";const x=E.toLowerCase(),N=E.toUpperCase();if(E!==x&&E!==N)return"Mixed-case string "+E;const I=(E=x).lastIndexOf("1");if(I===-1)return"No separator character for "+E;if(I===0)return"Missing prefix for "+E;const k=E.slice(0,I),R=E.slice(I+1);if(R.length<6)return"Data too short";let W=o(k);if(typeof W=="string")return W;const V=[];for(let Be=0;Be<R.length;++Be){const Le=R.charAt(Be),Je=n[Le];if(Je===void 0)return"Unknown character "+Le;W=i(W)^Je,Be+6>=R.length||V.push(Je)}return W!==g?"Invalid checksum for "+E:{prefix:k,words:V}}return g=d==="bech32"?1:734539939,{decodeUnsafe:function(E,T){const x=v(E,T);if(typeof x=="object")return x},decode:function(E,T){const x=v(E,T);if(typeof x=="object")return x;throw new Error(x)},encode:function(E,T,x){if(x=x||90,E.length+7+T.length>x)throw new TypeError("Exceeds length limit");let N=o(E=E.toLowerCase());if(typeof N=="string")throw new Error(N);let I=E+"1";for(let k=0;k<T.length;++k){const R=T[k];if(R>>5)throw new Error("Non 5-bit word");N=i(N)^R,I+=r.charAt(R)}for(let k=0;k<6;++k)N=i(N);N^=g;for(let k=0;k<6;++k)I+=r.charAt(N>>5*(5-k)&31);return I},toWords:a,fromWordsUnsafe:u,fromWords:f}}t.bech32=h("bech32"),t.bech32m=h("bech32m")},ag(Gh={exports:{}},Gh.exports),Gh.exports);(zc=Xh)&&zc.__esModule&&Object.prototype.hasOwnProperty.call(zc,"default")&&zc.default,Xh.bech32m,Xh.bech32,new Uint8Array(new Uint16Array([65279]).buffer)[0];var eo,to;(function(e){e.mainnet="mainnet",e.testnet="testnet",e.regtest="regtest"})(eo||(eo={})),function(e){e.p2pkh="p2pkh",e.p2sh="p2sh",e.p2wpkh="p2wpkh",e.p2wsh="p2wsh",e.p2tr="p2tr"}(to||(to={})),to.p2pkh,eo.mainnet,to.p2pkh,eo.testnet,to.p2sh,eo.mainnet,to.p2sh,eo.testnet;var Q8="accountChange";he({type:lt(Q8)});var e6="networkChange";he({type:lt(e6)});var t6="disconnect";he({type:lt(t6)});async function Jh(e){var t;const r=await(e==null?void 0:e())||((t=window.XverseProviders)==null?void 0:t.BitcoinProvider)||window.BitcoinProvider;if(!r)throw new Error("No Bitcoin wallet installed");return r}var cg=(e=>(e.Mainnet="Mainnet",e.Testnet="Testnet",e.Signet="Signet",e))(cg||{}),Yh=dn(Bc([ye(),Rn(),gs()])),dr=he({jsonrpc:lt("2.0"),method:ye(),params:dn(Bc([fn(Uc()),Ky({}),gs()])),id:Yh}),Wc=(e=>(e[e.PARSE_ERROR=-32700]="PARSE_ERROR",e[e.INVALID_REQUEST=-32600]="INVALID_REQUEST",e[e.METHOD_NOT_FOUND=-32601]="METHOD_NOT_FOUND",e[e.INVALID_PARAMS=-32602]="INVALID_PARAMS",e[e.INTERNAL_ERROR=-32603]="INTERNAL_ERROR",e[e.USER_REJECTION=-32e3]="USER_REJECTION",e[e.METHOD_NOT_SUPPORTED=-32001]="METHOD_NOT_SUPPORTED",e[e.ACCESS_DENIED=-32002]="ACCESS_DENIED",e))(Wc||{}),ug=he({jsonrpc:lt("2.0"),result:Mh(Uc()),id:Yh}),lg=he({jsonrpc:lt("2.0"),error:Mh(Uc()),id:Yh});Bc([ug,lg]);var qc=(e=>(e.Ordinals="ordinals",e.Payment="payment",e.Stacks="stacks",e))(qc||{}),hg=(e=>(e.p2pkh="p2pkh",e.p2sh="p2sh",e.p2wpkh="p2wpkh",e.p2wsh="p2wsh",e.p2tr="p2tr",e.stacks="stacks",e))(hg||{}),r6=he({address:ye(),publicKey:ye(),purpose:ys(qc),addressType:ys(hg)}),fg=async e=>{var t,r;const n=await Jh(e.getProvider),{purposes:i}=e.payload;if(!i)throw new Error("Address purposes are required");try{const o=Dr.createUnsecuredToken(e.payload),s=await n.connect(o);(t=e.onFinish)==null||t.call(e,s)}catch(o){console.error("[Connect] Error during address request",o),(r=e.onCancel)==null||r.call(e)}},n6="stx_getAddresses",i6=ws(he({message:dn(ye())}));he({...dr.entries,...he({method:lt(n6),params:i6,id:ye()}).entries});var s6="stx_signTransaction",o6=he({transaction:ye(),pubkey:dn(ye()),broadcast:dn(Ly())});he({...dr.entries,...he({method:lt(s6),params:o6,id:ye()}).entries});var a6=["software","ledger"],c6=jy(a6),u6="getInfo",l6=ws(gs());he({version:ye(),methods:dn(fn(ye())),supports:fn(ye())}),he({...dr.entries,...he({method:lt(u6),params:l6,id:ye()}).entries});var h6="getAddresses",f6=he({purposes:fn(ys(qc)),message:dn(ye())});he({...dr.entries,...he({method:lt(h6),params:f6,id:ye()}).entries});var d6="signMessage",Gc=(e=>(e.ECDSA="ECDSA",e.BIP322="BIP322",e))(Gc||{}),p6=he({address:ye(),message:ye(),protocol:dn(ys(Gc))});he({signature:ye(),messageHash:ye(),address:ye(),protocol:ys(Gc)}),he({...dr.entries,...he({method:lt(d6),params:p6,id:ye()}).entries});var y6="getAccounts",g6=he({purposes:fn(ys(qc)),message:dn(ye())});fn(he({...r6.entries,...he({walletType:c6}).entries})),he({...dr.entries,...he({method:lt(y6),params:g6,id:ye()}).entries});var w6="getBalance";ws(gs()),he({...dr.entries,...he({method:lt(w6),id:ye()}).entries});var b6="wallet_requestPermissions",m6=Fh();lt(!0),he({...dr.entries,...he({method:lt(b6),params:m6,id:ye()}).entries});var v6="wallet_renouncePermissions",E6=Fh();lt(!0),he({...dr.entries,...he({method:lt(v6),params:E6,id:ye()}).entries});var A6="wallet_getWalletType";ws(gs()),he({...dr.entries,...he({method:lt(A6),id:ye()}).entries});var S6="runes_getBalance",T6=ws(gs());he({balances:fn(he({runeName:ye(),amount:ye(),divisibility:Rn(),symbol:ye(),inscriptionId:ws(ye())}))}),he({...dr.entries,...he({method:lt(S6),params:T6,id:ye()}).entries});var _6="runes_transfer",k6=he({recipients:fn(he({runeName:ye(),amount:ye(),address:ye()}))});he({...dr.entries,...he({method:lt(_6),params:k6,id:ye()}).entries});var P6="ord_getInscriptions",O6=he({offset:Rn(),limit:Rn()});he({total:Rn(),limit:Rn(),offset:Rn(),inscriptions:fn(he({inscriptionId:ye(),inscriptionNumber:ye(),address:ye(),collectionName:dn(ye()),postage:ye(),contentLength:ye(),contentType:ye(),timestamp:Rn(),offset:Rn(),genesisTransaction:ye(),output:ye()}))}),he({...dr.entries,...he({method:lt(P6),params:O6,id:ye()}).entries});var I6="ord_sendInscriptions",x6=he({transfers:fn(he({address:ye(),inscriptionId:ye()}))});he({...dr.entries,...he({method:lt(I6),params:x6,id:ye()}).entries});var dg=async(e,t,r)=>{var n;let i=((n=window.XverseProviders)==null?void 0:n.BitcoinProvider)||window.BitcoinProvider;if(!i)throw new Error("no wallet provider was found");if(!e)throw new Error("A wallet method is required");const o=await i.request(e,t);return Hy(lg,o)?{status:"error",error:o.error}:Hy(ug,o)?{status:"success",result:o.result}:{status:"error",error:{code:-32603,message:"Received unknown response from provider.",data:o}}},$6=async e=>{var t,r;const n=await Jh(e.getProvider),{address:i,message:o}=e.payload;if(!i)throw new Error("An address is required to sign a message");if(!o)throw new Error("A message to be signed is required");try{const s=Dr.createUnsecuredToken(e.payload),a=await n.signMessage(s);(t=e.onFinish)==null||t.call(e,a)}catch(s){console.error("[Connect] Error during sign message request",s),(r=e.onCancel)==null||r.call(e)}},C6=e=>e.map(t=>{const{address:r,amountSats:n}=t;return{address:r,amountSats:n.toString()}}),N6=async e=>{var t,r;const n=await Jh(e.getProvider),{recipients:i,senderAddress:o,network:s,message:a}=e.payload;if(!i||i.length===0)throw new Error("At least one recipient is required");if(i.some(u=>typeof u.address!="string"||typeof u.amountSats!="bigint"))throw new Error("Incorrect recipient format");if(!o)throw new Error("The sender address is required");try{const u=C6(i),f={network:s,senderAddress:o,message:a,recipients:u},h=Dr.createUnsecuredToken(f),d=await n.sendBtcTransaction(h);(t=e.onFinish)==null||t.call(e,d)}catch(u){console.error("[Connect] Error during send BTC transaction request",u),(r=e.onCancel)==null||r.call(e)}};let pg=e=>e,ta={},Li={addEventListener(){},removeEventListener(){}};function B6(){try{return typeof localStorage<"u"}catch{return!1}}B6()&&(ta=localStorage),typeof window<"u"&&(Li={addEventListener(e,t,r){window.addEventListener("storage",t),window.addEventListener("pageshow",r)},removeEventListener(e,t,r){window.removeEventListener("storage",t),window.removeEventListener("pageshow",r)}});function ro(e,t={},r={}){let n=r.encode||pg,i=r.decode||pg,o=Ud(),s=o.setKey,a=(d,g)=>{typeof g>"u"?(r.listen!==!1&&Li.perKey&&Li.removeEventListener(e+d,f,h),delete ta[e+d]):(r.listen!==!1&&Li.perKey&&!(d in o.value)&&Li.addEventListener(e+d,f,h),ta[e+d]=n(g))};o.setKey=(d,g)=>{a(d,g),s(d,g)};let u=o.set;o.set=function(d){for(let g in d)a(g,d[g]);for(let g in o.value)g in d||a(g,void 0);u(d)};function f(d){d.key?d.key.startsWith(e)&&(d.newValue===null?s(d.key.slice(e.length),void 0):s(d.key.slice(e.length),i(d.newValue))):u({})}function h(){let d={...t};for(let g in ta)g.startsWith(e)&&(d[g.slice(e.length)]=i(ta[g]));for(let g in d)o.setKey(g,d[g])}return nm(o,()=>{if(h(),r.listen!==!1)return Li.addEventListener(e,f,h),()=>{Li.removeEventListener(e,f,h);for(let d in o.value)Li.removeEventListener(e+d,f,h)}}),o}const yg=["address","paymentAddress","publicKey","paymentPublicKey","balance"],U6="XVERSE_CONNECTED_WALLET_STATE";let R6=class extends ln{constructor(){super(...arguments),de(this,"observer"),de(this,"$valueStore",ro(U6,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),de(this,"removeSubscriber")}get library(){return window.BitcoinProvider}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of yg)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===In&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):yg.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){nn(this.$store,["provider"],t=>{t.provider!==In?this.removeSubscriber&&(this.$valueStore.set({address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))}),typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t,r;(t=window==null?void 0:window.XverseProviders)!=null&&t.BitcoinProvider&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[In]:!0}),(r=this.observer)==null||r.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0}))}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){const{address:r,paymentAddress:n}=this.$valueStore.get();try{if(r){this.restorePersistedValues(),zt(n,this.network).then(o=>{this.$store.setKey("balance",o)});return}let i=Vs(this.network||tt);await fg({payload:{purposes:["ordinals","payment"],message:"Address for receiving Ordinals and payments",network:{type:i}},onFinish:o=>{const s=jh(o.addresses),a=Dh(o.addresses);s&&a&&(this.$store.setKey("provider",In),this.$store.setKey("address",s.address),this.$store.setKey("paymentAddress",a.address)),this.$store.setKey("publicKey",String(o.addresses[0].publicKey)),this.$store.setKey("paymentPublicKey",String(o.addresses[1].publicKey)),zt(a.address,this.network).then(u=>{this.$store.setKey("balance",u)})},onCancel:()=>{throw new Error(`User canceled lasereyes to ${In} wallet`)},onError:o=>{throw new Error(`Can't lasereyes to ${In} wallet`)}}),this.$store.setKey("connected",!0)}catch(i){throw i}}async requestAccounts(){return[this.$store.get().address,this.$store.get().paymentAddress]}async getNetwork(){const{address:t}=this.$store.get();return t.slice(0,1)==="t"&&[it,Zt,Yt,Qt].includes(this.network)?this.network:tt}getPublicKey(){throw Hr}async getBalance(){const{paymentAddress:t}=this.$store.get();return await zt(t,this.network)}getInscriptions(){throw Hr}async sendBTC(t,r){const n=await dg("sendTransfer",{recipients:[{address:t,amount:r}]});if(n.status==="success")return n.result.txid;throw n.error.code===Wc.USER_REJECTION?new Error("User rejected the request"):new Error("Error sending BTC: "+n.error.message)}async signMessage(t,r){const n=r||this.$store.get().paymentAddress,i=await dg("signMessage",{address:n,message:t});if(i.status==="success")return i.result.signature;throw i.error.code===Wc.USER_REJECTION?new Error("User rejected the request"):new Error("Error signing message: "+i.error.message)}async signPsbt(t,r,n,i,o){const{address:s,paymentAddress:a}=this.$store.get(),u=ct.fromBase64(String(n),{network:er(this.network)}),f=u.data.inputs,h=[],d={address:s,signingIndexes:[]},g={address:a,signingIndexes:[]};let v=0;for await(let I of f){if(I.witnessUtxo===void 0)g.signingIndexes.push(Number(v));else{const{script:k}=I.witnessUtxo,R=Ko(k,er(this.network));R===a?g.signingIndexes.push(Number(v)):R===s&&d.signingIndexes.push(Number(v))}v++}d.signingIndexes.length>0&&h.push(d),g.signingIndexes.length>0&&h.push(g);let E,T,x;const N={payload:{network:{type:Vs(this.network)},message:"Sign Transaction",psbtBase64:u.toBase64(),broadcast:o,inputsToSign:h},onFinish:I=>{if(I.txId)E=I.txId;else if(I.psbtBase64){const k=ct.fromBase64(String(I.psbtBase64),{network:er(this.network)});T=k.toHex(),x=k.toBase64()}},onCancel:()=>console.log("Canceled")};return await signTransaction(N),{signedPsbtHex:T,signedPsbtBase64:x,txId:E}}pushPsbt(t){throw Hr}},H6=class extends ln{constructor(){super(...arguments),de(this,"observer")}get library(){return window.wizz}get network(){return this.$network.get()}handleNetworkChanged(t){this.parent.connect(os)}handleAccountsChanged(t){if(!t.length){this.parent.disconnect();return}this.$store.get().accounts[0]!==t[0]&&this.$store.setKey("accounts",t)}initialize(){nn(this.$store,["provider"],t=>{t.provider===os?this.addLibraryListeners():this.removeLibraryListeners()}),typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;this.library&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[os]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0}))}removeLibraryListeners(){var t,r;(t=this.library)==null||t.removeListener("networkChanged",this.handleNetworkChanged.bind(this)),(r=this.library)==null||r.removeListener("accountsChanged",this.handleAccountsChanged.bind(this))}addLibraryListeners(){var t,r;(t=this.library)==null||t.on("networkChanged",this.handleNetworkChanged.bind(this)),(r=this.library)==null||r.on("accountsChanged",this.handleAccountsChanged.bind(this))}dispose(){var t;(t=this.observer)==null||t.disconnect(),this.removeLibraryListeners()}async connect(){if(!this.library)throw I0;const t=await this.library.requestAccounts();if(!t)throw new Error("No accounts found");const r=await this.library.getPublicKey();if(!r)throw new Error("No public key found");this.$store.setKey("accounts",t),this.$store.setKey("address",t[0]),this.$store.setKey("paymentAddress",t[0]),this.$store.setKey("publicKey",r),this.$store.setKey("paymentPublicKey",r),this.$store.setKey("provider",os),await this.getNetwork().then(n=>{var i;n&&((i=this.config)==null?void 0:i.network)!==n&&this.parent.switchNetwork(n)}),await this.parent.getBalance(),this.$store.setKey("connected",!0)}async requestAccounts(){return await this.library.requestAccounts()}async getNetwork(){var t;const r=await((t=this.library)==null?void 0:t.getNetwork());return r?uh(r):void 0}async switchNetwork(t){var r;if(t===Qt||t===ls)return await this.library.switchNetwork(Fo);const n=uh(t);await((r=this.library)==null?void 0:r.switchNetwork(n)),this.$network.set(t),await this.parent.getBalance()}async getPublicKey(){var t;return await((t=this.library)==null?void 0:t.getPublicKey())}async getBalance(){return(await this.library.getBalance()).total}async getInscriptions(){return await this.library.getInscriptions(0,10)}async sendBTC(t,r){var n;const i=await((n=this.library)==null?void 0:n.sendBitcoin(t,r));if(i)return i;throw new Error("Error sending BTC")}async signMessage(t){var r;return await((r=this.library)==null?void 0:r.signMessage(t))}async signPsbt(t,r,n,i,o){var s;const a=await((s=this.library)==null?void 0:s.signPsbt(r,{autoFinalized:i,broadcast:!1})),u=ct.fromHex(a);let f;return i&&o&&(f=await this.pushPsbt(a)),{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:f}}async pushPsbt(t){return await qe.post(`${ti(this.$network.get())}/api/tx`,t).then(r=>r.data)}};const gg=["address","paymentAddress","publicKey","paymentPublicKey","balance"],L6="OYL_CONNECTED_WALLET_STATE";let K6=class extends ln{constructor(){super(...arguments),de(this,"observer"),de(this,"$valueStore",ro(L6,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),de(this,"removeSubscriber")}get library(){return window.oyl}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of gg)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===vi&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):gg.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;window!=null&&window.oyl&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[vi]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),nn(this.$store,["provider"],t=>{t.provider!==vi?this.removeSubscriber&&(this.$valueStore.set({address:"",publicKey:"",paymentAddress:"",paymentPublicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){if(!this.library)throw new Error("Oyl isn't installed");const{nativeSegwit:r,taproot:n}=await this.library.getAddresses();if(!r||!n)throw new Error("No accounts found");this.$store.setKey("address",n.address),this.$store.setKey("paymentAddress",r.address),this.$store.setKey("publicKey",n.publicKey),this.$store.setKey("paymentPublicKey",r.publicKey),this.$store.setKey("provider",vi),zt(r.address,this.network).then(o=>{this.$store.setKey("balance",o)}),this.$store.setKey("connected",!0);const i=await this.getBalance();i&&this.$store.setKey("balance",i)}async getNetwork(){return this.network}async sendBTC(t,r){const{psbtHex:n}=await Uy(this.$store.get().address,this.$store.get().paymentAddress,t,r,this.$store.get().paymentPublicKey,this.network,7),i=await this.signPsbt("",n,"",!0,!0);if(!i)throw new Error("Error sending BTC");return i.txId}async signMessage(t,r){const n=r||this.$store.get().paymentAddress;return(await this.library.signMessage({address:n,message:t})).signature}async signPsbt(t,r,n,i,o){const{psbt:s,txid:a}=await this.library.signPsbt({psbt:r,finalize:i,broadcast:o}),u=ct.fromHex(s);return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:a}}async pushPsbt(t){return(await this.library.pushPsbt({psbt:t})).txid}async getPublicKey(){var t;return await((t=this.library)==null?void 0:t.getPublicKey())}async getBalance(){const{total:t}=await this.library.getBalance();return this.$store.setKey("balance",t),t}async getInscriptions(){return await this.library.getInscriptions(0,10)}async requestAccounts(){return await this.library.requestAccounts()}async switchNetwork(){throw Hr}};const wg=["address","paymentAddress","publicKey","paymentPublicKey","balance"],j6="LEATHER_CONNECTED_WALLET_STATE";let D6=class extends ln{constructor(){super(...arguments),de(this,"observer"),de(this,"$valueStore",ro(j6,{address:"",publicKey:"",paymentAddress:"",paymentPublicKey:"",balance:""})),de(this,"removeSubscriber")}get library(){return window.LeatherProvider}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of wg)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===Ai&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):wg.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;window!=null&&window.LeatherProvider&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Ai]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),nn(this.$store,["provider"],t=>{t.provider!==Ai?this.removeSubscriber&&(this.$valueStore.set({address:"",publicKey:"",paymentAddress:"",paymentPublicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){var r;if(!this.library)throw new Error("Leather isn't installed");const n=await this.library.request("getAddresses");if(!n)throw new Error("No accounts found");const i=n.result.addresses,o=i.map(u=>u.address),s=i.find(u=>u.type===Ha),a=i.find(u=>u.type===gl);if(!(s!=null&&s.publicKey)||!(a!=null&&a.publicKey))throw new Error("No accounts found");if((r=String(s==null?void 0:s.address))!=null&&r.startsWith("tb")&&this.network!==it&&this.network!==Zt&&this.network!==Yt)throw new Error(`Please switch networks to ${this.network} in the wallet settings.`);this.$store.setKey("accounts",o),this.$store.setKey("address",s.address),this.$store.setKey("paymentAddress",a.address),this.$store.setKey("publicKey",s.publicKey),this.$store.setKey("paymentPublicKey",a.publicKey),this.$store.setKey("provider",Ai),zt(a.address,this.network).then(u=>{this.$store.setKey("balance",u)}),this.$store.setKey("connected",!0)}async getNetwork(){return this.network}async sendBTC(t,r){var n,i;const o=await((n=this.library)==null?void 0:n.request("sendTransfer",{recipients:[{address:t,amount:r}]}));if((i=o==null?void 0:o.result)!=null&&i.txid)return o.result.txid;throw o.error.code===Wc.USER_REJECTION?new Error("User rejected the request"):new Error("Error sending BTC: "+o.error.message)}async signMessage(t,r){var n;const i=r===this.$store.get().address?Ha:gl;if(r!==this.$store.get().address&&r!==this.$store.get().paymentAddress)throw new Error("Invalid address to sign message");const o=await this.library.request("signMessage",{message:t,paymentType:i});return(n=o==null?void 0:o.result)==null?void 0:n.signature}async signPsbt(t,r,n,i,o){const s={hex:r,broadcast:!1,network:this.network},a=(await this.library.request("signPsbt",s)).result.hex,u=ct.fromHex(String(a));if(i&&o){const f=u.finalizeAllInputs(),h=await this.pushPsbt(f.toHex());return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:h}}else if(i){const f=u.finalizeAllInputs();return{signedPsbtHex:f.toHex(),signedPsbtBase64:f.toBase64(),txId:void 0}}else return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:void 0}}async pushPsbt(t){const r=ct.fromHex(t).extractTransaction();return await qe.post(`${ti(this.network)}/api/tx`,r.toHex()).then(n=>n.data)}async getPublicKey(){const{result:t}=await this.library.request("getAddresses"),r=t.addresses.find(n=>n.type===Ha);if(!(r!=null&&r.publicKey))throw new Error("No accounts found");return r.publicKey}async getBalance(){const t=await zt(this.$store.get().paymentAddress,this.network);return this.$store.setKey("balance",t),t.toString()}async getInscriptions(){throw Hr}async requestAccounts(){const{result:t}=await this.library.request("getAddresses"),r=t.addresses.map(n=>n.address);return this.$store.setKey("accounts",r),r}async switchNetwork(){throw Hr}};var Zh={},bg={},pn={},mg={};Object.defineProperty(mg,"__esModule",{value:!0}),function(e){var t=Se&&Se.__createBinding||(Object.create?function(s,a,u,f){f===void 0&&(f=u);var h=Object.getOwnPropertyDescriptor(a,u);(!h||("get"in h?!a.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(s,f,h)}:function(s,a,u,f){f===void 0&&(f=u),s[f]=a[u]}),r=Se&&Se.__exportStar||function(s,a){for(var u in s)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,s,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.getProviderById=e.getProviders=e.getProviderOrThrow=void 0;async function n(s){var a,u;if(s){const h=await s();if(h)return h}const f=window.OrangeBitcoinProvider||((a=window.OrangecryptoProviders)==null?void 0:a.BitcoinProvider)||((u=window.OrangeWalletProviders)==null?void 0:u.OrangeBitcoinProvider);if(!f)throw new Error("No Orange Bitcoin wallet installed");return f}e.getProviderOrThrow=n;function i(){return window.btc_providers||(window.btc_providers=[]),window.btc_providers}e.getProviders=i;function o(s){var a;if(Array.isArray(window.btc_providers)){const u=window.btc_providers.find(f=>f.id===s);return(a=u==null?void 0:u.id)==null?void 0:a.split(".").reduce((f,h)=>f==null?void 0:f[h],window)}else{console.log("window.btc_providers is not defined or not an array");return}}e.getProviderById=o,r(mg,e)}(pn);var vg={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.AddressType=e.AddressPurpose=void 0,function(t){t.Ordinals="ordinals",t.Payment="payment",t.Stacks="stacks"}(e.AddressPurpose||(e.AddressPurpose={})),function(t){t.p2pkh="p2pkh",t.p2sh="p2sh",t.p2wpkh="p2wpkh",t.p2wsh="p2wsh",t.p2tr="p2tr",t.stacks="stacks"}(e.AddressType||(e.AddressType={}))})(vg),function(e){var t=Se&&Se.__createBinding||(Object.create?function(s,a,u,f){f===void 0&&(f=u);var h=Object.getOwnPropertyDescriptor(a,u);(!h||("get"in h?!a.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(s,f,h)}:function(s,a,u,f){f===void 0&&(f=u),s[f]=a[u]}),r=Se&&Se.__exportStar||function(s,a){for(var u in s)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,s,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.getAddress=void 0;const n=Dr,i=pn,o=async s=>{var a,u;const f=await(0,i.getProviderOrThrow)(s.getProvider),{purposes:h}=s.payload;if(!h)throw new Error("Address purposes are required");try{const d=(0,n.createUnsecuredToken)(s.payload),g=await f.connect(d);(a=s.onFinish)==null||a.call(s,g)}catch(d){console.error("[Connect] Error during address request",d),(u=s.onCancel)==null||u.call(s)}};e.getAddress=o,r(vg,e)}(bg);var Eg={},Ag={},Sg={};Object.defineProperty(Sg,"__esModule",{value:!0});var Tg={};Object.defineProperty(Tg,"__esModule",{value:!0}),function(e){var t=Se&&Se.__createBinding||(Object.create?function(n,i,o,s){s===void 0&&(s=o);var a=Object.getOwnPropertyDescriptor(i,o);(!a||("get"in a?!i.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return i[o]}}),Object.defineProperty(n,s,a)}:function(n,i,o,s){s===void 0&&(s=o),n[s]=i[o]}),r=Se&&Se.__exportStar||function(n,i){for(var o in n)o!=="default"&&!Object.prototype.hasOwnProperty.call(i,o)&&t(i,n,o)};Object.defineProperty(e,"__esModule",{value:!0}),r(Sg,e),r(Tg,e)}(Ag),function(e){var t=Se&&Se.__createBinding||(Object.create?function(s,a,u,f){f===void 0&&(f=u);var h=Object.getOwnPropertyDescriptor(a,u);(!h||("get"in h?!a.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(s,f,h)}:function(s,a,u,f){f===void 0&&(f=u),s[f]=a[u]}),r=Se&&Se.__exportStar||function(s,a){for(var u in s)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,s,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.request=void 0;const n=pn,i=async(s,a,u)=>{var f;let h=((f=window.OrangecryptoProviders)==null?void 0:f.BitcoinProvider)||window.OrangeBitcoinProvider;if(u&&(h=await(0,n.getProviderById)(u)),!h)throw new Error("no wallet provider was found");if(!s)throw new Error("A wallet method is required");const d=await h.request(s,a);return o(d)?{status:"success",result:d.result}:{status:"error",error:d.error}};e.request=i;const o=s=>Object.hasOwn(s,"result")&&!!s.result;r(Ag,e)}(Eg);var _g={},kg={};Object.defineProperty(kg,"__esModule",{value:!0}),function(e){var t=Se&&Se.__createBinding||(Object.create?function(a,u,f,h){h===void 0&&(h=f);var d=Object.getOwnPropertyDescriptor(u,f);(!d||("get"in d?!u.__esModule:d.writable||d.configurable))&&(d={enumerable:!0,get:function(){return u[f]}}),Object.defineProperty(a,h,d)}:function(a,u,f,h){h===void 0&&(h=f),a[h]=u[f]}),r=Se&&Se.__exportStar||function(a,u){for(var f in a)f!=="default"&&!Object.prototype.hasOwnProperty.call(u,f)&&t(u,a,f)};Object.defineProperty(e,"__esModule",{value:!0}),e.getCapabilities=void 0;const n=Dr,i=pn,o=(a,u)=>{const f=d=>!(!a[d]||u&&!u.has(d)),h={request:f("request"),connect:f("connect"),signMessage:f("signMessage"),signTransaction:f("signTransaction"),sendBtcTransaction:f("sendBtcTransaction"),createInscription:f("createInscription"),createRepeatInscriptions:f("createRepeatInscriptions"),signMultipleTransactions:f("signMultipleTransactions")};return Object.entries(h).reduce((d,[g,v])=>v?[...d,g]:d,[])},s=async a=>{var u,f,h;const d=await(0,i.getProviderOrThrow)(a.getProvider),g=(0,n.createUnsecuredToken)(a.payload);if(d.getCapabilities)try{const v=await d.getCapabilities(g);(u=a.onFinish)==null||u.call(a,o(d,new Set(v)))}catch(v){console.error("[Connect] Error during capabilities request",v)}try{const v=o(d);(f=a.onFinish)==null||f.call(a,v)}catch(v){console.error("[Connect] Error during capabilities request",v),(h=a.onCancel)==null||h.call(a)}};e.getCapabilities=s,r(kg,e)}(_g);var Pg={},Xc={},ra={};Object.defineProperty(ra,"__esModule",{value:!0}),ra.validateInscriptionPayload=void 0;const M6=4e5,F6=6e4,V6=e=>{const{contentType:t,content:r,payloadType:n,network:i,appFeeAddress:o,appFee:s}=e;if(!/^[a-z]+\/[a-z0-9\-\.\+]+(?=;.*|$)/.test(t))throw new Error("Invalid content type detected");if(!r||r.length===0)throw new Error("Empty content not allowed");if(!n||n!=="BASE_64"&&n!=="PLAIN_TEXT")throw new Error("Empty invalid payloadType specified");if(r.length>(i.type==="Mainnet"?M6:F6))throw new Error("Content too large");if(((o==null?void 0:o.length)??0)>0&&(s??0)<=0)throw new Error("Invalid combination of app fee address and fee provided")};ra.validateInscriptionPayload=V6,Object.defineProperty(Xc,"__esModule",{value:!0}),Xc.createInscription=void 0;const z6=Dr,W6=pn,q6=ra,G6=async e=>{var t,r;const{getProvider:n}=e,i=await(0,W6.getProviderOrThrow)(n);(0,q6.validateInscriptionPayload)(e.payload);try{const o=(0,z6.createUnsecuredToken)(e.payload),s=await i.createInscription(o);(t=e.onFinish)==null||t.call(e,s)}catch(o){console.error("[Connect] Error during create inscription",o),(r=e.onCancel)==null||r.call(e)}};Xc.createInscription=G6;var Jc={};Object.defineProperty(Jc,"__esModule",{value:!0}),Jc.createRepeatInscriptions=void 0;const X6=pn,J6=Dr,Y6=ra,Z6=async e=>{var t,r;const{getProvider:n}=e,i=await(0,X6.getProviderOrThrow)(n);(0,Y6.validateInscriptionPayload)(e.payload);try{const o=(0,J6.createUnsecuredToken)(e.payload),s=await i.createRepeatInscriptions(o);(t=e.onFinish)==null||t.call(e,s)}catch(o){console.error("[Connect] Error during create repeat inscriptions",o),(r=e.onCancel)==null||r.call(e)}};Jc.createRepeatInscriptions=Z6;var Og={};Object.defineProperty(Og,"__esModule",{value:!0}),function(e){var t=Se&&Se.__createBinding||(Object.create?function(n,i,o,s){s===void 0&&(s=o);var a=Object.getOwnPropertyDescriptor(i,o);(!a||("get"in a?!i.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return i[o]}}),Object.defineProperty(n,s,a)}:function(n,i,o,s){s===void 0&&(s=o),n[s]=i[o]}),r=Se&&Se.__exportStar||function(n,i){for(var o in n)o!=="default"&&!Object.prototype.hasOwnProperty.call(i,o)&&t(i,n,o)};Object.defineProperty(e,"__esModule",{value:!0}),r(Xc,e),r(Jc,e),r(Og,e)}(Pg);var Ig={},xg={};Object.defineProperty(xg,"__esModule",{value:!0}),function(e){var t=Se&&Se.__createBinding||(Object.create?function(s,a,u,f){f===void 0&&(f=u);var h=Object.getOwnPropertyDescriptor(a,u);(!h||("get"in h?!a.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(s,f,h)}:function(s,a,u,f){f===void 0&&(f=u),s[f]=a[u]}),r=Se&&Se.__exportStar||function(s,a){for(var u in s)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,s,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.signMessage=void 0;const n=Dr,i=pn,o=async s=>{var a,u;const f=await(0,i.getProviderOrThrow)(s.getProvider),{address:h,message:d}=s.payload;if(!h)throw new Error("An address is required to sign a message");if(!d)throw new Error("A message to be signed is required");try{const g=(0,n.createUnsecuredToken)(s.payload),v=await f.signMessage(g);(a=s.onFinish)==null||a.call(s,v)}catch(g){console.error("[Connect] Error during sign message request",g),(u=s.onCancel)==null||u.call(s)}};e.signMessage=o,r(xg,e)}(Ig);var $g={},Yc={};Object.defineProperty(Yc,"__esModule",{value:!0}),Yc.sendBtcTransaction=void 0;const Q6=Dr,e5=pn,t5=e=>e.map(t=>{const{address:r,amountSats:n}=t;return{address:r,amountSats:n.toString()}}),r5=async e=>{var t,r;const n=await(0,e5.getProviderOrThrow)(e.getProvider),{recipients:i,senderAddress:o,network:s,message:a}=e.payload;if(!i||i.length===0)throw new Error("At least one recipient is required");if(i.some(u=>typeof u.address!="string"||typeof u.amountSats!="bigint"))throw new Error("Incorrect recipient format");if(!o)throw new Error("The sender address is required");try{const u=t5(i),f={network:s,senderAddress:o,message:a,recipients:u},h=(0,Q6.createUnsecuredToken)(f),d=await n.sendBtcTransaction(h);(t=e.onFinish)==null||t.call(e,d)}catch(u){console.error("[Connect] Error during send BTC transaction request",u),(r=e.onCancel)==null||r.call(e)}};Yc.sendBtcTransaction=r5;var Zc={};Object.defineProperty(Zc,"__esModule",{value:!0}),Zc.signTransaction=void 0;const n5=Dr,i5=pn,s5=async e=>{var t,r;const n=await(0,i5.getProviderOrThrow)(e.getProvider),{psbtBase64:i,inputsToSign:o}=e.payload;if(!i)throw new Error("A value for psbtBase64 representing the tx hash is required");if(!o)throw new Error("An array specifying the inputs to be signed by the wallet is required");try{const s=(0,n5.createUnsecuredToken)(e.payload),a=await n.signTransaction(s);(t=e.onFinish)==null||t.call(e,a)}catch(s){console.error("[Connect] Error during sign transaction request",s),(r=e.onCancel)==null||r.call(e)}};Zc.signTransaction=s5;var Qc={};Object.defineProperty(Qc,"__esModule",{value:!0}),Qc.signMultipleTransactions=void 0;const o5=Dr,a5=pn,c5=async e=>{var t,r;const n=await(0,a5.getProviderOrThrow)(e.getProvider),{psbts:i}=e.payload;if(!i||!i.length)throw new Error("psbts array is required");if(i.length>100)throw new Error("psbts array must contain less than 100 psbts");try{const o=(0,o5.createUnsecuredToken)(e.payload),s=await n.signMultipleTransactions(o);(t=e.onFinish)==null||t.call(e,s)}catch(o){console.error("[Connect] Error during sign Multiple transactions request",o),(r=e.onCancel)==null||r.call(e)}};Qc.signMultipleTransactions=c5;var Cg={};Object.defineProperty(Cg,"__esModule",{value:!0}),function(e){var t=Se&&Se.__createBinding||(Object.create?function(n,i,o,s){s===void 0&&(s=o);var a=Object.getOwnPropertyDescriptor(i,o);(!a||("get"in a?!i.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return i[o]}}),Object.defineProperty(n,s,a)}:function(n,i,o,s){s===void 0&&(s=o),n[s]=i[o]}),r=Se&&Se.__exportStar||function(n,i){for(var o in n)o!=="default"&&!Object.prototype.hasOwnProperty.call(i,o)&&t(i,n,o)};Object.defineProperty(e,"__esModule",{value:!0}),r(Yc,e),r(Zc,e),r(Qc,e),r(Cg,e)}($g);var Ng={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.RpcErrorCode=e.BitcoinNetworkType=void 0,function(t){t.Mainnet="Mainnet",t.Testnet="Testnet"}(e.BitcoinNetworkType||(e.BitcoinNetworkType={})),function(t){t[t.PARSE_ERROR=-32700]="PARSE_ERROR",t[t.INVALID_REQUEST=-32600]="INVALID_REQUEST",t[t.METHOD_NOT_FOUND=-32601]="METHOD_NOT_FOUND",t[t.INVALID_PARAMS=-32602]="INVALID_PARAMS",t[t.INTERNAL_ERROR=-32603]="INTERNAL_ERROR",t[t.USER_REJECTION=-32e3]="USER_REJECTION",t[t.METHOD_NOT_SUPPORTED=-32001]="METHOD_NOT_SUPPORTED"}(e.RpcErrorCode||(e.RpcErrorCode={}))})(Ng),function(e){var t=Se&&Se.__createBinding||(Object.create?function(n,i,o,s){s===void 0&&(s=o);var a=Object.getOwnPropertyDescriptor(i,o);(!a||("get"in a?!i.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return i[o]}}),Object.defineProperty(n,s,a)}:function(n,i,o,s){s===void 0&&(s=o),n[s]=i[o]}),r=Se&&Se.__exportStar||function(n,i){for(var o in n)o!=="default"&&!Object.prototype.hasOwnProperty.call(i,o)&&t(i,n,o)};Object.defineProperty(e,"__esModule",{value:!0}),r(bg,e),r(Eg,e),r(_g,e),r(Pg,e),r(Ig,e),r(pn,e),r($g,e),r(Ng,e)}(Zh);const u5=uv(Zh),Bg=["address","paymentAddress","publicKey","paymentPublicKey","balance"],{signMessage:l5,sendBtcTransaction:h5,signTransaction:f5}=u5,d5="ORANGE_CONNECTED_WALLET_STATE";let p5=class extends ln{constructor(){super(...arguments),de(this,"observer"),de(this,"$valueStore",ro(d5,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),de(this,"removeSubscriber")}get library(){var t;return(t=window==null?void 0:window.OrangeWalletProviders)==null?void 0:t.OrangeBitcoinProvider}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Bg)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===Si&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Bg.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){var t;typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var r,n;(r=window==null?void 0:window.OrangeWalletProviders)!=null&&r.OrangeBitcoinProvider&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Si]:!0}),(n=this.observer)==null||n.disconnect())}),(t=this.observer)==null||t.observe(document,{childList:!0,subtree:!0})),nn(this.$store,["provider"],r=>{r.provider!==Si?this.removeSubscriber&&(this.$valueStore.set({address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){const{address:r,paymentAddress:n}=this.$valueStore.get();try{if(r){this.restorePersistedValues(),zt(n,this.network).then(s=>{this.$store.setKey("balance",s)});return}let i=Vo(this.network||tt);const o={payload:{purposes:["ordinals","payment"],message:"Address for receiving Ordinals and payments",network:{type:i}},onFinish:s=>{const a=jh(s.addresses),u=Dh(s.addresses);a&&u&&(this.$store.setKey("publicKey",String(s.addresses[0].publicKey)),this.$store.setKey("paymentPublicKey",String(s.addresses[1].publicKey)),this.$store.setKey("provider",Si),this.$store.setKey("address",a.address),this.$store.setKey("paymentAddress",u.address)),zt(u.address,this.network).then(f=>{this.$store.setKey("balance",f)})},onCancel:()=>{throw new Error(`User canceled lasereyes to ${Si} wallet`)}};await Zh.getAddress(o),this.$store.setKey("connected",!0)}catch(i){throw i}}async requestAccounts(){return[this.$store.get().address,this.$store.get().paymentAddress]}async getNetwork(){const{address:t}=this.$store.get();return t.slice(0,1)==="t"&&[it,Zt,Yt,Qt].includes(this.network)?this.network:tt}getPublicKey(){throw Hr}async getBalance(){const{paymentAddress:t}=this.$store.get();return await zt(t,this.network)}getInscriptions(){throw Hr}async sendBTC(t,r){let n="";const i={payload:{network:{type:Vo(this.network)},recipients:[{address:t,amountSats:BigInt(r)}],senderAddress:this.$store.get().paymentAddress},onFinish:o=>{console.log(o),n=o},onCancel:()=>{throw new Error("User canceled the request")}};return await h5(i),n}async signMessage(t,r){let n="";const i=r||this.$store.get().paymentAddress,o={payload:{network:{type:Vo(this.network)},address:i,message:t},onFinish:s=>{n=s},onCancel:()=>alert("Signature request canceled")};return await l5(o),n}async signPsbt(t,r,n,i,o){const s=ct.fromBase64(String(n),{network:er(this.network)}),a=this.$store.get().address,u=this.$store.get().paymentAddress,f=s.data.inputs,h=[],d={address:a,signingIndexes:[]},g={address:u,signingIndexes:[]};let v=0;for await(let I of f){if(I.witnessUtxo===void 0)g.signingIndexes.push(Number(v));else{const{script:k}=I.witnessUtxo,R=Ko(k,er(this.network));R===u?g.signingIndexes.push(Number(v)):R===a&&d.signingIndexes.push(Number(v))}v++}d.signingIndexes.length>0&&h.push(d),g.signingIndexes.length>0&&h.push(g);let E,T,x;const N={payload:{network:{type:Vo(this.network)},psbtBase64:s.toBase64(),broadcast:o,inputsToSign:h},onFinish:I=>{if(console.log(I),I.txId)E=I.txId;else if(I.psbtBase64){const k=ct.fromBase64(String(I.psbtBase64),{network:er(this.network)});T=k.toHex(),x=k.toBase64()}},onCancel:()=>console.log("Canceled")};return await f5(N),{signedPsbtHex:T,signedPsbtBase64:x,txId:E}}async pushPsbt(t){let r=t;if(!r.startsWith("02")){const n=ct.fromHex(r);n.finalizeAllInputs(),r=n.extractTransaction().toHex()}return await qe.post(`${ti(this.network)}/api/tx`,r).then(n=>n.data)}};const Ug=["address","paymentAddress","publicKey","paymentPublicKey","balance"],y5="OKX_CONNECTED_WALLET_STATE";class g5 extends ln{constructor(){super(...arguments),de(this,"observer"),de(this,"$valueStore",ro(y5,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),de(this,"removeSubscriber")}get library(){var t,r;let n;return this.network===it||this.network===Zt||this.network===Yt||this.network===Qt?n=(t=window==null?void 0:window.okxwallet)==null?void 0:t.bitcoinTestnet:(this.network===tt||this.network===ls)&&(n=(r=window==null?void 0:window.okxwallet)==null?void 0:r.bitcoin),n}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Ug)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===ss&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Ug.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){var t;typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var r;this.library&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[ss]:!0}),(r=this.observer)==null||r.disconnect())}),(t=this.observer)==null||t.observe(document,{childList:!0,subtree:!0})),nn(this.$store,["provider"],r=>{r.provider!==ss?this.removeSubscriber&&(this.$valueStore.set({address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){var r;try{const n=await this.library.connect();if(!n)throw new Error("No accounts found");this.$store.setKey("address",n.address),this.$store.setKey("paymentAddress",n.address),this.$store.setKey("publicKey",n.publicKey),this.$store.setKey("paymentPublicKey",n.publicKey),this.$store.setKey("accounts",[n]);const i=await((r=this.library)==null?void 0:r.getBalance());this.$store.setKey("balance",i.total),this.$store.setKey("provider",ss),this.$store.setKey("connected",!0)}catch(n){throw n}}async requestAccounts(){const t=this.library,r=this.network;return r===it||r===Zt||r===Qt?await t.connect():await t.requestAccounts()}async getNetwork(){const{address:t}=this.$store.get(),r=this.network;if(t.slice(0,1)==="t")return r===it?it:r===Zt?Zt:r===Yt?Yt:r===Qt?Qt:it;const n=await this.library.getNetwork();return B0(n)}async getPublicKey(){const t=this.library;return await(t==null?void 0:t.getPublicKey())}async getBalance(){const{paymentAddress:t}=this.$store.get();return await zt(t,this.network)}async getInscriptions(){return await this.library.getInscriptions(0,10)}async sendBTC(t,r){const n=await this.library.sendBitcoin(t,r);if(!n)throw new Error("Transaction failed");return n}async signMessage(t,r){const n=this.library;return await(n==null?void 0:n.signMessage(t))}async signPsbt(t,r,n,i,o){const s=await this.library.signPsbt(r,{autoFinalized:i}),a=ct.fromHex(s);if(i&&o){const u=await this.pushPsbt(s);return{signedPsbtHex:a.toHex(),signedPsbtBase64:a.toBase64(),txId:u}}return{signedPsbtHex:a.toHex(),signedPsbtBase64:a.toBase64(),txId:void 0}}async pushPsbt(t){return await qe.post(`${ti(this.network)}/api/tx`,t).then(r=>r.data)}}const Rg=["address","paymentAddress","publicKey","paymentPublicKey","balance"],w5="MAGIC_EDEN_CONNECTED_WALLET_STATE";class b5 extends ln{constructor(){super(...arguments),de(this,"observer"),de(this,"$valueStore",ro(w5,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),de(this,"removeSubscriber")}get library(){return window.magicEden.bitcoin}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Rg)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===Wn&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Rg.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;window!=null&&window.magicEden.bitcoin&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Wn]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),nn(this.$store,["provider"],t=>{t.provider!==Wn?this.removeSubscriber&&(this.$valueStore.set({address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){const{address:r,paymentAddress:n}=this.$valueStore.get();try{if(r){this.restorePersistedValues(),zt(n,this.network).then(o=>{this.$store.setKey("balance",o)});return}let i=Vs(this.network||tt);await fg({getProvider:async()=>this.library,payload:{purposes:["ordinals","payment"],message:"Address for receiving Ordinals and payments",network:{type:i}},onFinish:o=>{const s=jh(o.addresses),a=Dh(o.addresses);s&&a&&(this.$store.setKey("provider",Wn),this.$store.setKey("address",s.address),this.$store.setKey("paymentAddress",a.address)),this.$store.setKey("publicKey",String(o.addresses[0].publicKey)),this.$store.setKey("paymentPublicKey",String(o.addresses[1].publicKey)),zt(a.address,this.network).then(u=>{this.$store.setKey("balance",u)})},onCancel:()=>{throw new Error(`User canceled lasereyes to ${Wn} wallet`)},onError:o=>{throw new Error(`Can't lasereyes to ${Wn} wallet`)}}),this.$store.setKey("connected",!0)}catch(i){throw i}}async requestAccounts(){return[this.$store.get().address,this.$store.get().paymentAddress]}async getNetwork(){const{address:t}=this.$store.get();return t.slice(0,1)==="t"&&[it,Zt,Yt,Qt].includes(this.network)?this.network:tt}getPublicKey(){throw Hr}async getBalance(){const{paymentAddress:t}=this.$store.get();return await zt(t,this.network)}getInscriptions(){throw Hr}async sendBTC(t,r){let n;if(await N6({getProvider:async()=>this.library,payload:{network:{type:Vs(this.network)},recipients:[{address:t,amountSats:BigInt(r)}],senderAddress:this.$store.get().paymentAddress},onFinish:i=>{n=i},onCancel:()=>alert("Canceled")}),!n)throw new Error("Error sending BTC");return n.txid}async signMessage(t,r){try{const n=r||this.$store.get().paymentAddress;let i="";return await $6({getProvider:async()=>this.library,payload:{network:{type:cg.Mainnet},address:n,message:t,protocol:Gc.BIP322},onFinish:o=>{i=o},onCancel:()=>{alert("Request canceled")}}),i}catch(n){throw n}}async signPsbt(t,r,n,i,o){const{address:s,paymentAddress:a}=this.$store.get(),u=ct.fromBase64(String(n),{network:er(this.network)}),f=u.data.inputs,h=[],d={address:s,signingIndexes:[]},g={address:a,signingIndexes:[]};let v=0;for await(let k of f){const{script:R}=k.witnessUtxo,W=Ko(R,er(this.network));W===a?g.signingIndexes.push(Number(v)):W===s&&d.signingIndexes.push(Number(v)),v++}d.signingIndexes.length>0&&h.push(d),g.signingIndexes.length>0&&h.push(g);let E,T,x;const N=Vs(this.network),I={getProvider:async()=>this.library,payload:{network:{type:N},message:"Sign Transaction",psbtBase64:u.toBase64(),broadcast:o,inputsToSign:h},onFinish:k=>{if(k.psbtBase64){const R=ct.fromBase64(String(k.psbtBase64),{network:er(this.network)});T=R.toHex(),x=R.toBase64()}},onCancel:()=>{throw console.log("Canceled"),new Error("User canceled the request")},onError:k=>{throw console.log("error",k),k}};if(await signTransaction(I),o){const k=ct.fromBase64(String(x)).finalizeAllInputs().extractTransaction(),R=await this.pushPsbt(k.toHex());return{signedPsbtHex:k.toHex(),signedPsbtBase64:"test",txId:R}}else return{signedPsbtHex:T,signedPsbtBase64:x,txId:E}}async pushPsbt(t){return await qe.post(`${ti(this.network)}/api/tx`,t).then(r=>r.data)}}class m5 extends ln{constructor(){super(...arguments),de(this,"observer")}get library(){return window.phantom.bitcoin}get network(){return this.$network.get()}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;this.library&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Ei]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),nn(this.$store,["provider"],t=>{if(t.provider!==Ei){this.removeListeners();return}this.library.requestAccounts().then(r=>{this.handleAccountsChanged(r)}),this.addListeners()})}addListeners(){this.library.on("accountsChanged",this.handleAccountsChanged.bind(this)),this.library.on("networkChanged",this.handleNetworkChanged.bind(this))}removeListeners(){this.library.removeListener("accountsChanged",this.handleAccountsChanged.bind(this)),this.library.removeListener("networkChanged",this.handleNetworkChanged.bind(this))}dispose(){var t;(t=this.observer)==null||t.disconnect(),this.removeListeners()}handleAccountsChanged(t){if(!t.length){this.parent.disconnect();return}this.$store.get().accounts[0]!==t[0]&&(this.$store.setKey("accounts",t),t.length>0?this.parent.connect(Ei):this.parent.disconnect())}handleNetworkChanged(t){const r=zs(t);this.network!==r&&this.switchNetwork(r),this.parent.connect(Ei)}async connect(t){if(!this.library)throw new Error("Unisat isn't installed");const r=await this.library.requestAccounts();if(console.log("phantomAccounts",r),!r)throw new Error("No accounts found");this.$store.setKey("accounts",r);const n=r.find(o=>o.purpose==="ordinals"),i=r.find(o=>o.purpose==="payment");this.$store.setKey("address",n.address),this.$store.setKey("paymentAddress",i.address),this.$store.setKey("publicKey",n.publicKey),this.$store.setKey("paymentPublicKey",i.publicKey),this.$store.setKey("provider",Ei),zt(r[0],this.network).then(o=>{this.$store.setKey("balance",o)}),this.$store.setKey("connected",!0)}async getNetwork(){return this.$store.get().address.slice(0,1)==="t"?it:tt}async sendBTC(t,r){const{psbtHex:n}=await Uy(this.$store.get().address,this.$store.get().paymentAddress,t,r,this.$store.get().paymentPublicKey,this.network,7),i=await this.signPsbt("",n,"",!0,!0);if(!i)throw new Error("Error sending BTC");return i.txId}async signMessage(t,r){var n;const i=new TextEncoder().encode(t),o=new Uint8Array(i),s=r||this.$store.get().paymentAddress,a=await((n=this.library)==null?void 0:n.signMessage(s,o)),u=String.fromCharCode(...a.signature);return btoa(u)}async signPsbt(t,r,n,i,o){const{address:s,paymentAddress:a}=this.$store.get(),u=ct.fromHex(String(r),{network:er(this.network)}).data.inputs,f=[],h={address:s,signingIndexes:[]},d={address:a,signingIndexes:[]};let g=0;for await(let T of u){const{script:x}=T.witnessUtxo,N=Ko(x,er(this.network));N===a?d.signingIndexes.push(Number(g)):N===s&&h.signingIndexes.push(Number(g)),g++}h.signingIndexes.length>0&&f.push(h),d.signingIndexes.length>0&&f.push(d);const v=await this.library.signPsbt(r,{inputsToSign:f}),E=ct.fromHex(v);if(i&&o){const T=await this.pushPsbt(v);return{signedPsbtHex:E.toHex(),signedPsbtBase64:E.toBase64(),txId:T}}return{signedPsbtHex:E.toHex(),signedPsbtBase64:E.toBase64(),txId:void 0}}async pushPsbt(t){return await qe.post(`${ti(this.network)}/api/tx`,t).then(r=>r.data)}async getPublicKey(){return this.$store.get().publicKey}async getBalance(){return(await this.library.getBalance()).total}async getInscriptions(){return await this.library.getInscriptions(0,10)}async requestAccounts(){return await this.library.requestAccounts()}async switchNetwork(t){var r;const n=mc(t);await((r=this.library)==null?void 0:r.switchChain(n)),this.$network.set(t),await this.getBalance()}}class v5 extends ln{constructor(){super(...arguments),de(this,"observer")}get library(){return window.opnet}get network(){return this.$network.get()}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;this.library&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Ti]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),nn(this.$store,["provider"],t=>{if(t.provider!==Ti){this.removeListeners();return}this.library.getAccounts().then(r=>{this.handleAccountsChanged(r)}),this.addListeners()})}addListeners(){this.library.on("accountsChanged",this.handleAccountsChanged.bind(this)),this.library.on("networkChanged",this.handleNetworkChanged.bind(this))}removeListeners(){this.library.removeListener("accountsChanged",this.handleAccountsChanged.bind(this)),this.library.removeListener("networkChanged",this.handleNetworkChanged.bind(this))}dispose(){var t;(t=this.observer)==null||t.disconnect(),this.removeListeners()}handleAccountsChanged(t){if(!t.length){this.parent.disconnect();return}this.$store.get().accounts[0]!==t[0]&&(this.$store.setKey("accounts",t),t.length>0?this.parent.connect(Ti):this.parent.disconnect())}handleNetworkChanged(t){const r=zs(t);this.network!==r&&this.switchNetwork(r),this.parent.connect(Ti)}async connect(t){if(!this.library)throw new Error("OP_NET isn't installed");const r=await this.library.requestAccounts();if(!r)throw new Error("No accounts found");const n=await this.library.getPublicKey();if(!n)throw new Error("No public key found");this.$store.setKey("accounts",r),this.$store.setKey("address",r[0]),this.$store.setKey("paymentAddress",r[0]),this.$store.setKey("publicKey",n),this.$store.setKey("paymentPublicKey",n),this.$store.setKey("provider",Ti),await this.getNetwork().then(i=>{var o;((o=this.config)==null?void 0:o.network)!==i&&this.switchNetwork(i)}),zt(r[0],this.network).then(i=>{this.$store.setKey("balance",i)}),this.$store.setKey("connected",!0)}async getNetwork(){var t;const r=await((t=this.library)==null?void 0:t.getChain());return r?zs(r.enum):this.network}async sendBTC(t,r){var n;const i=await((n=this.library)==null?void 0:n.sendBitcoin(t,r));if(!i)throw new Error("Transaction failed");return i}async signMessage(t,r){var n;return await((n=this.library)==null?void 0:n.signMessage(t))}async signPsbt(t,r,n,i,o){var s;const a=await((s=this.library)==null?void 0:s.signPsbt(r,{autoFinalized:i})),u=ct.fromHex(a);if(i&&o){const f=await this.pushPsbt(a);return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:f}}return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:void 0}}async pushPsbt(t){return await qe.post(`${ti(this.network)}/api/tx`,t).then(r=>r.data)}async getPublicKey(){var t;return await((t=this.library)==null?void 0:t.getPublicKey())}async getBalance(){return(await this.library.getBalance()).total}async getInscriptions(){return await this.library.getInscriptions(0,10)}async requestAccounts(){return await this.library.requestAccounts()}async switchNetwork(t){var r;const n=mc(t);await((r=this.library)==null?void 0:r.switchChain(n)),this.$network.set(t),await this.getBalance()}}class E5{constructor(t,r){de(this,"$store"),de(this,"$network"),de(this,"$providerMap"),this.config=r,this.$store=t.$store,this.$network=t.$network,this.$providerMap={[Ai]:new D6(t,this,r),[Wn]:new b5(t,this,r),[ss]:new g5(t,this,r),[Ti]:new v5(t,this,r),[Si]:new p5(t,this,r),[vi]:new K6(t,this,r),[Ei]:new m5(t,this,r),[zn]:new T8(t,this,r),[In]:new R6(t,this,r),[os]:new H6(t,this,r)},this.$network.subscribe(this.watchNetworkChange.bind(this)),Bd(this.$store,["isInitializing"],n=>this.handleIsInitializingChanged(n.isInitializing)),r&&r.network&&(this.$network.set(r.network),this.getNetwork().then(n=>{try{r.network!==n&&this.switchNetwork(r.network)}catch{this.disconnect()}})),Bd(this.$store,["hasProvider"],this.checkInitializationComplete.bind(this)),_8()}dispose(){Object.values(this.$providerMap).forEach(t=>t==null?void 0:t.dispose())}handleIsInitializingChanged(t){if(typeof window<"u"&&typeof localStorage<"u"&&!t){const r=localStorage==null?void 0:localStorage.getItem(La);r&&(this.$store.setKey("provider",r),this.connect(r))}}async connect(t){this.$store.setKey("isConnecting",!0);try{if(localStorage==null||localStorage.setItem(La,t),!this.$providerMap[t])throw new Error("Unsupported wallet provider");const r=this.$providerMap[t];await(r==null?void 0:r.connect(t)),this.$store.setKey("connected",!0)}catch(r){throw console.error(r),this.$store.setKey("isConnecting",!1),this.disconnect(),r}finally{this.$store.setKey("isConnecting",!1)}}async requestAccounts(){var t;if(!this.$store.get().provider)throw new Error("No wallet provider connected");if(!this.$providerMap[this.$store.get().provider])throw new Error("The connected wallet doesn't support this method");try{return await((t=this.$providerMap[this.$store.get().provider])==null?void 0:t.requestAccounts())}catch(r){throw r instanceof Error&&r.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support this method"):r}}disconnect(){this.$store.setKey("connected",!1),this.$store.setKey("provider",void 0),this.$store.setKey("address",""),this.$store.setKey("paymentAddress",""),this.$store.setKey("publicKey",""),this.$store.setKey("paymentPublicKey",""),this.$store.setKey("balance",void 0),this.$store.setKey("accounts",[]),localStorage==null||localStorage.removeItem(La)}switchNetwork(t){var r;try{this.$store.get().provider&&((r=this.$providerMap[this.$store.get().provider])==null||r.switchNetwork(t))}catch(n){throw n instanceof Error&&n.message.toLowerCase().includes("not implemented")?(this.disconnect(),new Error("The connected wallet doesn't support programmatic network changes..")):n}}checkInitializationComplete(){Object.values(this.$store.get().hasProvider).every(t=>t!==void 0)&&this.$store.setKey("isInitializing",!1)}watchNetworkChange(){this.$store.setKey("balance",void 0)}async getNetwork(){var t;return this.$store.get().provider&&this.$providerMap[this.$store.get().provider]?await((t=this.$providerMap[this.$store.get().provider])==null?void 0:t.getNetwork()):this.$network.get()}async sendBTC(t,r){var n;if(r<=0)throw new Error("Amount must be greater than 0");if(!Number.isInteger(r))throw new Error("Amount must be an integer");if(!this.$store.get().provider)throw new Error("No wallet connected");if(this.$providerMap[this.$store.get().provider])try{return await((n=this.$providerMap[this.$store.get().provider])==null?void 0:n.sendBTC(t,r))}catch(i){throw i instanceof Error&&i.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support sending BTC..."):i}}async signMessage(t,r){var n;if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((n=this.$providerMap[this.$store.get().provider])==null?void 0:n.signMessage(t,r))}catch(i){throw i instanceof Error&&i.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support message signing..."):i}}async signPsbt(t,r=!1,n=!1){var i;let o,s;if(!t)throw new Error("No PSBT provided");if(E8(t))s=ct.fromHex(t).toBase64(),o=t;else if(v8(t))s=t,o=ct.fromBase64(t).toHex();else throw new Error("Invalid PSBT format");if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((i=this.$providerMap[this.$store.get().provider])==null?void 0:i.signPsbt(t,o,s,r,n))}catch(a){throw a instanceof Error&&a.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support PSBT signing..."):a}else throw new Error("No wallet provider connected")}async pushPsbt(t){var r;if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((r=this.$providerMap[this.$store.get().provider])==null?void 0:r.pushPsbt(t))}catch(n){throw n instanceof Error&&n.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support PSBT signing..."):n}}async getPublicKey(){var t;if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((t=this.$providerMap[this.$store.get().provider])==null?void 0:t.getPublicKey())}catch(r){throw r instanceof Error&&r.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support this method"):r}}async getBalance(){if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{const t=await this.$providerMap[this.$store.get().provider].getBalance();return this.$store.setKey("balance",BigInt(t)),t}catch(t){throw t instanceof Error&&t.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support this method"):t}}async getInscriptions(){var t;if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((t=this.$providerMap[this.$store.get().provider])==null?void 0:t.getInscriptions())}catch(r){throw r instanceof Error&&r.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support this method"):r}}}var A5=Object.defineProperty,S5=(e,t,r)=>t in e?A5(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ge=(e,t,r)=>S5(e,typeof t!="symbol"?t+"":t,r);function T5(e,t){for(var r=0;r<t.length;r++){const n=t[r];if(typeof n!="string"&&!Array.isArray(n)){for(const i in n)if(i!=="default"&&!(i in e)){const o=Object.getOwnPropertyDescriptor(n,i);o&&Object.defineProperty(e,i,o.get?o:{enumerable:!0,get:()=>n[i]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}let Qh=Symbol("clean"),yn=[],Ki=0;const eu=4;let ef=e=>{let t=[],r={get(){return r.lc||r.listen(()=>{})(),r.value},lc:0,listen(n){return r.lc=t.push(n),()=>{for(let o=Ki+eu;o<yn.length;)yn[o]===n?yn.splice(o,eu):o+=eu;let i=t.indexOf(n);~i&&(t.splice(i,1),--r.lc||r.off())}},notify(n,i){let o=!yn.length;for(let s of t)yn.push(s,r.value,n,i);if(o){for(Ki=0;Ki<yn.length;Ki+=eu)yn[Ki](yn[Ki+1],yn[Ki+2],yn[Ki+3]);yn.length=0}},off(){},set(n){let i=r.value;i!==n&&(r.value=n,r.notify(i))},subscribe(n){let i=r.listen(n);return n(r.value),i},value:e};return process.env.NODE_ENV!=="production"&&(r[Qh]=()=>{t=[],r.lc=0,r.off()}),r};const _5=5,no=6,tu=10;let k5=(e,t,r,n)=>(e.events=e.events||{},e.events[r+tu]||(e.events[r+tu]=n(i=>{e.events[r].reduceRight((o,s)=>(s(o),o),{shared:{},...i})})),e.events[r]=e.events[r]||[],e.events[r].push(t),()=>{let i=e.events[r],o=i.indexOf(t);i.splice(o,1),i.length||(delete e.events[r],e.events[r+tu](),delete e.events[r+tu])}),P5=1e3,O5=(e,t)=>k5(e,r=>{let n=t(r);n&&e.events[no].push(n)},_5,r=>{let n=e.listen;e.listen=(...o)=>(!e.lc&&!e.active&&(e.active=!0,r()),n(...o));let i=e.off;if(e.events[no]=[],e.off=()=>{i(),setTimeout(()=>{if(e.active&&!e.lc){e.active=!1;for(let o of e.events[no])o();e.events[no]=[]}},P5)},process.env.NODE_ENV!=="production"){let o=e[Qh];e[Qh]=()=>{for(let s of e.events[no])s();e.events[no]=[],e.active=!1,o()}}return()=>{e.listen=n,e.off=i}});function gn(e,t,r){let n=new Set([...t,void 0]);return e.listen((i,o,s)=>{n.has(s)&&r(i,o,s)})}function Hg(e,t,r){let n=gn(e,t,r);return r(e.value),n}let Lg=(e={})=>{let t=ef(e);return t.setKey=function(r,n){let i=t.value;typeof n>"u"&&r in t.value?(t.value={...t.value},delete t.value[r],t.notify(i,r)):t.value[r]!==n&&(t.value={...t.value,[r]:n},t.notify(i,r))},t};const ms="oyl",ji="unisat",ii="xverse",Di="phantom",vs="leather",si="magic-eden",Es="okx",As="wizz",Mi="orange",Fi="op_net",tf="p2tr",Kg="p2wpkh",rf="defaultWallet",wn={messagePrefix:`Bitcoin Signed Message:
|
|
29
|
+
***************************************************************************** */var og="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";(()=>{const e=Array(256).fill(-1);for(let t=0;t<og.length;++t)e[og.charCodeAt(t)]=t})();var ag,Gh,zc,Xh=(ag=function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.bech32m=t.bech32=void 0;const r="qpzry9x8gf2tvdw0s3jn54khce6mua7l",n={};for(let d=0;d<32;d++){const g=r.charAt(d);n[g]=d}function i(d){const g=d>>25;return(33554431&d)<<5^996825010&-(g>>0&1)^642813549&-(g>>1&1)^513874426&-(g>>2&1)^1027748829&-(g>>3&1)^705979059&-(g>>4&1)}function o(d){let g=1;for(let v=0;v<d.length;++v){const E=d.charCodeAt(v);if(E<33||E>126)return"Invalid prefix ("+d+")";g=i(g)^E>>5}g=i(g);for(let v=0;v<d.length;++v){const E=d.charCodeAt(v);g=i(g)^31&E}return g}function s(d,g,v,E){let T=0,x=0;const N=(1<<v)-1,I=[];for(let k=0;k<d.length;++k)for(T=T<<g|d[k],x+=g;x>=v;)x-=v,I.push(T>>x&N);if(E)x>0&&I.push(T<<v-x&N);else{if(x>=g)return"Excess padding";if(T<<v-x&N)return"Non-zero padding"}return I}function a(d){return s(d,8,5,!0)}function u(d){const g=s(d,5,8,!1);if(Array.isArray(g))return g}function f(d){const g=s(d,5,8,!1);if(Array.isArray(g))return g;throw new Error(g)}function h(d){let g;function v(E,T){if(T=T||90,E.length<8)return E+" too short";if(E.length>T)return"Exceeds length limit";const x=E.toLowerCase(),N=E.toUpperCase();if(E!==x&&E!==N)return"Mixed-case string "+E;const I=(E=x).lastIndexOf("1");if(I===-1)return"No separator character for "+E;if(I===0)return"Missing prefix for "+E;const k=E.slice(0,I),R=E.slice(I+1);if(R.length<6)return"Data too short";let W=o(k);if(typeof W=="string")return W;const V=[];for(let Be=0;Be<R.length;++Be){const Le=R.charAt(Be),Je=n[Le];if(Je===void 0)return"Unknown character "+Le;W=i(W)^Je,Be+6>=R.length||V.push(Je)}return W!==g?"Invalid checksum for "+E:{prefix:k,words:V}}return g=d==="bech32"?1:734539939,{decodeUnsafe:function(E,T){const x=v(E,T);if(typeof x=="object")return x},decode:function(E,T){const x=v(E,T);if(typeof x=="object")return x;throw new Error(x)},encode:function(E,T,x){if(x=x||90,E.length+7+T.length>x)throw new TypeError("Exceeds length limit");let N=o(E=E.toLowerCase());if(typeof N=="string")throw new Error(N);let I=E+"1";for(let k=0;k<T.length;++k){const R=T[k];if(R>>5)throw new Error("Non 5-bit word");N=i(N)^R,I+=r.charAt(R)}for(let k=0;k<6;++k)N=i(N);N^=g;for(let k=0;k<6;++k)I+=r.charAt(N>>5*(5-k)&31);return I},toWords:a,fromWordsUnsafe:u,fromWords:f}}t.bech32=h("bech32"),t.bech32m=h("bech32m")},ag(Gh={exports:{}},Gh.exports),Gh.exports);(zc=Xh)&&zc.__esModule&&Object.prototype.hasOwnProperty.call(zc,"default")&&zc.default,Xh.bech32m,Xh.bech32,new Uint8Array(new Uint16Array([65279]).buffer)[0];var eo,to;(function(e){e.mainnet="mainnet",e.testnet="testnet",e.regtest="regtest"})(eo||(eo={})),function(e){e.p2pkh="p2pkh",e.p2sh="p2sh",e.p2wpkh="p2wpkh",e.p2wsh="p2wsh",e.p2tr="p2tr"}(to||(to={})),to.p2pkh,eo.mainnet,to.p2pkh,eo.testnet,to.p2sh,eo.mainnet,to.p2sh,eo.testnet;var Q8="accountChange";he({type:lt(Q8)});var e6="networkChange";he({type:lt(e6)});var t6="disconnect";he({type:lt(t6)});async function Jh(e){var t;const r=await(e==null?void 0:e())||((t=window.XverseProviders)==null?void 0:t.BitcoinProvider)||window.BitcoinProvider;if(!r)throw new Error("No Bitcoin wallet installed");return r}var cg=(e=>(e.Mainnet="Mainnet",e.Testnet="Testnet",e.Signet="Signet",e))(cg||{}),Yh=dn(Bc([ye(),Rn(),gs()])),dr=he({jsonrpc:lt("2.0"),method:ye(),params:dn(Bc([fn(Uc()),Ky({}),gs()])),id:Yh}),Wc=(e=>(e[e.PARSE_ERROR=-32700]="PARSE_ERROR",e[e.INVALID_REQUEST=-32600]="INVALID_REQUEST",e[e.METHOD_NOT_FOUND=-32601]="METHOD_NOT_FOUND",e[e.INVALID_PARAMS=-32602]="INVALID_PARAMS",e[e.INTERNAL_ERROR=-32603]="INTERNAL_ERROR",e[e.USER_REJECTION=-32e3]="USER_REJECTION",e[e.METHOD_NOT_SUPPORTED=-32001]="METHOD_NOT_SUPPORTED",e[e.ACCESS_DENIED=-32002]="ACCESS_DENIED",e))(Wc||{}),ug=he({jsonrpc:lt("2.0"),result:Mh(Uc()),id:Yh}),lg=he({jsonrpc:lt("2.0"),error:Mh(Uc()),id:Yh});Bc([ug,lg]);var qc=(e=>(e.Ordinals="ordinals",e.Payment="payment",e.Stacks="stacks",e))(qc||{}),hg=(e=>(e.p2pkh="p2pkh",e.p2sh="p2sh",e.p2wpkh="p2wpkh",e.p2wsh="p2wsh",e.p2tr="p2tr",e.stacks="stacks",e))(hg||{}),r6=he({address:ye(),publicKey:ye(),purpose:ys(qc),addressType:ys(hg)}),fg=async e=>{var t,r;const n=await Jh(e.getProvider),{purposes:i}=e.payload;if(!i)throw new Error("Address purposes are required");try{const o=Dr.createUnsecuredToken(e.payload),s=await n.connect(o);(t=e.onFinish)==null||t.call(e,s)}catch(o){console.error("[Connect] Error during address request",o),(r=e.onCancel)==null||r.call(e)}},n6="stx_getAddresses",i6=ws(he({message:dn(ye())}));he({...dr.entries,...he({method:lt(n6),params:i6,id:ye()}).entries});var s6="stx_signTransaction",o6=he({transaction:ye(),pubkey:dn(ye()),broadcast:dn(Ly())});he({...dr.entries,...he({method:lt(s6),params:o6,id:ye()}).entries});var a6=["software","ledger"],c6=jy(a6),u6="getInfo",l6=ws(gs());he({version:ye(),methods:dn(fn(ye())),supports:fn(ye())}),he({...dr.entries,...he({method:lt(u6),params:l6,id:ye()}).entries});var h6="getAddresses",f6=he({purposes:fn(ys(qc)),message:dn(ye())});he({...dr.entries,...he({method:lt(h6),params:f6,id:ye()}).entries});var d6="signMessage",Gc=(e=>(e.ECDSA="ECDSA",e.BIP322="BIP322",e))(Gc||{}),p6=he({address:ye(),message:ye(),protocol:dn(ys(Gc))});he({signature:ye(),messageHash:ye(),address:ye(),protocol:ys(Gc)}),he({...dr.entries,...he({method:lt(d6),params:p6,id:ye()}).entries});var y6="getAccounts",g6=he({purposes:fn(ys(qc)),message:dn(ye())});fn(he({...r6.entries,...he({walletType:c6}).entries})),he({...dr.entries,...he({method:lt(y6),params:g6,id:ye()}).entries});var w6="getBalance";ws(gs()),he({...dr.entries,...he({method:lt(w6),id:ye()}).entries});var b6="wallet_requestPermissions",m6=Fh();lt(!0),he({...dr.entries,...he({method:lt(b6),params:m6,id:ye()}).entries});var v6="wallet_renouncePermissions",E6=Fh();lt(!0),he({...dr.entries,...he({method:lt(v6),params:E6,id:ye()}).entries});var A6="wallet_getWalletType";ws(gs()),he({...dr.entries,...he({method:lt(A6),id:ye()}).entries});var S6="runes_getBalance",T6=ws(gs());he({balances:fn(he({runeName:ye(),amount:ye(),divisibility:Rn(),symbol:ye(),inscriptionId:ws(ye())}))}),he({...dr.entries,...he({method:lt(S6),params:T6,id:ye()}).entries});var _6="runes_transfer",k6=he({recipients:fn(he({runeName:ye(),amount:ye(),address:ye()}))});he({...dr.entries,...he({method:lt(_6),params:k6,id:ye()}).entries});var P6="ord_getInscriptions",O6=he({offset:Rn(),limit:Rn()});he({total:Rn(),limit:Rn(),offset:Rn(),inscriptions:fn(he({inscriptionId:ye(),inscriptionNumber:ye(),address:ye(),collectionName:dn(ye()),postage:ye(),contentLength:ye(),contentType:ye(),timestamp:Rn(),offset:Rn(),genesisTransaction:ye(),output:ye()}))}),he({...dr.entries,...he({method:lt(P6),params:O6,id:ye()}).entries});var I6="ord_sendInscriptions",x6=he({transfers:fn(he({address:ye(),inscriptionId:ye()}))});he({...dr.entries,...he({method:lt(I6),params:x6,id:ye()}).entries});var dg=async(e,t,r)=>{var n;let i=((n=window.XverseProviders)==null?void 0:n.BitcoinProvider)||window.BitcoinProvider;if(!i)throw new Error("no wallet provider was found");if(!e)throw new Error("A wallet method is required");const o=await i.request(e,t);return Hy(lg,o)?{status:"error",error:o.error}:Hy(ug,o)?{status:"success",result:o.result}:{status:"error",error:{code:-32603,message:"Received unknown response from provider.",data:o}}},$6=async e=>{var t,r;const n=await Jh(e.getProvider),{address:i,message:o}=e.payload;if(!i)throw new Error("An address is required to sign a message");if(!o)throw new Error("A message to be signed is required");try{const s=Dr.createUnsecuredToken(e.payload),a=await n.signMessage(s);(t=e.onFinish)==null||t.call(e,a)}catch(s){console.error("[Connect] Error during sign message request",s),(r=e.onCancel)==null||r.call(e)}},C6=e=>e.map(t=>{const{address:r,amountSats:n}=t;return{address:r,amountSats:n.toString()}}),N6=async e=>{var t,r;const n=await Jh(e.getProvider),{recipients:i,senderAddress:o,network:s,message:a}=e.payload;if(!i||i.length===0)throw new Error("At least one recipient is required");if(i.some(u=>typeof u.address!="string"||typeof u.amountSats!="bigint"))throw new Error("Incorrect recipient format");if(!o)throw new Error("The sender address is required");try{const u=C6(i),f={network:s,senderAddress:o,message:a,recipients:u},h=Dr.createUnsecuredToken(f),d=await n.sendBtcTransaction(h);(t=e.onFinish)==null||t.call(e,d)}catch(u){console.error("[Connect] Error during send BTC transaction request",u),(r=e.onCancel)==null||r.call(e)}};let pg=e=>e,ta={},Li={addEventListener(){},removeEventListener(){}};function B6(){try{return typeof localStorage<"u"}catch{return!1}}B6()&&(ta=localStorage),typeof window<"u"&&(Li={addEventListener(e,t,r){window.addEventListener("storage",t),window.addEventListener("pageshow",r)},removeEventListener(e,t,r){window.removeEventListener("storage",t),window.removeEventListener("pageshow",r)}});function ro(e,t={},r={}){let n=r.encode||pg,i=r.decode||pg,o=Ud(),s=o.setKey,a=(d,g)=>{typeof g>"u"?(r.listen!==!1&&Li.perKey&&Li.removeEventListener(e+d,f,h),delete ta[e+d]):(r.listen!==!1&&Li.perKey&&!(d in o.value)&&Li.addEventListener(e+d,f,h),ta[e+d]=n(g))};o.setKey=(d,g)=>{a(d,g),s(d,g)};let u=o.set;o.set=function(d){for(let g in d)a(g,d[g]);for(let g in o.value)g in d||a(g,void 0);u(d)};function f(d){d.key?d.key.startsWith(e)&&(d.newValue===null?s(d.key.slice(e.length),void 0):s(d.key.slice(e.length),i(d.newValue))):u({})}function h(){let d={...t};for(let g in ta)g.startsWith(e)&&(d[g.slice(e.length)]=i(ta[g]));for(let g in d)o.setKey(g,d[g])}return nm(o,()=>{if(h(),r.listen!==!1)return Li.addEventListener(e,f,h),()=>{Li.removeEventListener(e,f,h);for(let d in o.value)Li.removeEventListener(e+d,f,h)}}),o}const yg=["address","paymentAddress","publicKey","paymentPublicKey","balance"],U6="XVERSE_CONNECTED_WALLET_STATE";let R6=class extends ln{constructor(){super(...arguments),de(this,"observer"),de(this,"$valueStore",ro(U6,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),de(this,"removeSubscriber")}get library(){return window==null?void 0:window.BitcoinProvider}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of yg)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===In&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):yg.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){nn(this.$store,["provider"],t=>{t.provider!==In?this.removeSubscriber&&(this.$valueStore.set({address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))}),typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t,r;(t=window==null?void 0:window.XverseProviders)!=null&&t.BitcoinProvider&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[In]:!0}),(r=this.observer)==null||r.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0}))}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){const{address:r,paymentAddress:n}=this.$valueStore.get();try{if(r){this.restorePersistedValues(),zt(n,this.network).then(o=>{this.$store.setKey("balance",o)});return}let i=Vs(this.network||tt);await fg({payload:{purposes:["ordinals","payment"],message:"Address for receiving Ordinals and payments",network:{type:i}},onFinish:o=>{const s=jh(o.addresses),a=Dh(o.addresses);s&&a&&(this.$store.setKey("provider",In),this.$store.setKey("address",s.address),this.$store.setKey("paymentAddress",a.address)),this.$store.setKey("publicKey",String(o.addresses[0].publicKey)),this.$store.setKey("paymentPublicKey",String(o.addresses[1].publicKey)),zt(a.address,this.network).then(u=>{this.$store.setKey("balance",u)})},onCancel:()=>{throw new Error(`User canceled lasereyes to ${In} wallet`)},onError:o=>{throw new Error(`Can't lasereyes to ${In} wallet`)}}),this.$store.setKey("connected",!0)}catch(i){throw i}}async requestAccounts(){return[this.$store.get().address,this.$store.get().paymentAddress]}async getNetwork(){const{address:t}=this.$store.get();return t.slice(0,1)==="t"&&[it,Zt,Yt,Qt].includes(this.network)?this.network:tt}getPublicKey(){throw Hr}async getBalance(){const{paymentAddress:t}=this.$store.get();return await zt(t,this.network)}getInscriptions(){throw Hr}async sendBTC(t,r){const n=await dg("sendTransfer",{recipients:[{address:t,amount:r}]});if(n.status==="success")return n.result.txid;throw n.error.code===Wc.USER_REJECTION?new Error("User rejected the request"):new Error("Error sending BTC: "+n.error.message)}async signMessage(t,r){const n=r||this.$store.get().paymentAddress,i=await dg("signMessage",{address:n,message:t});if(i.status==="success")return i.result.signature;throw i.error.code===Wc.USER_REJECTION?new Error("User rejected the request"):new Error("Error signing message: "+i.error.message)}async signPsbt(t,r,n,i,o){const{address:s,paymentAddress:a}=this.$store.get(),u=ct.fromBase64(String(n),{network:er(this.network)}),f=u.data.inputs,h=[],d={address:s,signingIndexes:[]},g={address:a,signingIndexes:[]};let v=0;for await(let I of f){if(I.witnessUtxo===void 0)g.signingIndexes.push(Number(v));else{const{script:k}=I.witnessUtxo,R=Ko(k,er(this.network));R===a?g.signingIndexes.push(Number(v)):R===s&&d.signingIndexes.push(Number(v))}v++}d.signingIndexes.length>0&&h.push(d),g.signingIndexes.length>0&&h.push(g);let E,T,x;const N={payload:{network:{type:Vs(this.network)},message:"Sign Transaction",psbtBase64:u.toBase64(),broadcast:o,inputsToSign:h},onFinish:I=>{if(I.txId)E=I.txId;else if(I.psbtBase64){const k=ct.fromBase64(String(I.psbtBase64),{network:er(this.network)});T=k.toHex(),x=k.toBase64()}},onCancel:()=>console.log("Canceled")};return await signTransaction(N),{signedPsbtHex:T,signedPsbtBase64:x,txId:E}}pushPsbt(t){throw Hr}},H6=class extends ln{constructor(){super(...arguments),de(this,"observer")}get library(){return window.wizz}get network(){return this.$network.get()}handleNetworkChanged(t){this.parent.connect(os)}handleAccountsChanged(t){if(!t.length){this.parent.disconnect();return}this.$store.get().accounts[0]!==t[0]&&this.$store.setKey("accounts",t)}initialize(){nn(this.$store,["provider"],t=>{t.provider===os?this.addLibraryListeners():this.removeLibraryListeners()}),typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;this.library&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[os]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0}))}removeLibraryListeners(){var t,r;(t=this.library)==null||t.removeListener("networkChanged",this.handleNetworkChanged.bind(this)),(r=this.library)==null||r.removeListener("accountsChanged",this.handleAccountsChanged.bind(this))}addLibraryListeners(){var t,r;(t=this.library)==null||t.on("networkChanged",this.handleNetworkChanged.bind(this)),(r=this.library)==null||r.on("accountsChanged",this.handleAccountsChanged.bind(this))}dispose(){var t;(t=this.observer)==null||t.disconnect(),this.removeLibraryListeners()}async connect(){if(!this.library)throw I0;const t=await this.library.requestAccounts();if(!t)throw new Error("No accounts found");const r=await this.library.getPublicKey();if(!r)throw new Error("No public key found");this.$store.setKey("accounts",t),this.$store.setKey("address",t[0]),this.$store.setKey("paymentAddress",t[0]),this.$store.setKey("publicKey",r),this.$store.setKey("paymentPublicKey",r),this.$store.setKey("provider",os),await this.getNetwork().then(n=>{var i;n&&((i=this.config)==null?void 0:i.network)!==n&&this.parent.switchNetwork(n)}),await this.parent.getBalance(),this.$store.setKey("connected",!0)}async requestAccounts(){return await this.library.requestAccounts()}async getNetwork(){var t;const r=await((t=this.library)==null?void 0:t.getNetwork());return r?uh(r):void 0}async switchNetwork(t){var r;if(t===Qt||t===ls)return await this.library.switchNetwork(Fo);const n=uh(t);await((r=this.library)==null?void 0:r.switchNetwork(n)),this.$network.set(t),await this.parent.getBalance()}async getPublicKey(){var t;return await((t=this.library)==null?void 0:t.getPublicKey())}async getBalance(){return(await this.library.getBalance()).total}async getInscriptions(){return await this.library.getInscriptions(0,10)}async sendBTC(t,r){var n;const i=await((n=this.library)==null?void 0:n.sendBitcoin(t,r));if(i)return i;throw new Error("Error sending BTC")}async signMessage(t){var r;return await((r=this.library)==null?void 0:r.signMessage(t))}async signPsbt(t,r,n,i,o){var s;const a=await((s=this.library)==null?void 0:s.signPsbt(r,{autoFinalized:i,broadcast:!1})),u=ct.fromHex(a);let f;return i&&o&&(f=await this.pushPsbt(a)),{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:f}}async pushPsbt(t){return await qe.post(`${ti(this.$network.get())}/api/tx`,t).then(r=>r.data)}};const gg=["address","paymentAddress","publicKey","paymentPublicKey","balance"],L6="OYL_CONNECTED_WALLET_STATE";let K6=class extends ln{constructor(){super(...arguments),de(this,"observer"),de(this,"$valueStore",ro(L6,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),de(this,"removeSubscriber")}get library(){return window.oyl}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of gg)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===vi&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):gg.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;window!=null&&window.oyl&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[vi]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),nn(this.$store,["provider"],t=>{t.provider!==vi?this.removeSubscriber&&(this.$valueStore.set({address:"",publicKey:"",paymentAddress:"",paymentPublicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){if(!this.library)throw new Error("Oyl isn't installed");const{nativeSegwit:r,taproot:n}=await this.library.getAddresses();if(!r||!n)throw new Error("No accounts found");this.$store.setKey("address",n.address),this.$store.setKey("paymentAddress",r.address),this.$store.setKey("publicKey",n.publicKey),this.$store.setKey("paymentPublicKey",r.publicKey),this.$store.setKey("provider",vi),zt(r.address,this.network).then(o=>{this.$store.setKey("balance",o)}),this.$store.setKey("connected",!0);const i=await this.getBalance();i&&this.$store.setKey("balance",i)}async getNetwork(){return this.network}async sendBTC(t,r){const{psbtHex:n}=await Uy(this.$store.get().address,this.$store.get().paymentAddress,t,r,this.$store.get().paymentPublicKey,this.network,7),i=await this.signPsbt("",n,"",!0,!0);if(!i)throw new Error("Error sending BTC");return i.txId}async signMessage(t,r){const n=r||this.$store.get().paymentAddress;return(await this.library.signMessage({address:n,message:t})).signature}async signPsbt(t,r,n,i,o){const{psbt:s,txid:a}=await this.library.signPsbt({psbt:r,finalize:i,broadcast:o}),u=ct.fromHex(s);return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:a}}async pushPsbt(t){return(await this.library.pushPsbt({psbt:t})).txid}async getPublicKey(){var t;return await((t=this.library)==null?void 0:t.getPublicKey())}async getBalance(){const{total:t}=await this.library.getBalance();return this.$store.setKey("balance",t),t}async getInscriptions(){return await this.library.getInscriptions(0,10)}async requestAccounts(){return await this.library.requestAccounts()}async switchNetwork(){throw Hr}};const wg=["address","paymentAddress","publicKey","paymentPublicKey","balance"],j6="LEATHER_CONNECTED_WALLET_STATE";let D6=class extends ln{constructor(){super(...arguments),de(this,"observer"),de(this,"$valueStore",ro(j6,{address:"",publicKey:"",paymentAddress:"",paymentPublicKey:"",balance:""})),de(this,"removeSubscriber")}get library(){return window.LeatherProvider}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of wg)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===Ai&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):wg.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;window!=null&&window.LeatherProvider&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Ai]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),nn(this.$store,["provider"],t=>{t.provider!==Ai?this.removeSubscriber&&(this.$valueStore.set({address:"",publicKey:"",paymentAddress:"",paymentPublicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){var r;if(!this.library)throw new Error("Leather isn't installed");const n=await this.library.request("getAddresses");if(!n)throw new Error("No accounts found");const i=n.result.addresses,o=i.map(u=>u.address),s=i.find(u=>u.type===Ha),a=i.find(u=>u.type===gl);if(!(s!=null&&s.publicKey)||!(a!=null&&a.publicKey))throw new Error("No accounts found");if((r=String(s==null?void 0:s.address))!=null&&r.startsWith("tb")&&this.network!==it&&this.network!==Zt&&this.network!==Yt)throw new Error(`Please switch networks to ${this.network} in the wallet settings.`);this.$store.setKey("accounts",o),this.$store.setKey("address",s.address),this.$store.setKey("paymentAddress",a.address),this.$store.setKey("publicKey",s.publicKey),this.$store.setKey("paymentPublicKey",a.publicKey),this.$store.setKey("provider",Ai),zt(a.address,this.network).then(u=>{this.$store.setKey("balance",u)}),this.$store.setKey("connected",!0)}async getNetwork(){return this.network}async sendBTC(t,r){var n,i;const o=await((n=this.library)==null?void 0:n.request("sendTransfer",{recipients:[{address:t,amount:r}]}));if((i=o==null?void 0:o.result)!=null&&i.txid)return o.result.txid;throw o.error.code===Wc.USER_REJECTION?new Error("User rejected the request"):new Error("Error sending BTC: "+o.error.message)}async signMessage(t,r){var n;const i=r===this.$store.get().address?Ha:gl;if(r!==this.$store.get().address&&r!==this.$store.get().paymentAddress)throw new Error("Invalid address to sign message");const o=await this.library.request("signMessage",{message:t,paymentType:i});return(n=o==null?void 0:o.result)==null?void 0:n.signature}async signPsbt(t,r,n,i,o){const s={hex:r,broadcast:!1,network:this.network},a=(await this.library.request("signPsbt",s)).result.hex,u=ct.fromHex(String(a));if(i&&o){const f=u.finalizeAllInputs(),h=await this.pushPsbt(f.toHex());return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:h}}else if(i){const f=u.finalizeAllInputs();return{signedPsbtHex:f.toHex(),signedPsbtBase64:f.toBase64(),txId:void 0}}else return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:void 0}}async pushPsbt(t){const r=ct.fromHex(t).extractTransaction();return await qe.post(`${ti(this.network)}/api/tx`,r.toHex()).then(n=>n.data)}async getPublicKey(){const{result:t}=await this.library.request("getAddresses"),r=t.addresses.find(n=>n.type===Ha);if(!(r!=null&&r.publicKey))throw new Error("No accounts found");return r.publicKey}async getBalance(){const t=await zt(this.$store.get().paymentAddress,this.network);return this.$store.setKey("balance",t),t.toString()}async getInscriptions(){throw Hr}async requestAccounts(){const{result:t}=await this.library.request("getAddresses"),r=t.addresses.map(n=>n.address);return this.$store.setKey("accounts",r),r}async switchNetwork(){throw Hr}};var Zh={},bg={},pn={},mg={};Object.defineProperty(mg,"__esModule",{value:!0}),function(e){var t=Se&&Se.__createBinding||(Object.create?function(s,a,u,f){f===void 0&&(f=u);var h=Object.getOwnPropertyDescriptor(a,u);(!h||("get"in h?!a.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(s,f,h)}:function(s,a,u,f){f===void 0&&(f=u),s[f]=a[u]}),r=Se&&Se.__exportStar||function(s,a){for(var u in s)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,s,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.getProviderById=e.getProviders=e.getProviderOrThrow=void 0;async function n(s){var a,u;if(s){const h=await s();if(h)return h}const f=window.OrangeBitcoinProvider||((a=window.OrangecryptoProviders)==null?void 0:a.BitcoinProvider)||((u=window.OrangeWalletProviders)==null?void 0:u.OrangeBitcoinProvider);if(!f)throw new Error("No Orange Bitcoin wallet installed");return f}e.getProviderOrThrow=n;function i(){return window.btc_providers||(window.btc_providers=[]),window.btc_providers}e.getProviders=i;function o(s){var a;if(Array.isArray(window.btc_providers)){const u=window.btc_providers.find(f=>f.id===s);return(a=u==null?void 0:u.id)==null?void 0:a.split(".").reduce((f,h)=>f==null?void 0:f[h],window)}else{console.log("window.btc_providers is not defined or not an array");return}}e.getProviderById=o,r(mg,e)}(pn);var vg={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.AddressType=e.AddressPurpose=void 0,function(t){t.Ordinals="ordinals",t.Payment="payment",t.Stacks="stacks"}(e.AddressPurpose||(e.AddressPurpose={})),function(t){t.p2pkh="p2pkh",t.p2sh="p2sh",t.p2wpkh="p2wpkh",t.p2wsh="p2wsh",t.p2tr="p2tr",t.stacks="stacks"}(e.AddressType||(e.AddressType={}))})(vg),function(e){var t=Se&&Se.__createBinding||(Object.create?function(s,a,u,f){f===void 0&&(f=u);var h=Object.getOwnPropertyDescriptor(a,u);(!h||("get"in h?!a.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(s,f,h)}:function(s,a,u,f){f===void 0&&(f=u),s[f]=a[u]}),r=Se&&Se.__exportStar||function(s,a){for(var u in s)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,s,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.getAddress=void 0;const n=Dr,i=pn,o=async s=>{var a,u;const f=await(0,i.getProviderOrThrow)(s.getProvider),{purposes:h}=s.payload;if(!h)throw new Error("Address purposes are required");try{const d=(0,n.createUnsecuredToken)(s.payload),g=await f.connect(d);(a=s.onFinish)==null||a.call(s,g)}catch(d){console.error("[Connect] Error during address request",d),(u=s.onCancel)==null||u.call(s)}};e.getAddress=o,r(vg,e)}(bg);var Eg={},Ag={},Sg={};Object.defineProperty(Sg,"__esModule",{value:!0});var Tg={};Object.defineProperty(Tg,"__esModule",{value:!0}),function(e){var t=Se&&Se.__createBinding||(Object.create?function(n,i,o,s){s===void 0&&(s=o);var a=Object.getOwnPropertyDescriptor(i,o);(!a||("get"in a?!i.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return i[o]}}),Object.defineProperty(n,s,a)}:function(n,i,o,s){s===void 0&&(s=o),n[s]=i[o]}),r=Se&&Se.__exportStar||function(n,i){for(var o in n)o!=="default"&&!Object.prototype.hasOwnProperty.call(i,o)&&t(i,n,o)};Object.defineProperty(e,"__esModule",{value:!0}),r(Sg,e),r(Tg,e)}(Ag),function(e){var t=Se&&Se.__createBinding||(Object.create?function(s,a,u,f){f===void 0&&(f=u);var h=Object.getOwnPropertyDescriptor(a,u);(!h||("get"in h?!a.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(s,f,h)}:function(s,a,u,f){f===void 0&&(f=u),s[f]=a[u]}),r=Se&&Se.__exportStar||function(s,a){for(var u in s)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,s,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.request=void 0;const n=pn,i=async(s,a,u)=>{var f;let h=((f=window.OrangecryptoProviders)==null?void 0:f.BitcoinProvider)||window.OrangeBitcoinProvider;if(u&&(h=await(0,n.getProviderById)(u)),!h)throw new Error("no wallet provider was found");if(!s)throw new Error("A wallet method is required");const d=await h.request(s,a);return o(d)?{status:"success",result:d.result}:{status:"error",error:d.error}};e.request=i;const o=s=>Object.hasOwn(s,"result")&&!!s.result;r(Ag,e)}(Eg);var _g={},kg={};Object.defineProperty(kg,"__esModule",{value:!0}),function(e){var t=Se&&Se.__createBinding||(Object.create?function(a,u,f,h){h===void 0&&(h=f);var d=Object.getOwnPropertyDescriptor(u,f);(!d||("get"in d?!u.__esModule:d.writable||d.configurable))&&(d={enumerable:!0,get:function(){return u[f]}}),Object.defineProperty(a,h,d)}:function(a,u,f,h){h===void 0&&(h=f),a[h]=u[f]}),r=Se&&Se.__exportStar||function(a,u){for(var f in a)f!=="default"&&!Object.prototype.hasOwnProperty.call(u,f)&&t(u,a,f)};Object.defineProperty(e,"__esModule",{value:!0}),e.getCapabilities=void 0;const n=Dr,i=pn,o=(a,u)=>{const f=d=>!(!a[d]||u&&!u.has(d)),h={request:f("request"),connect:f("connect"),signMessage:f("signMessage"),signTransaction:f("signTransaction"),sendBtcTransaction:f("sendBtcTransaction"),createInscription:f("createInscription"),createRepeatInscriptions:f("createRepeatInscriptions"),signMultipleTransactions:f("signMultipleTransactions")};return Object.entries(h).reduce((d,[g,v])=>v?[...d,g]:d,[])},s=async a=>{var u,f,h;const d=await(0,i.getProviderOrThrow)(a.getProvider),g=(0,n.createUnsecuredToken)(a.payload);if(d.getCapabilities)try{const v=await d.getCapabilities(g);(u=a.onFinish)==null||u.call(a,o(d,new Set(v)))}catch(v){console.error("[Connect] Error during capabilities request",v)}try{const v=o(d);(f=a.onFinish)==null||f.call(a,v)}catch(v){console.error("[Connect] Error during capabilities request",v),(h=a.onCancel)==null||h.call(a)}};e.getCapabilities=s,r(kg,e)}(_g);var Pg={},Xc={},ra={};Object.defineProperty(ra,"__esModule",{value:!0}),ra.validateInscriptionPayload=void 0;const M6=4e5,F6=6e4,V6=e=>{const{contentType:t,content:r,payloadType:n,network:i,appFeeAddress:o,appFee:s}=e;if(!/^[a-z]+\/[a-z0-9\-\.\+]+(?=;.*|$)/.test(t))throw new Error("Invalid content type detected");if(!r||r.length===0)throw new Error("Empty content not allowed");if(!n||n!=="BASE_64"&&n!=="PLAIN_TEXT")throw new Error("Empty invalid payloadType specified");if(r.length>(i.type==="Mainnet"?M6:F6))throw new Error("Content too large");if(((o==null?void 0:o.length)??0)>0&&(s??0)<=0)throw new Error("Invalid combination of app fee address and fee provided")};ra.validateInscriptionPayload=V6,Object.defineProperty(Xc,"__esModule",{value:!0}),Xc.createInscription=void 0;const z6=Dr,W6=pn,q6=ra,G6=async e=>{var t,r;const{getProvider:n}=e,i=await(0,W6.getProviderOrThrow)(n);(0,q6.validateInscriptionPayload)(e.payload);try{const o=(0,z6.createUnsecuredToken)(e.payload),s=await i.createInscription(o);(t=e.onFinish)==null||t.call(e,s)}catch(o){console.error("[Connect] Error during create inscription",o),(r=e.onCancel)==null||r.call(e)}};Xc.createInscription=G6;var Jc={};Object.defineProperty(Jc,"__esModule",{value:!0}),Jc.createRepeatInscriptions=void 0;const X6=pn,J6=Dr,Y6=ra,Z6=async e=>{var t,r;const{getProvider:n}=e,i=await(0,X6.getProviderOrThrow)(n);(0,Y6.validateInscriptionPayload)(e.payload);try{const o=(0,J6.createUnsecuredToken)(e.payload),s=await i.createRepeatInscriptions(o);(t=e.onFinish)==null||t.call(e,s)}catch(o){console.error("[Connect] Error during create repeat inscriptions",o),(r=e.onCancel)==null||r.call(e)}};Jc.createRepeatInscriptions=Z6;var Og={};Object.defineProperty(Og,"__esModule",{value:!0}),function(e){var t=Se&&Se.__createBinding||(Object.create?function(n,i,o,s){s===void 0&&(s=o);var a=Object.getOwnPropertyDescriptor(i,o);(!a||("get"in a?!i.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return i[o]}}),Object.defineProperty(n,s,a)}:function(n,i,o,s){s===void 0&&(s=o),n[s]=i[o]}),r=Se&&Se.__exportStar||function(n,i){for(var o in n)o!=="default"&&!Object.prototype.hasOwnProperty.call(i,o)&&t(i,n,o)};Object.defineProperty(e,"__esModule",{value:!0}),r(Xc,e),r(Jc,e),r(Og,e)}(Pg);var Ig={},xg={};Object.defineProperty(xg,"__esModule",{value:!0}),function(e){var t=Se&&Se.__createBinding||(Object.create?function(s,a,u,f){f===void 0&&(f=u);var h=Object.getOwnPropertyDescriptor(a,u);(!h||("get"in h?!a.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(s,f,h)}:function(s,a,u,f){f===void 0&&(f=u),s[f]=a[u]}),r=Se&&Se.__exportStar||function(s,a){for(var u in s)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,s,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.signMessage=void 0;const n=Dr,i=pn,o=async s=>{var a,u;const f=await(0,i.getProviderOrThrow)(s.getProvider),{address:h,message:d}=s.payload;if(!h)throw new Error("An address is required to sign a message");if(!d)throw new Error("A message to be signed is required");try{const g=(0,n.createUnsecuredToken)(s.payload),v=await f.signMessage(g);(a=s.onFinish)==null||a.call(s,v)}catch(g){console.error("[Connect] Error during sign message request",g),(u=s.onCancel)==null||u.call(s)}};e.signMessage=o,r(xg,e)}(Ig);var $g={},Yc={};Object.defineProperty(Yc,"__esModule",{value:!0}),Yc.sendBtcTransaction=void 0;const Q6=Dr,e5=pn,t5=e=>e.map(t=>{const{address:r,amountSats:n}=t;return{address:r,amountSats:n.toString()}}),r5=async e=>{var t,r;const n=await(0,e5.getProviderOrThrow)(e.getProvider),{recipients:i,senderAddress:o,network:s,message:a}=e.payload;if(!i||i.length===0)throw new Error("At least one recipient is required");if(i.some(u=>typeof u.address!="string"||typeof u.amountSats!="bigint"))throw new Error("Incorrect recipient format");if(!o)throw new Error("The sender address is required");try{const u=t5(i),f={network:s,senderAddress:o,message:a,recipients:u},h=(0,Q6.createUnsecuredToken)(f),d=await n.sendBtcTransaction(h);(t=e.onFinish)==null||t.call(e,d)}catch(u){console.error("[Connect] Error during send BTC transaction request",u),(r=e.onCancel)==null||r.call(e)}};Yc.sendBtcTransaction=r5;var Zc={};Object.defineProperty(Zc,"__esModule",{value:!0}),Zc.signTransaction=void 0;const n5=Dr,i5=pn,s5=async e=>{var t,r;const n=await(0,i5.getProviderOrThrow)(e.getProvider),{psbtBase64:i,inputsToSign:o}=e.payload;if(!i)throw new Error("A value for psbtBase64 representing the tx hash is required");if(!o)throw new Error("An array specifying the inputs to be signed by the wallet is required");try{const s=(0,n5.createUnsecuredToken)(e.payload),a=await n.signTransaction(s);(t=e.onFinish)==null||t.call(e,a)}catch(s){console.error("[Connect] Error during sign transaction request",s),(r=e.onCancel)==null||r.call(e)}};Zc.signTransaction=s5;var Qc={};Object.defineProperty(Qc,"__esModule",{value:!0}),Qc.signMultipleTransactions=void 0;const o5=Dr,a5=pn,c5=async e=>{var t,r;const n=await(0,a5.getProviderOrThrow)(e.getProvider),{psbts:i}=e.payload;if(!i||!i.length)throw new Error("psbts array is required");if(i.length>100)throw new Error("psbts array must contain less than 100 psbts");try{const o=(0,o5.createUnsecuredToken)(e.payload),s=await n.signMultipleTransactions(o);(t=e.onFinish)==null||t.call(e,s)}catch(o){console.error("[Connect] Error during sign Multiple transactions request",o),(r=e.onCancel)==null||r.call(e)}};Qc.signMultipleTransactions=c5;var Cg={};Object.defineProperty(Cg,"__esModule",{value:!0}),function(e){var t=Se&&Se.__createBinding||(Object.create?function(n,i,o,s){s===void 0&&(s=o);var a=Object.getOwnPropertyDescriptor(i,o);(!a||("get"in a?!i.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return i[o]}}),Object.defineProperty(n,s,a)}:function(n,i,o,s){s===void 0&&(s=o),n[s]=i[o]}),r=Se&&Se.__exportStar||function(n,i){for(var o in n)o!=="default"&&!Object.prototype.hasOwnProperty.call(i,o)&&t(i,n,o)};Object.defineProperty(e,"__esModule",{value:!0}),r(Yc,e),r(Zc,e),r(Qc,e),r(Cg,e)}($g);var Ng={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.RpcErrorCode=e.BitcoinNetworkType=void 0,function(t){t.Mainnet="Mainnet",t.Testnet="Testnet"}(e.BitcoinNetworkType||(e.BitcoinNetworkType={})),function(t){t[t.PARSE_ERROR=-32700]="PARSE_ERROR",t[t.INVALID_REQUEST=-32600]="INVALID_REQUEST",t[t.METHOD_NOT_FOUND=-32601]="METHOD_NOT_FOUND",t[t.INVALID_PARAMS=-32602]="INVALID_PARAMS",t[t.INTERNAL_ERROR=-32603]="INTERNAL_ERROR",t[t.USER_REJECTION=-32e3]="USER_REJECTION",t[t.METHOD_NOT_SUPPORTED=-32001]="METHOD_NOT_SUPPORTED"}(e.RpcErrorCode||(e.RpcErrorCode={}))})(Ng),function(e){var t=Se&&Se.__createBinding||(Object.create?function(n,i,o,s){s===void 0&&(s=o);var a=Object.getOwnPropertyDescriptor(i,o);(!a||("get"in a?!i.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return i[o]}}),Object.defineProperty(n,s,a)}:function(n,i,o,s){s===void 0&&(s=o),n[s]=i[o]}),r=Se&&Se.__exportStar||function(n,i){for(var o in n)o!=="default"&&!Object.prototype.hasOwnProperty.call(i,o)&&t(i,n,o)};Object.defineProperty(e,"__esModule",{value:!0}),r(bg,e),r(Eg,e),r(_g,e),r(Pg,e),r(Ig,e),r(pn,e),r($g,e),r(Ng,e)}(Zh);const u5=uv(Zh),Bg=["address","paymentAddress","publicKey","paymentPublicKey","balance"],{signMessage:l5,sendBtcTransaction:h5,signTransaction:f5}=u5,d5="ORANGE_CONNECTED_WALLET_STATE";let p5=class extends ln{constructor(){super(...arguments),de(this,"observer"),de(this,"$valueStore",ro(d5,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),de(this,"removeSubscriber")}get library(){var t;return(t=window==null?void 0:window.OrangeWalletProviders)==null?void 0:t.OrangeBitcoinProvider}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Bg)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===Si&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Bg.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){var t;typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var r,n;(r=window==null?void 0:window.OrangeWalletProviders)!=null&&r.OrangeBitcoinProvider&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Si]:!0}),(n=this.observer)==null||n.disconnect())}),(t=this.observer)==null||t.observe(document,{childList:!0,subtree:!0})),nn(this.$store,["provider"],r=>{r.provider!==Si?this.removeSubscriber&&(this.$valueStore.set({address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){const{address:r,paymentAddress:n}=this.$valueStore.get();try{if(r){this.restorePersistedValues(),zt(n,this.network).then(s=>{this.$store.setKey("balance",s)});return}let i=Vo(this.network||tt);const o={payload:{purposes:["ordinals","payment"],message:"Address for receiving Ordinals and payments",network:{type:i}},onFinish:s=>{const a=jh(s.addresses),u=Dh(s.addresses);a&&u&&(this.$store.setKey("publicKey",String(s.addresses[0].publicKey)),this.$store.setKey("paymentPublicKey",String(s.addresses[1].publicKey)),this.$store.setKey("provider",Si),this.$store.setKey("address",a.address),this.$store.setKey("paymentAddress",u.address)),zt(u.address,this.network).then(f=>{this.$store.setKey("balance",f)})},onCancel:()=>{throw new Error(`User canceled lasereyes to ${Si} wallet`)}};await Zh.getAddress(o),this.$store.setKey("connected",!0)}catch(i){throw i}}async requestAccounts(){return[this.$store.get().address,this.$store.get().paymentAddress]}async getNetwork(){const{address:t}=this.$store.get();return t.slice(0,1)==="t"&&[it,Zt,Yt,Qt].includes(this.network)?this.network:tt}getPublicKey(){throw Hr}async getBalance(){const{paymentAddress:t}=this.$store.get();return await zt(t,this.network)}getInscriptions(){throw Hr}async sendBTC(t,r){let n="";const i={payload:{network:{type:Vo(this.network)},recipients:[{address:t,amountSats:BigInt(r)}],senderAddress:this.$store.get().paymentAddress},onFinish:o=>{console.log(o),n=o},onCancel:()=>{throw new Error("User canceled the request")}};return await h5(i),n}async signMessage(t,r){let n="";const i=r||this.$store.get().paymentAddress,o={payload:{network:{type:Vo(this.network)},address:i,message:t},onFinish:s=>{n=s},onCancel:()=>alert("Signature request canceled")};return await l5(o),n}async signPsbt(t,r,n,i,o){const s=ct.fromBase64(String(n),{network:er(this.network)}),a=this.$store.get().address,u=this.$store.get().paymentAddress,f=s.data.inputs,h=[],d={address:a,signingIndexes:[]},g={address:u,signingIndexes:[]};let v=0;for await(let I of f){if(I.witnessUtxo===void 0)g.signingIndexes.push(Number(v));else{const{script:k}=I.witnessUtxo,R=Ko(k,er(this.network));R===u?g.signingIndexes.push(Number(v)):R===a&&d.signingIndexes.push(Number(v))}v++}d.signingIndexes.length>0&&h.push(d),g.signingIndexes.length>0&&h.push(g);let E,T,x;const N={payload:{network:{type:Vo(this.network)},psbtBase64:s.toBase64(),broadcast:o,inputsToSign:h},onFinish:I=>{if(console.log(I),I.txId)E=I.txId;else if(I.psbtBase64){const k=ct.fromBase64(String(I.psbtBase64),{network:er(this.network)});T=k.toHex(),x=k.toBase64()}},onCancel:()=>console.log("Canceled")};return await f5(N),{signedPsbtHex:T,signedPsbtBase64:x,txId:E}}async pushPsbt(t){let r=t;if(!r.startsWith("02")){const n=ct.fromHex(r);n.finalizeAllInputs(),r=n.extractTransaction().toHex()}return await qe.post(`${ti(this.network)}/api/tx`,r).then(n=>n.data)}};const Ug=["address","paymentAddress","publicKey","paymentPublicKey","balance"],y5="OKX_CONNECTED_WALLET_STATE";class g5 extends ln{constructor(){super(...arguments),de(this,"observer"),de(this,"$valueStore",ro(y5,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),de(this,"removeSubscriber")}get library(){var t,r;let n;return this.network===it||this.network===Zt||this.network===Yt||this.network===Qt?n=(t=window==null?void 0:window.okxwallet)==null?void 0:t.bitcoinTestnet:(this.network===tt||this.network===ls)&&(n=(r=window==null?void 0:window.okxwallet)==null?void 0:r.bitcoin),n}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Ug)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===ss&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Ug.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){var t;typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var r;this.library&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[ss]:!0}),(r=this.observer)==null||r.disconnect())}),(t=this.observer)==null||t.observe(document,{childList:!0,subtree:!0})),nn(this.$store,["provider"],r=>{r.provider!==ss?this.removeSubscriber&&(this.$valueStore.set({address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){var r;try{const n=await this.library.connect();if(!n)throw new Error("No accounts found");this.$store.setKey("address",n.address),this.$store.setKey("paymentAddress",n.address),this.$store.setKey("publicKey",n.publicKey),this.$store.setKey("paymentPublicKey",n.publicKey),this.$store.setKey("accounts",[n]);const i=await((r=this.library)==null?void 0:r.getBalance());this.$store.setKey("balance",i.total),this.$store.setKey("provider",ss),this.$store.setKey("connected",!0)}catch(n){throw n}}async requestAccounts(){const t=this.library,r=this.network;return r===it||r===Zt||r===Qt?await t.connect():await t.requestAccounts()}async getNetwork(){const{address:t}=this.$store.get(),r=this.network;if(t.slice(0,1)==="t")return r===it?it:r===Zt?Zt:r===Yt?Yt:r===Qt?Qt:it;const n=await this.library.getNetwork();return B0(n)}async getPublicKey(){const t=this.library;return await(t==null?void 0:t.getPublicKey())}async getBalance(){const{paymentAddress:t}=this.$store.get();return await zt(t,this.network)}async getInscriptions(){return await this.library.getInscriptions(0,10)}async sendBTC(t,r){const n=await this.library.sendBitcoin(t,r);if(!n)throw new Error("Transaction failed");return n}async signMessage(t,r){const n=this.library;return await(n==null?void 0:n.signMessage(t))}async signPsbt(t,r,n,i,o){const s=await this.library.signPsbt(r,{autoFinalized:i}),a=ct.fromHex(s);if(i&&o){const u=await this.pushPsbt(s);return{signedPsbtHex:a.toHex(),signedPsbtBase64:a.toBase64(),txId:u}}return{signedPsbtHex:a.toHex(),signedPsbtBase64:a.toBase64(),txId:void 0}}async pushPsbt(t){return await qe.post(`${ti(this.network)}/api/tx`,t).then(r=>r.data)}}const Rg=["address","paymentAddress","publicKey","paymentPublicKey","balance"],w5="MAGIC_EDEN_CONNECTED_WALLET_STATE";class b5 extends ln{constructor(){super(...arguments),de(this,"observer"),de(this,"$valueStore",ro(w5,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),de(this,"removeSubscriber")}get library(){var t;return(t=window==null?void 0:window.magicEden)==null?void 0:t.bitcoin}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Rg)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===Wn&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Rg.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t,r;(t=window==null?void 0:window.magicEden)!=null&&t.bitcoin&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Wn]:!0}),(r=this.observer)==null||r.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),nn(this.$store,["provider"],t=>{t.provider!==Wn?this.removeSubscriber&&(this.$valueStore.set({address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){const{address:r,paymentAddress:n}=this.$valueStore.get();try{if(r){this.restorePersistedValues(),zt(n,this.network).then(o=>{this.$store.setKey("balance",o)});return}let i=Vs(this.network||tt);await fg({getProvider:async()=>this.library,payload:{purposes:["ordinals","payment"],message:"Address for receiving Ordinals and payments",network:{type:i}},onFinish:o=>{const s=jh(o.addresses),a=Dh(o.addresses);s&&a&&(this.$store.setKey("provider",Wn),this.$store.setKey("address",s.address),this.$store.setKey("paymentAddress",a.address)),this.$store.setKey("publicKey",String(o.addresses[0].publicKey)),this.$store.setKey("paymentPublicKey",String(o.addresses[1].publicKey)),zt(a.address,this.network).then(u=>{this.$store.setKey("balance",u)})},onCancel:()=>{throw new Error(`User canceled lasereyes to ${Wn} wallet`)},onError:o=>{throw new Error(`Can't lasereyes to ${Wn} wallet`)}}),this.$store.setKey("connected",!0)}catch(i){throw i}}async requestAccounts(){return[this.$store.get().address,this.$store.get().paymentAddress]}async getNetwork(){const{address:t}=this.$store.get();return t.slice(0,1)==="t"&&[it,Zt,Yt,Qt].includes(this.network)?this.network:tt}getPublicKey(){throw Hr}async getBalance(){const{paymentAddress:t}=this.$store.get();return await zt(t,this.network)}getInscriptions(){throw Hr}async sendBTC(t,r){let n;if(await N6({getProvider:async()=>this.library,payload:{network:{type:Vs(this.network)},recipients:[{address:t,amountSats:BigInt(r)}],senderAddress:this.$store.get().paymentAddress},onFinish:i=>{n=i},onCancel:()=>alert("Canceled")}),!n)throw new Error("Error sending BTC");return n.txid}async signMessage(t,r){try{const n=r||this.$store.get().paymentAddress;let i="";return await $6({getProvider:async()=>this.library,payload:{network:{type:cg.Mainnet},address:n,message:t,protocol:Gc.BIP322},onFinish:o=>{i=o},onCancel:()=>{alert("Request canceled")}}),i}catch(n){throw n}}async signPsbt(t,r,n,i,o){const{address:s,paymentAddress:a}=this.$store.get(),u=ct.fromBase64(String(n),{network:er(this.network)}),f=u.data.inputs,h=[],d={address:s,signingIndexes:[]},g={address:a,signingIndexes:[]};let v=0;for await(let k of f){const{script:R}=k.witnessUtxo,W=Ko(R,er(this.network));W===a?g.signingIndexes.push(Number(v)):W===s&&d.signingIndexes.push(Number(v)),v++}d.signingIndexes.length>0&&h.push(d),g.signingIndexes.length>0&&h.push(g);let E,T,x;const N=Vs(this.network),I={getProvider:async()=>this.library,payload:{network:{type:N},message:"Sign Transaction",psbtBase64:u.toBase64(),broadcast:o,inputsToSign:h},onFinish:k=>{if(k.psbtBase64){const R=ct.fromBase64(String(k.psbtBase64),{network:er(this.network)});T=R.toHex(),x=R.toBase64()}},onCancel:()=>{throw console.log("Canceled"),new Error("User canceled the request")},onError:k=>{throw console.log("error",k),k}};if(await signTransaction(I),o){const k=ct.fromBase64(String(x)).finalizeAllInputs().extractTransaction(),R=await this.pushPsbt(k.toHex());return{signedPsbtHex:k.toHex(),signedPsbtBase64:"test",txId:R}}else return{signedPsbtHex:T,signedPsbtBase64:x,txId:E}}async pushPsbt(t){return await qe.post(`${ti(this.network)}/api/tx`,t).then(r=>r.data)}}class m5 extends ln{constructor(){super(...arguments),de(this,"observer")}get library(){var t;return(t=window==null?void 0:window.phantom)==null?void 0:t.bitcoin}get network(){return this.$network.get()}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;this.library&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Ei]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),nn(this.$store,["provider"],t=>{if(t.provider!==Ei){this.removeListeners();return}this.library.requestAccounts().then(r=>{this.handleAccountsChanged(r)}),this.addListeners()})}addListeners(){this.library.on("accountsChanged",this.handleAccountsChanged.bind(this)),this.library.on("networkChanged",this.handleNetworkChanged.bind(this))}removeListeners(){this.library.removeListener("accountsChanged",this.handleAccountsChanged.bind(this)),this.library.removeListener("networkChanged",this.handleNetworkChanged.bind(this))}dispose(){var t;(t=this.observer)==null||t.disconnect(),this.removeListeners()}handleAccountsChanged(t){if(!t.length){this.parent.disconnect();return}this.$store.get().accounts[0]!==t[0]&&(this.$store.setKey("accounts",t),t.length>0?this.parent.connect(Ei):this.parent.disconnect())}handleNetworkChanged(t){const r=zs(t);this.network!==r&&this.switchNetwork(r),this.parent.connect(Ei)}async connect(t){if(!this.library)throw new Error("Unisat isn't installed");const r=await this.library.requestAccounts();if(console.log("phantomAccounts",r),!r)throw new Error("No accounts found");this.$store.setKey("accounts",r);const n=r.find(o=>o.purpose==="ordinals"),i=r.find(o=>o.purpose==="payment");this.$store.setKey("address",n.address),this.$store.setKey("paymentAddress",i.address),this.$store.setKey("publicKey",n.publicKey),this.$store.setKey("paymentPublicKey",i.publicKey),this.$store.setKey("provider",Ei),zt(r[0],this.network).then(o=>{this.$store.setKey("balance",o)}),this.$store.setKey("connected",!0)}async getNetwork(){return this.$store.get().address.slice(0,1)==="t"?it:tt}async sendBTC(t,r){const{psbtHex:n}=await Uy(this.$store.get().address,this.$store.get().paymentAddress,t,r,this.$store.get().paymentPublicKey,this.network,7),i=await this.signPsbt("",n,"",!0,!0);if(!i)throw new Error("Error sending BTC");return i.txId}async signMessage(t,r){var n;const i=new TextEncoder().encode(t),o=new Uint8Array(i),s=r||this.$store.get().paymentAddress,a=await((n=this.library)==null?void 0:n.signMessage(s,o)),u=String.fromCharCode(...a.signature);return btoa(u)}async signPsbt(t,r,n,i,o){const{address:s,paymentAddress:a}=this.$store.get(),u=ct.fromHex(String(r),{network:er(this.network)}).data.inputs,f=[],h={address:s,signingIndexes:[]},d={address:a,signingIndexes:[]};let g=0;for await(let T of u){const{script:x}=T.witnessUtxo,N=Ko(x,er(this.network));N===a?d.signingIndexes.push(Number(g)):N===s&&h.signingIndexes.push(Number(g)),g++}h.signingIndexes.length>0&&f.push(h),d.signingIndexes.length>0&&f.push(d);const v=await this.library.signPsbt(r,{inputsToSign:f}),E=ct.fromHex(v);if(i&&o){const T=await this.pushPsbt(v);return{signedPsbtHex:E.toHex(),signedPsbtBase64:E.toBase64(),txId:T}}return{signedPsbtHex:E.toHex(),signedPsbtBase64:E.toBase64(),txId:void 0}}async pushPsbt(t){return await qe.post(`${ti(this.network)}/api/tx`,t).then(r=>r.data)}async getPublicKey(){return this.$store.get().publicKey}async getBalance(){return(await this.library.getBalance()).total}async getInscriptions(){return await this.library.getInscriptions(0,10)}async requestAccounts(){return await this.library.requestAccounts()}async switchNetwork(t){var r;const n=mc(t);await((r=this.library)==null?void 0:r.switchChain(n)),this.$network.set(t),await this.getBalance()}}class v5 extends ln{constructor(){super(...arguments),de(this,"observer")}get library(){return window.opnet}get network(){return this.$network.get()}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;this.library&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Ti]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),nn(this.$store,["provider"],t=>{if(t.provider!==Ti){this.removeListeners();return}this.library.getAccounts().then(r=>{this.handleAccountsChanged(r)}),this.addListeners()})}addListeners(){this.library.on("accountsChanged",this.handleAccountsChanged.bind(this)),this.library.on("networkChanged",this.handleNetworkChanged.bind(this))}removeListeners(){this.library.removeListener("accountsChanged",this.handleAccountsChanged.bind(this)),this.library.removeListener("networkChanged",this.handleNetworkChanged.bind(this))}dispose(){var t;(t=this.observer)==null||t.disconnect(),this.removeListeners()}handleAccountsChanged(t){if(!t.length){this.parent.disconnect();return}this.$store.get().accounts[0]!==t[0]&&(this.$store.setKey("accounts",t),t.length>0?this.parent.connect(Ti):this.parent.disconnect())}handleNetworkChanged(t){const r=zs(t);this.network!==r&&this.switchNetwork(r),this.parent.connect(Ti)}async connect(t){if(!this.library)throw new Error("OP_NET isn't installed");const r=await this.library.requestAccounts();if(!r)throw new Error("No accounts found");const n=await this.library.getPublicKey();if(!n)throw new Error("No public key found");this.$store.setKey("accounts",r),this.$store.setKey("address",r[0]),this.$store.setKey("paymentAddress",r[0]),this.$store.setKey("publicKey",n),this.$store.setKey("paymentPublicKey",n),this.$store.setKey("provider",Ti),await this.getNetwork().then(i=>{var o;((o=this.config)==null?void 0:o.network)!==i&&this.switchNetwork(i)}),zt(r[0],this.network).then(i=>{this.$store.setKey("balance",i)}),this.$store.setKey("connected",!0)}async getNetwork(){var t;const r=await((t=this.library)==null?void 0:t.getChain());return r?zs(r.enum):this.network}async sendBTC(t,r){var n;const i=await((n=this.library)==null?void 0:n.sendBitcoin(t,r));if(!i)throw new Error("Transaction failed");return i}async signMessage(t,r){var n;return await((n=this.library)==null?void 0:n.signMessage(t))}async signPsbt(t,r,n,i,o){var s;const a=await((s=this.library)==null?void 0:s.signPsbt(r,{autoFinalized:i})),u=ct.fromHex(a);if(i&&o){const f=await this.pushPsbt(a);return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:f}}return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:void 0}}async pushPsbt(t){return await qe.post(`${ti(this.network)}/api/tx`,t).then(r=>r.data)}async getPublicKey(){var t;return await((t=this.library)==null?void 0:t.getPublicKey())}async getBalance(){return(await this.library.getBalance()).total}async getInscriptions(){return await this.library.getInscriptions(0,10)}async requestAccounts(){return await this.library.requestAccounts()}async switchNetwork(t){var r;const n=mc(t);await((r=this.library)==null?void 0:r.switchChain(n)),this.$network.set(t),await this.getBalance()}}class E5{constructor(t,r){de(this,"$store"),de(this,"$network"),de(this,"$providerMap"),this.config=r,this.$store=t.$store,this.$network=t.$network,this.$providerMap={[Ai]:new D6(t,this,r),[Wn]:new b5(t,this,r),[ss]:new g5(t,this,r),[Ti]:new v5(t,this,r),[Si]:new p5(t,this,r),[vi]:new K6(t,this,r),[Ei]:new m5(t,this,r),[zn]:new T8(t,this,r),[In]:new R6(t,this,r),[os]:new H6(t,this,r)},this.$network.subscribe(this.watchNetworkChange.bind(this)),Bd(this.$store,["isInitializing"],n=>this.handleIsInitializingChanged(n.isInitializing)),r&&r.network&&(this.$network.set(r.network),this.getNetwork().then(n=>{try{r.network!==n&&this.switchNetwork(r.network)}catch{this.disconnect()}})),Bd(this.$store,["hasProvider"],this.checkInitializationComplete.bind(this)),_8()}dispose(){Object.values(this.$providerMap).forEach(t=>t==null?void 0:t.dispose())}handleIsInitializingChanged(t){if(typeof window<"u"&&typeof localStorage<"u"&&!t){const r=localStorage==null?void 0:localStorage.getItem(La);r&&(this.$store.setKey("provider",r),this.connect(r))}}async connect(t){this.$store.setKey("isConnecting",!0);try{if(localStorage==null||localStorage.setItem(La,t),!this.$providerMap[t])throw new Error("Unsupported wallet provider");const r=this.$providerMap[t];await(r==null?void 0:r.connect(t)),this.$store.setKey("connected",!0)}catch(r){throw console.error(r),this.$store.setKey("isConnecting",!1),this.disconnect(),r}finally{this.$store.setKey("isConnecting",!1)}}async requestAccounts(){var t;if(!this.$store.get().provider)throw new Error("No wallet provider connected");if(!this.$providerMap[this.$store.get().provider])throw new Error("The connected wallet doesn't support this method");try{return await((t=this.$providerMap[this.$store.get().provider])==null?void 0:t.requestAccounts())}catch(r){throw r instanceof Error&&r.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support this method"):r}}disconnect(){this.$store.setKey("connected",!1),this.$store.setKey("provider",void 0),this.$store.setKey("address",""),this.$store.setKey("paymentAddress",""),this.$store.setKey("publicKey",""),this.$store.setKey("paymentPublicKey",""),this.$store.setKey("balance",void 0),this.$store.setKey("accounts",[]),localStorage==null||localStorage.removeItem(La)}switchNetwork(t){var r;try{this.$store.get().provider&&((r=this.$providerMap[this.$store.get().provider])==null||r.switchNetwork(t))}catch(n){throw n instanceof Error&&n.message.toLowerCase().includes("not implemented")?(this.disconnect(),new Error("The connected wallet doesn't support programmatic network changes..")):n}}checkInitializationComplete(){Object.values(this.$store.get().hasProvider).every(t=>t!==void 0)&&this.$store.setKey("isInitializing",!1)}watchNetworkChange(){this.$store.setKey("balance",void 0)}async getNetwork(){var t;return this.$store.get().provider&&this.$providerMap[this.$store.get().provider]?await((t=this.$providerMap[this.$store.get().provider])==null?void 0:t.getNetwork()):this.$network.get()}async sendBTC(t,r){var n;if(r<=0)throw new Error("Amount must be greater than 0");if(!Number.isInteger(r))throw new Error("Amount must be an integer");if(!this.$store.get().provider)throw new Error("No wallet connected");if(this.$providerMap[this.$store.get().provider])try{return await((n=this.$providerMap[this.$store.get().provider])==null?void 0:n.sendBTC(t,r))}catch(i){throw i instanceof Error&&i.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support sending BTC..."):i}}async signMessage(t,r){var n;if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((n=this.$providerMap[this.$store.get().provider])==null?void 0:n.signMessage(t,r))}catch(i){throw i instanceof Error&&i.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support message signing..."):i}}async signPsbt(t,r=!1,n=!1){var i;let o,s;if(!t)throw new Error("No PSBT provided");if(E8(t))s=ct.fromHex(t).toBase64(),o=t;else if(v8(t))s=t,o=ct.fromBase64(t).toHex();else throw new Error("Invalid PSBT format");if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((i=this.$providerMap[this.$store.get().provider])==null?void 0:i.signPsbt(t,o,s,r,n))}catch(a){throw a instanceof Error&&a.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support PSBT signing..."):a}else throw new Error("No wallet provider connected")}async pushPsbt(t){var r;if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((r=this.$providerMap[this.$store.get().provider])==null?void 0:r.pushPsbt(t))}catch(n){throw n instanceof Error&&n.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support PSBT signing..."):n}}async getPublicKey(){var t;if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((t=this.$providerMap[this.$store.get().provider])==null?void 0:t.getPublicKey())}catch(r){throw r instanceof Error&&r.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support this method"):r}}async getBalance(){if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{const t=await this.$providerMap[this.$store.get().provider].getBalance();return this.$store.setKey("balance",BigInt(t)),t}catch(t){throw t instanceof Error&&t.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support this method"):t}}async getInscriptions(){var t;if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((t=this.$providerMap[this.$store.get().provider])==null?void 0:t.getInscriptions())}catch(r){throw r instanceof Error&&r.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support this method"):r}}}var A5=Object.defineProperty,S5=(e,t,r)=>t in e?A5(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ge=(e,t,r)=>S5(e,typeof t!="symbol"?t+"":t,r);function T5(e,t){for(var r=0;r<t.length;r++){const n=t[r];if(typeof n!="string"&&!Array.isArray(n)){for(const i in n)if(i!=="default"&&!(i in e)){const o=Object.getOwnPropertyDescriptor(n,i);o&&Object.defineProperty(e,i,o.get?o:{enumerable:!0,get:()=>n[i]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}let Qh=Symbol("clean"),yn=[],Ki=0;const eu=4;let ef=e=>{let t=[],r={get(){return r.lc||r.listen(()=>{})(),r.value},lc:0,listen(n){return r.lc=t.push(n),()=>{for(let o=Ki+eu;o<yn.length;)yn[o]===n?yn.splice(o,eu):o+=eu;let i=t.indexOf(n);~i&&(t.splice(i,1),--r.lc||r.off())}},notify(n,i){let o=!yn.length;for(let s of t)yn.push(s,r.value,n,i);if(o){for(Ki=0;Ki<yn.length;Ki+=eu)yn[Ki](yn[Ki+1],yn[Ki+2],yn[Ki+3]);yn.length=0}},off(){},set(n){let i=r.value;i!==n&&(r.value=n,r.notify(i))},subscribe(n){let i=r.listen(n);return n(r.value),i},value:e};return process.env.NODE_ENV!=="production"&&(r[Qh]=()=>{t=[],r.lc=0,r.off()}),r};const _5=5,no=6,tu=10;let k5=(e,t,r,n)=>(e.events=e.events||{},e.events[r+tu]||(e.events[r+tu]=n(i=>{e.events[r].reduceRight((o,s)=>(s(o),o),{shared:{},...i})})),e.events[r]=e.events[r]||[],e.events[r].push(t),()=>{let i=e.events[r],o=i.indexOf(t);i.splice(o,1),i.length||(delete e.events[r],e.events[r+tu](),delete e.events[r+tu])}),P5=1e3,O5=(e,t)=>k5(e,r=>{let n=t(r);n&&e.events[no].push(n)},_5,r=>{let n=e.listen;e.listen=(...o)=>(!e.lc&&!e.active&&(e.active=!0,r()),n(...o));let i=e.off;if(e.events[no]=[],e.off=()=>{i(),setTimeout(()=>{if(e.active&&!e.lc){e.active=!1;for(let o of e.events[no])o();e.events[no]=[]}},P5)},process.env.NODE_ENV!=="production"){let o=e[Qh];e[Qh]=()=>{for(let s of e.events[no])s();e.events[no]=[],e.active=!1,o()}}return()=>{e.listen=n,e.off=i}});function gn(e,t,r){let n=new Set([...t,void 0]);return e.listen((i,o,s)=>{n.has(s)&&r(i,o,s)})}function Hg(e,t,r){let n=gn(e,t,r);return r(e.value),n}let Lg=(e={})=>{let t=ef(e);return t.setKey=function(r,n){let i=t.value;typeof n>"u"&&r in t.value?(t.value={...t.value},delete t.value[r],t.notify(i,r)):t.value[r]!==n&&(t.value={...t.value,[r]:n},t.notify(i,r))},t};const ms="oyl",ji="unisat",ii="xverse",Di="phantom",vs="leather",si="magic-eden",Es="okx",As="wizz",Mi="orange",Fi="op_net",tf="p2tr",Kg="p2wpkh",rf="defaultWallet",wn={messagePrefix:`Bitcoin Signed Message:
|
|
30
30
|
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},I5={messagePrefix:`Bitcoin Signed Message:
|
|
31
31
|
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};function x5(e){if(e.length<8||e.length>72||e[0]!==48||e[1]!==e.length-2||e[2]!==2)return!1;const t=e[3];if(t===0||5+t>=e.length||e[4+t]!==2)return!1;const r=e[5+t];return!(r===0||6+t+r!==e.length||e[4]&128||t>1&&e[4]===0&&!(e[5]&128)||e[t+6]&128||r>1&&e[t+6]===0&&!(e[t+7]&128))}function $5(e){if(e.length<8)throw new Error("DER sequence length is too short");if(e.length>72)throw new Error("DER sequence length is too long");if(e[0]!==48)throw new Error("Expected DER sequence");if(e[1]!==e.length-2)throw new Error("DER sequence length is invalid");if(e[2]!==2)throw new Error("Expected DER integer");const t=e[3];if(t===0)throw new Error("R length is zero");if(5+t>=e.length)throw new Error("R length is too long");if(e[4+t]!==2)throw new Error("Expected DER integer (2)");const r=e[5+t];if(r===0)throw new Error("S length is zero");if(6+t+r!==e.length)throw new Error("S length is invalid");if(e[4]&128)throw new Error("R value is negative");if(t>1&&e[4]===0&&!(e[5]&128))throw new Error("R value excessively padded");if(e[t+6]&128)throw new Error("S value is negative");if(r>1&&e[t+6]===0&&!(e[t+7]&128))throw new Error("S value excessively padded");return{r:e.slice(4,4+t),s:e.slice(6+t)}}function C5(e,t){const r=e.length,n=t.length;if(r===0)throw new Error("R length is zero");if(n===0)throw new Error("S length is zero");if(r>33)throw new Error("R length is too long");if(n>33)throw new Error("S length is too long");if(e[0]&128)throw new Error("R value is negative");if(t[0]&128)throw new Error("S value is negative");if(r>1&&e[0]===0&&!(e[1]&128))throw new Error("R value excessively padded");if(n>1&&t[0]===0&&!(t[1]&128))throw new Error("S value excessively padded");const i=new Uint8Array(6+r+n);return i[0]=48,i[1]=i.length-2,i[2]=2,i[3]=e.length,i.set(e,4),i[4+r]=2,i[5+r]=t.length,i.set(t,6+r),i}const Ge={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_NOP2:177,OP_CHECKLOCKTIMEVERIFY:177,OP_NOP3:178,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_CHECKSIGADD:186,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255},jg={};for(const e of Object.keys(Ge)){const t=Ge[e];jg[t]=e}const ru="0123456789abcdefABCDEF",nu=ru.split("").map(e=>e.codePointAt(0)),iu=Array(256).fill(!0).map((e,t)=>{const r=String.fromCodePoint(t),n=ru.indexOf(r);return n<0?void 0:n<16?n:n-6}),Dg=new TextEncoder,Mg=new TextDecoder;function N5(e){return Mg.decode(e)}function B5(e){return Dg.encode(e)}function ht(e){const t=e.reduce((i,o)=>i+o.length,0),r=new Uint8Array(t);let n=0;for(const i of e)r.set(i,n),n+=i.length;return r}function Ee(e){const t=e||new Uint8Array;return t.length>512?R5(t):U5(t)}function U5(e){let t="";for(let r=0;r<e.length;++r)t+=ru[iu[nu[e[r]>>4]]],t+=ru[iu[nu[e[r]&15]]];return t}function R5(e){const t=new Uint8Array(e.length*2);for(let r=0;r<e.length;++r)t[r*2]=nu[e[r]>>4],t[r*2+1]=nu[e[r]&15];return Mg.decode(t)}function oi(e){const t=Dg.encode(e||""),r=new Uint8Array(Math.floor(t.length/2));let n;for(n=0;n<r.length;n++){const i=iu[t[n*2]],o=iu[t[n*2+1]];if(i===void 0||o===void 0)break;r[n]=i<<4|o}return n===r.length?r:r.slice(0,n)}function H5(e){return btoa(String.fromCharCode(...e))}function Fg(e){const t=atob(e),r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t.charCodeAt(n);return r}function ee(e,t){const r=Math.min(e.length,t.length);for(let n=0;n<r;++n)if(e[n]!==t[n])return e[n]<t[n]?-1:1;return e.length===t.length?0:e.length>t.length?1:-1}function Pr(e,t,r){if(t+1>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r>255)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 255. Received ${r}`);return e[t]=r,t+1}function L5(e,t,r,n){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>65535)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 65535. Received ${r}`);return n==="LE"?(e[t]=r&255,e[t+1]=r>>8&255):(e[t]=r>>8&255,e[t+1]=r&255),t+2}function na(e,t,r,n){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>4294967295)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${4294967295}. Received ${r}`);return n==="LE"?(e[t]=r&255,e[t+1]=r>>8&255,e[t+2]=r>>16&255,e[t+3]=r>>24&255):(e[t]=r>>24&255,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=r&255),t+4}function K5(e,t,r,n){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>0xffffffffffffffffn)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${0xffffffffffffffffn}. Received ${r}`);return n==="LE"?(e[t]=Number(r&0xffn),e[t+1]=Number(r>>8n&0xffn),e[t+2]=Number(r>>16n&0xffn),e[t+3]=Number(r>>24n&0xffn),e[t+4]=Number(r>>32n&0xffn),e[t+5]=Number(r>>40n&0xffn),e[t+6]=Number(r>>48n&0xffn),e[t+7]=Number(r>>56n&0xffn)):(e[t]=Number(r>>56n&0xffn),e[t+1]=Number(r>>48n&0xffn),e[t+2]=Number(r>>40n&0xffn),e[t+3]=Number(r>>32n&0xffn),e[t+4]=Number(r>>24n&0xffn),e[t+5]=Number(r>>16n&0xffn),e[t+6]=Number(r>>8n&0xffn),e[t+7]=Number(r&0xffn)),t+8}function ai(e,t){if(t+1>e.length)throw new Error("Offset is outside the bounds of Uint8Array");return e[t]}function j5(e,t,r){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),r==="LE"){let n=0;return n=(n<<8)+e[t+1],n=(n<<8)+e[t],n}else{let n=0;return n=(n<<8)+e[t],n=(n<<8)+e[t+1],n}}function io(e,t,r){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),r==="LE"){let n=0;return n=(n<<8)+e[t+3]>>>0,n=(n<<8)+e[t+2]>>>0,n=(n<<8)+e[t+1]>>>0,n=(n<<8)+e[t]>>>0,n}else{let n=0;return n=(n<<8)+e[t]>>>0,n=(n<<8)+e[t+1]>>>0,n=(n<<8)+e[t+2]>>>0,n=(n<<8)+e[t+3]>>>0,n}}function Vg(e,t,r,n){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r>2147483647||r<-2147483648)throw new Error(`The value of "value" is out of range. It must be >= -2147483648 and <= 2147483647. Received ${r}`);return n=n.toUpperCase(),n==="LE"?(e[t]=r&255,e[t+1]=r>>8&255,e[t+2]=r>>16&255,e[t+3]=r>>24&255):(e[t]=r>>24&255,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=r&255),t+4}function zg(e,t,r,n){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r>0x7fffffffffffffffn||r<-0x8000000000000000n)throw new Error(`The value of "value" is out of range. It must be >= ${-0x8000000000000000n} and <= ${0x7fffffffffffffffn}. Received ${r}`);return n=n.toUpperCase(),n==="LE"?(e[t]=Number(r&0xffn),e[t+1]=Number(r>>8n&0xffn),e[t+2]=Number(r>>16n&0xffn),e[t+3]=Number(r>>24n&0xffn),e[t+4]=Number(r>>32n&0xffn),e[t+5]=Number(r>>40n&0xffn),e[t+6]=Number(r>>48n&0xffn),e[t+7]=Number(r>>56n&0xffn)):(e[t]=Number(r>>56n&0xffn),e[t+1]=Number(r>>48n&0xffn),e[t+2]=Number(r>>40n&0xffn),e[t+3]=Number(r>>32n&0xffn),e[t+4]=Number(r>>24n&0xffn),e[t+5]=Number(r>>16n&0xffn),e[t+6]=Number(r>>8n&0xffn),e[t+7]=Number(r&0xffn)),t+8}function D5(e,t,r){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),r==="LE"){const n=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24>>>0);return e[t+3]<=127?n:n-4294967296}else{const n=(e[t]<<24>>>0)+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];return e[t]<=127?n:n-4294967296}}function Wg(e,t,r){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");r=r.toUpperCase();let n=0n;if(r==="LE")return n=(n<<8n)+BigInt(e[t+7]),n=(n<<8n)+BigInt(e[t+6]),n=(n<<8n)+BigInt(e[t+5]),n=(n<<8n)+BigInt(e[t+4]),n=(n<<8n)+BigInt(e[t+3]),n=(n<<8n)+BigInt(e[t+2]),n=(n<<8n)+BigInt(e[t+1]),n=(n<<8n)+BigInt(e[t]),e[t+7]<=127?n:n-0x10000000000000000n;{let i=0n;return i=(i<<8n)+BigInt(e[t]),i=(i<<8n)+BigInt(e[t+1]),i=(i<<8n)+BigInt(e[t+2]),i=(i<<8n)+BigInt(e[t+3]),i=(i<<8n)+BigInt(e[t+4]),i=(i<<8n)+BigInt(e[t+5]),i=(i<<8n)+BigInt(e[t+6]),i=(i<<8n)+BigInt(e[t+7]),e[t]<=127?i:i-0x10000000000000000n}}function qg(e){return e<Ge.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}function M5(e,t,r){const n=qg(t);return n===1?Pr(e,r,t):n===2?(Pr(e,r,Ge.OP_PUSHDATA1),Pr(e,r+1,t)):n===3?(Pr(e,r,Ge.OP_PUSHDATA2),L5(e,r+1,t,"LE")):(Pr(e,r,Ge.OP_PUSHDATA4),na(e,r+1,t,"LE")),n}function F5(e,t){const r=ai(e,t);let n,i;if(r<Ge.OP_PUSHDATA1)n=r,i=1;else if(r===Ge.OP_PUSHDATA1){if(t+2>e.length)return null;n=ai(e,t+1),i=2}else if(r===Ge.OP_PUSHDATA2){if(t+3>e.length)return null;n=j5(e,t+1,"LE"),i=3}else{if(t+5>e.length)return null;if(r!==Ge.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=io(e,t+1,"LE"),i=5}return{opcode:r,number:n,size:i}}function V5(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function z5(e){let t=Math.abs(e);const r=V5(t),n=new Uint8Array(r),i=e<0;for(let o=0;o<r;++o)Pr(n,o,t&255),t>>=8;return n[r-1]&128?Pr(n,r-1,i?128:0):i&&(n[r-1]|=128),n}function W5(e){return{lang:(e==null?void 0:e.lang)??void 0,message:e==null?void 0:e.message,abortEarly:(e==null?void 0:e.abortEarly)??void 0,abortPipeEarly:(e==null?void 0:e.abortPipeEarly)??void 0}}function q5(e,t){var r;return(r=void 0)==null?void 0:r.get(t)}function ia(e){var t,r;const n=typeof e;return n==="string"?`"${e}"`:n==="number"||n==="bigint"||n==="boolean"?`${e}`:n==="object"||n==="function"?(e&&((r=(t=Object.getPrototypeOf(e))==null?void 0:t.constructor)==null?void 0:r.name))??"null":n}function Wt(e,t,r,n,i){const o=i&&"input"in i?i.input:r.value,s=(i==null?void 0:i.expected)??e.expects??null,a=(i==null?void 0:i.received)??ia(o),u={kind:e.kind,type:e.type,input:o,expected:s,received:a,message:`Invalid ${t}: ${s?`Expected ${s} but r`:"R"}eceived ${a}`,requirement:e.requirement,path:i==null?void 0:i.path,issues:i==null?void 0:i.issues,lang:n.lang,abortEarly:n.abortEarly,abortPipeEarly:n.abortPipeEarly},f=e.kind==="schema",h=(i==null?void 0:i.message)??e.message??q5(e.reference,u.lang)??(f?(u.lang,void 0):null)??n.message??(u.lang,void 0);h&&(u.message=typeof h=="function"?h(u):h),f&&(r.typed=!1),r.issues?r.issues.push(u):r.issues=[u]}function G5(e,t){const r=[...new Set(e)];return r.length>1?`(${r.join(` ${t} `)})`:r[0]??"never"}var X5=class extends Error{constructor(e){super(e[0].message),ge(this,"issues"),this.name="ValiError",this.issues=e}};function Gg(e,t){return{kind:"validation",type:"every_item",reference:Gg,async:!1,expects:null,requirement:e,message:t,_run(r,n){return r.typed&&!r.value.every(this.requirement)&&Wt(this,"item",r,n),r}}}function nf(e){return{kind:"validation",type:"integer",reference:nf,async:!1,expects:null,requirement:Number.isInteger,message:e,_run(t,r){return t.typed&&!this.requirement(t.value)&&Wt(this,"integer",t,r),t}}}function Xg(e,t){return{kind:"validation",type:"length",reference:Xg,async:!1,expects:`${e}`,requirement:e,message:t,_run(r,n){return r.typed&&r.value.length!==this.requirement&&Wt(this,"length",r,n,{received:`${r.value.length}`}),r}}}function su(e,t){return{kind:"validation",type:"max_value",reference:su,async:!1,expects:`<=${e instanceof Date?e.toJSON():ia(e)}`,requirement:e,message:t,_run(r,n){return r.typed&&r.value>this.requirement&&Wt(this,"value",r,n,{received:r.value instanceof Date?r.value.toJSON():ia(r.value)}),r}}}function ou(e,t){return{kind:"validation",type:"min_value",reference:ou,async:!1,expects:`>=${e instanceof Date?e.toJSON():ia(e)}`,requirement:e,message:t,_run(r,n){return r.typed&&r.value<this.requirement&&Wt(this,"value",r,n,{received:r.value instanceof Date?r.value.toJSON():ia(r.value)}),r}}}function Jg(e,t){return{kind:"validation",type:"regex",reference:Jg,async:!1,expects:`${e}`,requirement:e,message:t,_run(r,n){return r.typed&&!this.requirement.test(r.value)&&Wt(this,"format",r,n),r}}}function sf(e,t,r){return typeof e.default=="function"?e.default(t,r):e.default}function au(e,t){return!e._run({typed:!1,value:t},{abortEarly:!0}).issues}function Yg(){return{kind:"schema",type:"any",reference:Yg,expects:"any",async:!1,_run(e){return e.typed=!0,e}}}function pr(e,t){return{kind:"schema",type:"array",reference:pr,expects:"Array",async:!1,item:e,message:t,_run(r,n){var i;const o=r.value;if(Array.isArray(o)){r.typed=!0,r.value=[];for(let s=0;s<o.length;s++){const a=o[s],u=this.item._run({typed:!1,value:a},n);if(u.issues){const f={type:"array",origin:"value",input:o,key:s,value:a};for(const h of u.issues)h.path?h.path.unshift(f):h.path=[f],(i=r.issues)==null||i.push(h);if(r.issues||(r.issues=u.issues),n.abortEarly){r.typed=!1;break}}u.typed||(r.typed=!1),r.value.push(u.value)}}else Wt(this,"type",r,n);return r}}}function Zg(e){return{kind:"schema",type:"bigint",reference:Zg,expects:"bigint",async:!1,message:e,_run(t,r){return typeof t.value=="bigint"?t.typed=!0:Wt(this,"type",t,r),t}}}function bn(e,t){return{kind:"schema",type:"custom",reference:bn,expects:"unknown",async:!1,check:e,message:t,_run(r,n){return this.check(r.value)?r.typed=!0:Wt(this,"type",r,n),r}}}function cu(e,t){return{kind:"schema",type:"instance",reference:cu,expects:e.name,async:!1,class:e,message:t,_run(r,n){return r.value instanceof this.class?r.typed=!0:Wt(this,"type",r,n),r}}}function of(e,...t){const r={kind:"schema",type:"nullable",reference:of,expects:`(${e.expects} | null)`,async:!1,wrapped:e,_run(n,i){return n.value===null&&("default"in this&&(n.value=sf(this,n,i)),n.value===null)?(n.typed=!0,n):this.wrapped._run(n,i)}};return 0 in t&&(r.default=t[0]),r}function Qg(e,...t){const r={kind:"schema",type:"nullish",reference:Qg,expects:`(${e.expects} | null | undefined)`,async:!1,wrapped:e,_run(n,i){return(n.value===null||n.value===void 0)&&("default"in this&&(n.value=sf(this,n,i)),n.value===null||n.value===void 0)?(n.typed=!0,n):this.wrapped._run(n,i)}};return 0 in t&&(r.default=t[0]),r}function yr(e){return{kind:"schema",type:"number",reference:yr,expects:"number",async:!1,message:e,_run(t,r){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:Wt(this,"type",t,r),t}}}function xt(e,t){return{kind:"schema",type:"object",reference:xt,expects:"Object",async:!1,entries:e,message:t,_run(r,n){var i;const o=r.value;if(o&&typeof o=="object"){r.typed=!0,r.value={};for(const s in this.entries){const a=o[s],u=this.entries[s]._run({typed:!1,value:a},n);if(u.issues){const f={type:"object",origin:"value",input:o,key:s,value:a};for(const h of u.issues)h.path?h.path.unshift(f):h.path=[f],(i=r.issues)==null||i.push(h);if(r.issues||(r.issues=u.issues),n.abortEarly){r.typed=!1;break}}u.typed||(r.typed=!1),(u.value!==void 0||s in o)&&(r.value[s]=u.value)}}else Wt(this,"type",r,n);return r}}}function uu(e,...t){const r={kind:"schema",type:"optional",reference:uu,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,_run(n,i){return n.value===void 0&&("default"in this&&(n.value=sf(this,n,i)),n.value===void 0)?(n.typed=!0,n):this.wrapped._run(n,i)}};return 0 in t&&(r.default=t[0]),r}function Ss(e){return{kind:"schema",type:"string",reference:Ss,expects:"string",async:!1,message:e,_run(t,r){return typeof t.value=="string"?t.typed=!0:Wt(this,"type",t,r),t}}}function Hn(e,t){return{kind:"schema",type:"tuple",reference:Hn,expects:"Array",async:!1,items:e,message:t,_run(r,n){var i;const o=r.value;if(Array.isArray(o)){r.typed=!0,r.value=[];for(let s=0;s<this.items.length;s++){const a=o[s],u=this.items[s]._run({typed:!1,value:a},n);if(u.issues){const f={type:"array",origin:"value",input:o,key:s,value:a};for(const h of u.issues)h.path?h.path.unshift(f):h.path=[f],(i=r.issues)==null||i.push(h);if(r.issues||(r.issues=u.issues),n.abortEarly){r.typed=!1;break}}u.typed||(r.typed=!1),r.value.push(u.value)}}else Wt(this,"type",r,n);return r}}}function e1(e){let t;if(e)for(const r of e)t?t.push(...r.issues):t=r.issues;return t}function af(e,t){return{kind:"schema",type:"union",reference:af,expects:G5(e.map(r=>r.expects),"|"),async:!1,options:e,message:t,_run(r,n){let i,o,s;for(const a of this.options){const u=a._run({typed:!1,value:r.value},n);if(u.typed)if(u.issues)o?o.push(u):o=[u];else{i=u;break}else s?s.push(u):s=[u]}if(i)return i;if(o){if(o.length===1)return o[0];Wt(this,"type",r,n,{issues:e1(o)}),r.typed=!0}else{if((s==null?void 0:s.length)===1)return s[0];Wt(this,"type",r,n,{issues:e1(s)})}return r}}}function ft(e,t,r){const n=e._run({typed:!1,value:t},W5(r));if(n.issues)throw new X5(n.issues);return n.value}function Vi(e,t){const r={};for(const n in e.entries)r[n]=uu(e.entries[n]);return{...e,entries:r}}function so(...e){return{...e[0],pipe:e,_run(t,r){for(const n of e)if(n.kind!=="metadata"){if(t.issues&&(n.kind==="schema"||n.kind==="transformation")){t.typed=!1;break}(!t.issues||!r.abortEarly&&!r.abortPipeEarly)&&(t=n._run(t,r))}return t}}}const t1=new Uint8Array(32),r1=oi("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Bt=e=>so(cu(Uint8Array),Xg(e));function sa(e,t){return e.length!==t.length?!1:e.every((r,n)=>ee(r,t[n])===0)}function mn(e){if(!(e instanceof Uint8Array)||e.length<33)return!1;const t=e[0],r=e.slice(1,33);if(ee(t1,r)===0||ee(r,r1)>=0)return!1;if((t===2||t===3)&&e.length===33)return!0;const n=e.slice(33);return ee(t1,n)===0||ee(n,r1)>=0?!1:t===4&&e.length===65}const lu=254;function cf(e){return!e||!("output"in e)||!(e.output instanceof Uint8Array)?!1:e.version!==void 0?(e.version&lu)===e.version:!0}function n1(e){return Array.isArray(e)?e.length!==2?!1:e.every(t=>n1(t)):cf(e)}const J5=Bt(32),Y5=Bt(20),i1=Bt(32),Me=cu(Uint8Array);so(Ss(),Jg(/^([0-9a-f]{2})+$/i));const Z5=so(yr(),nf(),ou(0),su(255)),ci=so(yr(),nf(),ou(0),su(4294967295)),uf=so(Zg(),ou(0n),su(0x7fffffffffffffffn)),s1=e=>xt(Object.entries(e).reduce((t,r)=>({...t,[r[0]]:Qg(r[1])}),{})),o1=new Uint8Array(1);function a1(e){let t=0;for(;e[t]===0;)++t;return t===e.length?o1:(e=e.slice(t),e[0]&128?ht([o1,e]):e)}function c1(e){e[0]===0&&(e=e.slice(1));const t=new Uint8Array(32),r=Math.max(0,32-e.length);return t.set(e,r),t}function Q5(e){const t=ai(e,e.length-1);if(!hf(t))throw new Error("Invalid hashType "+t);const r=$5(e.subarray(0,-1)),n=c1(r.r),i=c1(r.s);return{signature:ht([n,i]),hashType:t}}function eT(e,t){if(ft(xt({signature:Bt(64),hashType:Z5}),{signature:e,hashType:t}),!hf(t))throw new Error("Invalid hashType "+t);const r=new Uint8Array(1);Pr(r,0,t);const n=a1(e.slice(0,32)),i=a1(e.slice(32,64));return ht([C5(n,i),r])}const tT=Object.freeze(Object.defineProperty({__proto__:null,decode:Q5,encode:eT},Symbol.toStringTag,{value:"Module"})),u1=Ge.OP_RESERVED,l1=pr(af([cu(Uint8Array),yr()]));function rT(e){return au(yr(),e)&&(e===Ge.OP_0||e>=Ge.OP_1&&e<=Ge.OP_16||e===Ge.OP_1NEGATE)}function h1(e){return au(Me,e)||rT(e)}function lf(e){return au(so(Yg(),Gg(h1)),e)}function f1(e){return e.length-e.filter(h1).length}function hu(e){if(e.length===0)return Ge.OP_0;if(e.length===1){if(e[0]>=1&&e[0]<=16)return u1+e[0];if(e[0]===129)return Ge.OP_1NEGATE}}function d1(e){return e instanceof Uint8Array}function nT(e){return au(l1,e)}function fu(e){return e instanceof Uint8Array}function gr(e){if(d1(e))return e;ft(l1,e);const t=e.reduce((i,o)=>fu(o)?o.length===1&&hu(o)!==void 0?i+1:i+qg(o.length)+o.length:i+1,0),r=new Uint8Array(t);let n=0;if(e.forEach(i=>{if(fu(i)){const o=hu(i);if(o!==void 0){Pr(r,n,o),n+=1;return}n+=M5(r,i.length,n),r.set(i,n),n+=i.length}else Pr(r,n,i),n+=1}),n!==r.length)throw new Error("Could not decode chunks");return r}function mt(e){if(nT(e))return e;ft(Me,e);const t=[];let r=0;for(;r<e.length;){const n=e[r];if(n>Ge.OP_0&&n<=Ge.OP_PUSHDATA4){const i=F5(e,r);if(i===null||(r+=i.size,r+i.number>e.length))return null;const o=e.slice(r,r+i.number);r+=i.number;const s=hu(o);s!==void 0?t.push(s):t.push(o)}else t.push(n),r+=1}return t}function iT(e){if(d1(e)&&(e=mt(e)),!e)throw new Error("Could not convert invalid chunks to ASM");return e.map(t=>{if(fu(t)){const r=hu(t);if(r===void 0)return Ee(t);t=r}return jg[t]}).join(" ")}function sT(e){return e=mt(e),ft(bn(lf),e),e.map(t=>fu(t)?t:t===Ge.OP_0?new Uint8Array(0):z5(t-u1))}function oT(e){return mn(e)}function hf(e){const t=e&-129;return t>0&&t<4}function ui(e){return!(e instanceof Uint8Array)||!hf(e[e.length-1])?!1:x5(e.slice(0,-1))}const oa=tT;function we(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){const n=r.call(this);return this[t]=n,n},set(n){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,value:n,writable:!0})}})}function Mr(e){let t;return()=>(t!==void 0||(t=e()),t)}const oo=Ge,du=oo.OP_RESERVED;function pu(e,t){if(!e.input&&!e.output&&!(e.pubkeys&&e.m!==void 0)&&!e.signatures)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{});function r(a){return ui(a)||(t.allowIncomplete&&a===oo.OP_0)!==void 0}ft(Vi(xt({network:xt({}),m:yr(),n:yr(),output:Me,pubkeys:pr(bn(mn),"Received invalid pubkey"),signatures:pr(bn(r),"Expected signature to be of type isAcceptableSignature"),input:Me})),e);const n={network:e.network||wn};let i=[],o=!1;function s(a){o||(o=!0,i=mt(a),n.m=i[0]-du,n.n=i[i.length-2]-du,n.pubkeys=i.slice(1,-2))}if(we(n,"output",()=>{if(e.m&&n.n&&e.pubkeys)return gr([].concat(du+e.m,e.pubkeys,du+n.n,oo.OP_CHECKMULTISIG))}),we(n,"m",()=>{if(n.output)return s(n.output),n.m}),we(n,"n",()=>{if(n.pubkeys)return n.pubkeys.length}),we(n,"pubkeys",()=>{if(e.output)return s(e.output),n.pubkeys}),we(n,"signatures",()=>{if(e.input)return mt(e.input).slice(1)}),we(n,"input",()=>{if(e.signatures)return gr([oo.OP_0].concat(e.signatures))}),we(n,"witness",()=>{if(n.input)return[]}),we(n,"name",()=>{if(!(!n.m||!n.n))return`p2ms(${n.m} of ${n.n})`}),t.validate){if(e.output){if(s(e.output),ft(yr(),i[0],{message:"Output is invalid"}),ft(yr(),i[i.length-2],{message:"Output is invalid"}),i[i.length-1]!==oo.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(n.m<=0||n.n>16||n.m>n.n||n.n!==i.length-3)throw new TypeError("Output is invalid");if(!n.pubkeys.every(a=>mn(a)))throw new TypeError("Output is invalid");if(e.m!==void 0&&e.m!==n.m)throw new TypeError("m mismatch");if(e.n!==void 0&&e.n!==n.n)throw new TypeError("n mismatch");if(e.pubkeys&&!sa(e.pubkeys,n.pubkeys))throw new TypeError("Pubkeys mismatch")}if(e.pubkeys){if(e.n!==void 0&&e.n!==e.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(n.n=e.pubkeys.length,n.n<n.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<n.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>n.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==oo.OP_0)throw new TypeError("Input is invalid");if(n.signatures.length===0||!n.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!sa(e.signatures,n.signatures))throw new TypeError("Signature mismatch");if(e.m!==void 0&&e.m!==e.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(n,e)}const p1=Ge;function y1(e,t){if(!e.input&&!e.output&&!e.pubkey&&!e.input&&!e.signature)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ft(Vi(xt({network:xt({}),output:Me,pubkey:bn(mn,"invalid pubkey"),signature:bn(ui,"Expected signature to be of type isCanonicalScriptSignature"),input:Me})),e);const r=Mr(()=>mt(e.input)),n={name:"p2pk",network:e.network||wn};if(we(n,"output",()=>{if(e.pubkey)return gr([e.pubkey,p1.OP_CHECKSIG])}),we(n,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),we(n,"signature",()=>{if(e.input)return r()[0]}),we(n,"input",()=>{if(e.signature)return gr([e.signature])}),we(n,"witness",()=>{if(n.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==p1.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!mn(n.pubkey))throw new TypeError("Output pubkey is invalid");if(e.pubkey&&ee(e.pubkey,n.pubkey)!==0)throw new TypeError("Pubkey mismatch")}if(e.signature&&e.input&&ee(e.input,n.input)!==0)throw new TypeError("Signature mismatch");if(e.input){if(r().length!==1)throw new TypeError("Input is invalid");if(!ui(n.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(n,e)}function aT(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function g1(e,...t){if(!aT(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function w1(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function cT(e,t){g1(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ff=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Ln=(e,t)=>e<<32-t|e>>>t,yu=(e,t)=>e<<t|e>>>32-t>>>0;new Uint8Array(new Uint32Array([287454020]).buffer)[0];function uT(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function b1(e){return typeof e=="string"&&(e=uT(e)),g1(e),e}class lT{clone(){return this._cloneInto()}}function m1(e){const t=n=>e().update(b1(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function hT(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),a=Number(r&o),u=n?4:0,f=n?0:4;e.setUint32(t+u,s,n),e.setUint32(t+f,a,n)}const fT=(e,t,r)=>e&t^~e&r,dT=(e,t,r)=>e&t^e&r^t&r;let v1=class extends lT{constructor(e,t,r,n){super(),this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=ff(this.buffer)}update(e){w1(this);const{view:t,buffer:r,blockLen:n}=this;e=b1(e);const i=e.length;for(let o=0;o<i;){const s=Math.min(n-this.pos,i-o);if(s===n){const a=ff(e);for(;n<=i-o;o+=n)this.process(a,o);continue}r.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===n&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){w1(this),cT(e,this),this.finished=!0;const{buffer:t,view:r,blockLen:n,isLE:i}=this;let{pos:o}=this;t[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>n-o&&(this.process(r,0),o=0);for(let h=o;h<n;h++)t[h]=0;hT(r,n-8,BigInt(this.length*8),i),this.process(r,0);const s=ff(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=a/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<u;h++)s.setUint32(4*h,f[h],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:r,length:n,finished:i,destroyed:o,pos:s}=this;return e.length=n,e.pos=s,e.finished=i,e.destroyed=o,n%t&&e.buffer.set(r),e}};const pT=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),E1=new Uint8Array(new Array(16).fill(0).map((e,t)=>t)),yT=E1.map(e=>(9*e+5)%16);let df=[E1],pf=[yT];for(let e=0;e<4;e++)for(let t of[df,pf])t.push(t[e].map(r=>pT[r]));const A1=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>new Uint8Array(e)),gT=df.map((e,t)=>e.map(r=>A1[t][r])),wT=pf.map((e,t)=>e.map(r=>A1[t][r])),bT=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),mT=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function S1(e,t,r,n){return e===0?t^r^n:e===1?t&r|~t&n:e===2?(t|~r)^n:e===3?t&n|r&~n:t^(r|~n)}const gu=new Uint32Array(16);class vT extends v1{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:r,h2:n,h3:i,h4:o}=this;return[t,r,n,i,o]}set(t,r,n,i,o){this.h0=t|0,this.h1=r|0,this.h2=n|0,this.h3=i|0,this.h4=o|0}process(t,r){for(let v=0;v<16;v++,r+=4)gu[v]=t.getUint32(r,!0);let n=this.h0|0,i=n,o=this.h1|0,s=o,a=this.h2|0,u=a,f=this.h3|0,h=f,d=this.h4|0,g=d;for(let v=0;v<5;v++){const E=4-v,T=bT[v],x=mT[v],N=df[v],I=pf[v],k=gT[v],R=wT[v];for(let W=0;W<16;W++){const V=yu(n+S1(v,o,a,f)+gu[N[W]]+T,k[W])+d|0;n=d,d=f,f=yu(a,10)|0,a=o,o=V}for(let W=0;W<16;W++){const V=yu(i+S1(E,s,u,h)+gu[I[W]]+x,R[W])+g|0;i=g,g=h,h=yu(u,10)|0,u=s,s=V}}this.set(this.h1+a+h|0,this.h2+f+g|0,this.h3+d+i|0,this.h4+n+s|0,this.h0+o+u|0)}roundClean(){gu.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}const ET=m1(()=>new vT),AT=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),zi=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Wi=new Uint32Array(64);let ST=class extends v1{constructor(){super(64,32,8,!1),this.A=zi[0]|0,this.B=zi[1]|0,this.C=zi[2]|0,this.D=zi[3]|0,this.E=zi[4]|0,this.F=zi[5]|0,this.G=zi[6]|0,this.H=zi[7]|0}get(){const{A:e,B:t,C:r,D:n,E:i,F:o,G:s,H:a}=this;return[e,t,r,n,i,o,s,a]}set(e,t,r,n,i,o,s,a){this.A=e|0,this.B=t|0,this.C=r|0,this.D=n|0,this.E=i|0,this.F=o|0,this.G=s|0,this.H=a|0}process(e,t){for(let h=0;h<16;h++,t+=4)Wi[h]=e.getUint32(t,!1);for(let h=16;h<64;h++){const d=Wi[h-15],g=Wi[h-2],v=Ln(d,7)^Ln(d,18)^d>>>3,E=Ln(g,17)^Ln(g,19)^g>>>10;Wi[h]=E+Wi[h-7]+v+Wi[h-16]|0}let{A:r,B:n,C:i,D:o,E:s,F:a,G:u,H:f}=this;for(let h=0;h<64;h++){const d=Ln(s,6)^Ln(s,11)^Ln(s,25),g=f+d+fT(s,a,u)+AT[h]+Wi[h]|0,v=(Ln(r,2)^Ln(r,13)^Ln(r,22))+dT(r,n,i)|0;f=u,u=a,a=s,s=o+g|0,o=i,i=n,n=r,r=g+v|0}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(r,n,i,o,s,a,u,f)}roundClean(){Wi.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const rr=m1(()=>new ST);function li(e){return ET(rr(e))}function Ts(e){return rr(rr(e))}const TT={"BIP0340/challenge":Uint8Array.from([123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124,123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124]),"BIP0340/aux":Uint8Array.from([241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144,241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144]),"BIP0340/nonce":Uint8Array.from([7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47,7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47]),TapLeaf:Uint8Array.from([174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238,174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238]),TapBranch:Uint8Array.from([25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21,25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21]),TapSighash:Uint8Array.from([244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49,244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49]),TapTweak:Uint8Array.from([232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233,232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233]),"KeyAgg list":Uint8Array.from([72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240,72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240]),"KeyAgg coefficient":Uint8Array.from([191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129,191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129])};function wu(e,t){return rr(ht([TT[e],t]))}function _T(e){if(e.length>=255)throw new TypeError("Alphabet too long");const t=new Uint8Array(256);for(let f=0;f<t.length;f++)t[f]=255;for(let f=0;f<e.length;f++){const h=e.charAt(f),d=h.charCodeAt(0);if(t[d]!==255)throw new TypeError(h+" is ambiguous");t[d]=f}const r=e.length,n=e.charAt(0),i=Math.log(r)/Math.log(256),o=Math.log(256)/Math.log(r);function s(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";let h=0,d=0,g=0;const v=f.length;for(;g!==v&&f[g]===0;)g++,h++;const E=(v-g)*o+1>>>0,T=new Uint8Array(E);for(;g!==v;){let I=f[g],k=0;for(let R=E-1;(I!==0||k<d)&&R!==-1;R--,k++)I+=256*T[R]>>>0,T[R]=I%r>>>0,I=I/r>>>0;if(I!==0)throw new Error("Non-zero carry");d=k,g++}let x=E-d;for(;x!==E&&T[x]===0;)x++;let N=n.repeat(h);for(;x<E;++x)N+=e.charAt(T[x]);return N}function a(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;let h=0,d=0,g=0;for(;f[h]===n;)d++,h++;const v=(f.length-h)*i+1>>>0,E=new Uint8Array(v);for(;f[h];){let I=t[f.charCodeAt(h)];if(I===255)return;let k=0;for(let R=v-1;(I!==0||k<g)&&R!==-1;R--,k++)I+=r*E[R]>>>0,E[R]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");g=k,h++}let T=v-g;for(;T!==v&&E[T]===0;)T++;const x=new Uint8Array(d+(v-T));let N=d;for(;T!==v;)x[N++]=E[T++];return x}function u(f){const h=a(f);if(h)return h;throw new Error("Non-base"+r+" character")}return{encode:s,decodeUnsafe:a,decode:u}}var kT="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";const yf=_T(kT);function PT(e){function t(o){var s=Uint8Array.from(o),a=e(s),u=s.length+4,f=new Uint8Array(u);return f.set(s,0),f.set(a.subarray(0,4),s.length),yf.encode(f)}function r(o){var s=o.slice(0,-4),a=o.slice(-4),u=e(s);if(!(a[0]^u[0]|a[1]^u[1]|a[2]^u[2]|a[3]^u[3]))return s}function n(o){var s=yf.decodeUnsafe(o);if(s!=null)return r(s)}function i(o){var s=yf.decode(o),a=r(s);if(a==null)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}}function OT(e){return rr(rr(e))}const aa=PT(OT),qi=Ge;function ca(e,t){if(!e.address&&!e.hash&&!e.output&&!e.pubkey&&!e.input)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ft(Vi(xt({network:xt({}),address:Ss(),hash:Y5,output:Bt(25),pubkey:bn(mn),signature:bn(ui),input:Me})),e);const r=Mr(()=>{const s=aa.decode(e.address),a=ai(s,0),u=s.slice(1);return{version:a,hash:u}}),n=Mr(()=>mt(e.input)),i=e.network||wn,o={name:"p2pkh",network:i};if(we(o,"address",()=>{if(!o.hash)return;const s=new Uint8Array(21);return Pr(s,0,i.pubKeyHash),s.set(o.hash,1),aa.encode(s)}),we(o,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return r().hash;if(e.pubkey||o.pubkey)return li(e.pubkey||o.pubkey)}),we(o,"output",()=>{if(o.hash)return gr([qi.OP_DUP,qi.OP_HASH160,o.hash,qi.OP_EQUALVERIFY,qi.OP_CHECKSIG])}),we(o,"pubkey",()=>{if(e.input)return n()[1]}),we(o,"signature",()=>{if(e.input)return n()[0]}),we(o,"input",()=>{if(e.pubkey&&e.signature)return gr([e.signature,e.pubkey])}),we(o,"witness",()=>{if(o.input)return[]}),t.validate){let s=Uint8Array.from([]);if(e.address){if(r().version!==i.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(r().hash.length!==20)throw new TypeError("Invalid address");s=r().hash}if(e.hash){if(s.length>0&&ee(s,e.hash)!==0)throw new TypeError("Hash mismatch");s=e.hash}if(e.output){if(e.output.length!==25||e.output[0]!==qi.OP_DUP||e.output[1]!==qi.OP_HASH160||e.output[2]!==20||e.output[23]!==qi.OP_EQUALVERIFY||e.output[24]!==qi.OP_CHECKSIG)throw new TypeError("Output is invalid");const a=e.output.slice(3,23);if(s.length>0&&ee(s,a)!==0)throw new TypeError("Hash mismatch");s=a}if(e.pubkey){const a=li(e.pubkey);if(s.length>0&&ee(s,a)!==0)throw new TypeError("Hash mismatch");s=a}if(e.input){const a=n();if(a.length!==2)throw new TypeError("Input is invalid");if(!ui(a[0]))throw new TypeError("Input has invalid signature");if(!mn(a[1]))throw new TypeError("Input has invalid pubkey");if(e.signature&&ee(e.signature,a[0])!==0)throw new TypeError("Signature mismatch");if(e.pubkey&&ee(e.pubkey,a[1])!==0)throw new TypeError("Pubkey mismatch");const u=li(a[1]);if(s.length>0&&ee(s,u)!==0)throw new TypeError("Hash mismatch")}}return Object.assign(o,e)}const ua=Ge;function ao(e,t){if(!e.address&&!e.hash&&!e.output&&!e.redeem&&!e.input)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ft(Vi(xt({network:xt({}),address:Ss(),hash:Bt(20),output:Bt(23),redeem:Vi(xt({network:xt({}),output:Me,input:Me,witness:pr(Me)})),input:Me,witness:pr(Me)})),e);let r=e.network;r||(r=e.redeem&&e.redeem.network||wn);const n={network:r},i=Mr(()=>{const a=aa.decode(e.address),u=ai(a,0),f=a.slice(1);return{version:u,hash:f}}),o=Mr(()=>mt(e.input)),s=Mr(()=>{const a=o(),u=a[a.length-1];return{network:r,output:u===ua.OP_FALSE?Uint8Array.from([]):u,input:gr(a.slice(0,-1)),witness:e.witness||[]}});if(we(n,"address",()=>{if(!n.hash)return;const a=new Uint8Array(21);return Pr(a,0,n.network.scriptHash),a.set(n.hash,1),aa.encode(a)}),we(n,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return i().hash;if(n.redeem&&n.redeem.output)return li(n.redeem.output)}),we(n,"output",()=>{if(n.hash)return gr([ua.OP_HASH160,n.hash,ua.OP_EQUAL])}),we(n,"redeem",()=>{if(e.input)return s()}),we(n,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return gr([].concat(mt(e.redeem.input),e.redeem.output))}),we(n,"witness",()=>{if(n.redeem&&n.redeem.witness)return n.redeem.witness;if(n.input)return[]}),we(n,"name",()=>{const a=["p2sh"];return n.redeem!==void 0&&n.redeem.name!==void 0&&a.push(n.redeem.name),a.join("-")}),t.validate){let a=Uint8Array.from([]);if(e.address){if(i().version!==r.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(i().hash.length!==20)throw new TypeError("Invalid address");a=i().hash}if(e.hash){if(a.length>0&&ee(a,e.hash)!==0)throw new TypeError("Hash mismatch");a=e.hash}if(e.output){if(e.output.length!==23||e.output[0]!==ua.OP_HASH160||e.output[1]!==20||e.output[22]!==ua.OP_EQUAL)throw new TypeError("Output is invalid");const f=e.output.slice(2,22);if(a.length>0&&ee(a,f)!==0)throw new TypeError("Hash mismatch");a=f}const u=f=>{if(f.output){const h=mt(f.output);if(!h||h.length<1)throw new TypeError("Redeem.output too short");if(f.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(f1(h)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const d=li(f.output);if(a.length>0&&ee(a,d)!==0)throw new TypeError("Hash mismatch");a=d}if(f.input){const h=f.input.length>0,d=f.witness&&f.witness.length>0;if(!h&&!d)throw new TypeError("Empty input");if(h&&d)throw new TypeError("Input and witness provided");if(h){const g=mt(f.input);if(!lf(g))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const f=o();if(!f||f.length<1)throw new TypeError("Input too short");if(!(s().output instanceof Uint8Array))throw new TypeError("Input is invalid");u(s())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==r)throw new TypeError("Network mismatch");if(e.input){const f=s();if(e.redeem.output&&ee(e.redeem.output,f.output)!==0)throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&ee(e.redeem.input,f.input)!==0)throw new TypeError("Redeem.input mismatch")}u(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!sa(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,e)}var Te=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function IT(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function xT(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var r=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}),r}var la={};Object.defineProperty(la,"__esModule",{value:!0});var ha=la.bech32m=Or=la.bech32=void 0;const bu="qpzry9x8gf2tvdw0s3jn54khce6mua7l",T1={};for(let e=0;e<bu.length;e++){const t=bu.charAt(e);T1[t]=e}function co(e){const t=e>>25;return(e&33554431)<<5^-(t>>0&1)&996825010^-(t>>1&1)&642813549^-(t>>2&1)&513874426^-(t>>3&1)&1027748829^-(t>>4&1)&705979059}function _1(e){let t=1;for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+e+")";t=co(t)^n>>5}t=co(t);for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);t=co(t)^n&31}return t}function gf(e,t,r,n){let i=0,o=0;const s=(1<<r)-1,a=[];for(let u=0;u<e.length;++u)for(i=i<<t|e[u],o+=t;o>=r;)o-=r,a.push(i>>o&s);if(n)o>0&&a.push(i<<r-o&s);else{if(o>=t)return"Excess padding";if(i<<r-o&s)return"Non-zero padding"}return a}function $T(e){return gf(e,8,5,!0)}function CT(e){const t=gf(e,5,8,!1);if(Array.isArray(t))return t}function NT(e){const t=gf(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function k1(e){let t;e==="bech32"?t=1:t=734539939;function r(s,a,u){if(u=u||90,s.length+7+a.length>u)throw new TypeError("Exceeds length limit");s=s.toLowerCase();let f=_1(s);if(typeof f=="string")throw new Error(f);let h=s+"1";for(let d=0;d<a.length;++d){const g=a[d];if(g>>5)throw new Error("Non 5-bit word");f=co(f)^g,h+=bu.charAt(g)}for(let d=0;d<6;++d)f=co(f);f^=t;for(let d=0;d<6;++d){const g=f>>(5-d)*5&31;h+=bu.charAt(g)}return h}function n(s,a){if(a=a||90,s.length<8)return s+" too short";if(s.length>a)return"Exceeds length limit";const u=s.toLowerCase(),f=s.toUpperCase();if(s!==u&&s!==f)return"Mixed-case string "+s;s=u;const h=s.lastIndexOf("1");if(h===-1)return"No separator character for "+s;if(h===0)return"Missing prefix for "+s;const d=s.slice(0,h),g=s.slice(h+1);if(g.length<6)return"Data too short";let v=_1(d);if(typeof v=="string")return v;const E=[];for(let T=0;T<g.length;++T){const x=g.charAt(T),N=T1[x];if(N===void 0)return"Unknown character "+x;v=co(v)^N,!(T+6>=g.length)&&E.push(N)}return v!==t?"Invalid checksum for "+s:{prefix:d,words:E}}function i(s,a){const u=n(s,a);if(typeof u=="object")return u}function o(s,a){const u=n(s,a);if(typeof u=="object")return u;throw new Error(u)}return{decodeUnsafe:i,decode:o,encode:r,toWords:$T,fromWordsUnsafe:CT,fromWords:NT}}var Or=la.bech32=k1("bech32");ha=la.bech32m=k1("bech32m");const P1=Ge,BT=new Uint8Array(0);function fa(e,t){if(!e.address&&!e.hash&&!e.output&&!e.pubkey&&!e.witness)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ft(Vi(xt({address:Ss(),hash:Bt(20),input:Bt(0),network:xt({}),output:Bt(22),pubkey:bn(mn,"Not a valid pubkey"),signature:bn(ui),witness:pr(Me)})),e);const r=Mr(()=>{const o=Or.decode(e.address),s=o.words.shift(),a=Or.fromWords(o.words);return{version:s,prefix:o.prefix,data:Uint8Array.from(a)}}),n=e.network||wn,i={name:"p2wpkh",network:n};if(we(i,"address",()=>{if(!i.hash)return;const o=Or.toWords(i.hash);return o.unshift(0),Or.encode(n.bech32,o)}),we(i,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return r().data;if(e.pubkey||i.pubkey)return li(e.pubkey||i.pubkey)}),we(i,"output",()=>{if(i.hash)return gr([P1.OP_0,i.hash])}),we(i,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),we(i,"signature",()=>{if(e.witness)return e.witness[0]}),we(i,"input",()=>{if(i.witness)return BT}),we(i,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let o=Uint8Array.from([]);if(e.address){if(n&&n.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==0)throw new TypeError("Invalid address version");if(r().data.length!==20)throw new TypeError("Invalid address data");o=r().data}if(e.hash){if(o.length>0&&ee(o,e.hash)!==0)throw new TypeError("Hash mismatch");o=e.hash}if(e.output){if(e.output.length!==22||e.output[0]!==P1.OP_0||e.output[1]!==20)throw new TypeError("Output is invalid");if(o.length>0&&ee(o,e.output.slice(2))!==0)throw new TypeError("Hash mismatch");o=e.output.slice(2)}if(e.pubkey){const s=li(e.pubkey);if(o.length>0&&ee(o,s)!==0)throw new TypeError("Hash mismatch");if(o=s,!mn(e.pubkey)||e.pubkey.length!==33)throw new TypeError("Invalid pubkey for p2wpkh")}if(e.witness){if(e.witness.length!==2)throw new TypeError("Witness is invalid");if(!ui(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!mn(e.witness[1])||e.witness[1].length!==33)throw new TypeError("Witness has invalid pubkey");if(e.signature&&ee(e.signature,e.witness[0])!==0)throw new TypeError("Signature mismatch");if(e.pubkey&&ee(e.pubkey,e.witness[1])!==0)throw new TypeError("Pubkey mismatch");const s=li(e.witness[1]);if(o.length>0&&ee(o,s)!==0)throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}const O1=Ge,wf=new Uint8Array(0);function mu(e){return!!(e instanceof Uint8Array&&e.length===65&&e[0]===4&&mn(e))}function da(e,t){if(!e.address&&!e.hash&&!e.output&&!e.redeem&&!e.witness)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ft(s1({network:xt({}),address:Ss(),hash:J5,output:Bt(34),redeem:s1({input:Me,network:xt({}),output:Me,witness:pr(Me)}),input:Bt(0),witness:pr(Me)}),e);const r=Mr(()=>{const s=Or.decode(e.address),a=s.words.shift(),u=Or.fromWords(s.words);return{version:a,prefix:s.prefix,data:Uint8Array.from(u)}}),n=Mr(()=>mt(e.redeem.input));let i=e.network;i||(i=e.redeem&&e.redeem.network||wn);const o={network:i};if(we(o,"address",()=>{if(!o.hash)return;const s=Or.toWords(o.hash);return s.unshift(0),Or.encode(i.bech32,s)}),we(o,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return r().data;if(o.redeem&&o.redeem.output)return rr(o.redeem.output)}),we(o,"output",()=>{if(o.hash)return gr([O1.OP_0,o.hash])}),we(o,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:wf,witness:e.witness.slice(0,-1)}}),we(o,"input",()=>{if(o.witness)return wf}),we(o,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const s=sT(n());return o.redeem=Object.assign({witness:s},e.redeem),o.redeem.input=wf,[].concat(s,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),we(o,"name",()=>{const s=["p2wsh"];return o.redeem!==void 0&&o.redeem.name!==void 0&&s.push(o.redeem.name),s.join("-")}),t.validate){let s=Uint8Array.from([]);if(e.address){if(r().prefix!==i.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==0)throw new TypeError("Invalid address version");if(r().data.length!==32)throw new TypeError("Invalid address data");s=r().data}if(e.hash){if(s.length>0&&ee(s,e.hash)!==0)throw new TypeError("Hash mismatch");s=e.hash}if(e.output){if(e.output.length!==34||e.output[0]!==O1.OP_0||e.output[1]!==32)throw new TypeError("Output is invalid");const a=e.output.slice(2);if(s.length>0&&ee(s,a)!==0)throw new TypeError("Hash mismatch");s=a}if(e.redeem){if(e.redeem.network&&e.redeem.network!==i)throw new TypeError("Network mismatch");if(e.redeem.input&&e.redeem.input.length>0&&e.redeem.witness&&e.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(e.redeem.output){const a=mt(e.redeem.output);if(!a||a.length<1)throw new TypeError("Redeem.output is invalid");if(e.redeem.output.byteLength>3600)throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");if(f1(a)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const u=rr(e.redeem.output);if(s.length>0&&ee(s,u)!==0)throw new TypeError("Hash mismatch");s=u}if(e.redeem.input&&!lf(n()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!sa(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&n().some(mu)||e.redeem.output&&(mt(e.redeem.output)||[]).some(mu))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(e.witness&&e.witness.length>0){const a=e.witness[e.witness.length-1];if(e.redeem&&e.redeem.output&&ee(e.redeem.output,a)!==0)throw new TypeError("Witness and redeem.output mismatch");if(e.witness.some(mu)||(mt(a)||[]).some(mu))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(o,e)}const pa={};function UT(e){e?e!==pa.eccLib&&(RT(e),pa.eccLib=e):pa.eccLib=e}function bf(){if(!pa.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return pa.eccLib}const hi=e=>oi(e);function RT(e){Fr(typeof e.isXOnlyPoint=="function"),Fr(e.isXOnlyPoint(hi("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Fr(e.isXOnlyPoint(hi("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),Fr(e.isXOnlyPoint(hi("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),Fr(e.isXOnlyPoint(hi("0000000000000000000000000000000000000000000000000000000000000001"))),Fr(!e.isXOnlyPoint(hi("0000000000000000000000000000000000000000000000000000000000000000"))),Fr(!e.isXOnlyPoint(hi("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),Fr(typeof e.xOnlyPointAddTweak=="function"),HT.forEach(t=>{const r=e.xOnlyPointAddTweak(hi(t.pubkey),hi(t.tweak));t.result===null?Fr(r===null):(Fr(r!==null),Fr(r.parity===t.parity),Fr(ee(r.xOnlyPubkey,hi(t.result))===0))})}function Fr(e){if(!e)throw new Error("ecc library invalid")}const HT=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}],I1="0123456789abcdefABCDEF";I1.split("").map(e=>e.codePointAt(0)),Array(256).fill(!0).map((e,t)=>{const r=String.fromCodePoint(t),n=I1.indexOf(r);return n<0?void 0:n<16?n:n-6}),new TextEncoder,new TextDecoder;function LT(e,t,r,n){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>65535)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 65535. Received ${r}`);n==="LE"?(e[t]=r&255,e[t+1]=r>>8&255):(e[t]=r>>8&255,e[t+1]=r&255)}function KT(e,t,r,n){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>4294967295)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${4294967295}. Received ${r}`);n==="LE"?(e[t]=r&255,e[t+1]=r>>8&255,e[t+2]=r>>16&255,e[t+3]=r>>24&255):(e[t]=r>>24&255,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=r&255)}function jT(e,t,r,n){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>0xffffffffffffffffn)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${0xffffffffffffffffn}. Received ${r}`);n==="LE"?(e[t]=Number(r&0xffn),e[t+1]=Number(r>>8n&0xffn),e[t+2]=Number(r>>16n&0xffn),e[t+3]=Number(r>>24n&0xffn),e[t+4]=Number(r>>32n&0xffn),e[t+5]=Number(r>>40n&0xffn),e[t+6]=Number(r>>48n&0xffn),e[t+7]=Number(r>>56n&0xffn)):(e[t]=Number(r>>56n&0xffn),e[t+1]=Number(r>>48n&0xffn),e[t+2]=Number(r>>40n&0xffn),e[t+3]=Number(r>>32n&0xffn),e[t+4]=Number(r>>24n&0xffn),e[t+5]=Number(r>>16n&0xffn),e[t+6]=Number(r>>8n&0xffn),e[t+7]=Number(r&0xffn))}function DT(e,t,r){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),r==="LE"){let n=0;return n=(n<<8)+e[t+1],n=(n<<8)+e[t],n}else{let n=0;return n=(n<<8)+e[t],n=(n<<8)+e[t+1],n}}function MT(e,t,r){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),r==="LE"){let n=0;return n=(n<<8)+e[t+3]>>>0,n=(n<<8)+e[t+2]>>>0,n=(n<<8)+e[t+1]>>>0,n=(n<<8)+e[t]>>>0,n}else{let n=0;return n=(n<<8)+e[t]>>>0,n=(n<<8)+e[t+1]>>>0,n=(n<<8)+e[t+2]>>>0,n=(n<<8)+e[t+3]>>>0,n}}function FT(e,t,r){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),r==="LE"){let n=0n;return n=(n<<8n)+BigInt(e[t+7]),n=(n<<8n)+BigInt(e[t+6]),n=(n<<8n)+BigInt(e[t+5]),n=(n<<8n)+BigInt(e[t+4]),n=(n<<8n)+BigInt(e[t+3]),n=(n<<8n)+BigInt(e[t+2]),n=(n<<8n)+BigInt(e[t+1]),n=(n<<8n)+BigInt(e[t]),n}else{let n=0n;return n=(n<<8n)+BigInt(e[t]),n=(n<<8n)+BigInt(e[t+1]),n=(n<<8n)+BigInt(e[t+2]),n=(n<<8n)+BigInt(e[t+3]),n=(n<<8n)+BigInt(e[t+4]),n=(n<<8n)+BigInt(e[t+5]),n=(n<<8n)+BigInt(e[t+6]),n=(n<<8n)+BigInt(e[t+7]),n}}const VT=e=>{if(e<0||e>0xffffffffffffffffn)throw new RangeError("value out of range")};function zT(e){if(e<0||e>Number.MAX_SAFE_INTEGER||e%1!==0)throw new RangeError("value out of range")}function x1(e){typeof e=="number"?zT(e):VT(e)}function Gi(e,t,r){x1(e),r===void 0&&(r=0),t===void 0&&(t=new Uint8Array(Vr(e)));let n=0;return e<253?(t.set([Number(e)],r),n=1):e<=65535?(t.set([253],r),LT(t,r+1,Number(e),"LE"),n=3):e<=4294967295?(t.set([254],r),KT(t,r+1,Number(e),"LE"),n=5):(t.set([255],r),jT(t,r+1,BigInt(e),"LE"),n=9),{buffer:t,bytes:n}}function uo(e,t){t===void 0&&(t=0);const r=e.at(t);if(r===void 0)throw new Error("buffer too small");if(r<253)return{numberValue:r,bigintValue:BigInt(r),bytes:1};if(r===253){const n=DT(e,t+1,"LE");return{numberValue:n,bigintValue:BigInt(n),bytes:3}}else if(r===254){const n=MT(e,t+1,"LE");return{numberValue:n,bigintValue:BigInt(n),bytes:5}}else{const n=FT(e,t+1,"LE");return{numberValue:n<=Number.MAX_SAFE_INTEGER?Number(n):null,bigintValue:n,bytes:9}}}function Vr(e){return x1(e),e<253?1:e<=65535?3:e<=4294967295?5:9}const WT=9007199254740991;function qT(e,t){if(typeof e!="number"&&typeof e!="bigint")throw new Error("cannot write a non-number as a number");if(e<0&&e<BigInt(0))throw new Error("specified a negative value for writing an unsigned value");if(e>t&&e>BigInt(t))throw new Error("RangeError: value out of range");if(Math.floor(Number(e))!==Number(e))throw new Error("value has a fractional component")}function mf(e){if(e.length<1)return e;let t=e.length-1,r=0;for(let n=0;n<e.length/2;n++)r=e[n],e[n]=e[t],e[t]=r,t--;return e}function $1(e){const t=new Uint8Array(e.length);return t.set(e),t}class qt{constructor(t,r=0){ge(this,"buffer"),ge(this,"offset"),this.buffer=t,this.offset=r,ft(Hn([Me,ci]),[t,r])}static withCapacity(t){return new qt(new Uint8Array(t))}writeUInt8(t){this.offset=Pr(this.buffer,this.offset,t)}writeInt32(t){this.offset=Vg(this.buffer,this.offset,t,"LE")}writeInt64(t){this.offset=zg(this.buffer,this.offset,BigInt(t),"LE")}writeUInt32(t){this.offset=na(this.buffer,this.offset,t,"LE")}writeUInt64(t){this.offset=K5(this.buffer,this.offset,BigInt(t),"LE")}writeVarInt(t){const{bytes:r}=Gi(t,this.buffer,this.offset);this.offset+=r}writeSlice(t){if(this.buffer.length<this.offset+t.length)throw new Error("Cannot write slice out of bounds");this.buffer.set(t,this.offset),this.offset+=t.length}writeVarSlice(t){this.writeVarInt(t.length),this.writeSlice(t)}writeVector(t){this.writeVarInt(t.length),t.forEach(r=>this.writeVarSlice(r))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}}class GT{constructor(t,r=0){ge(this,"buffer"),ge(this,"offset"),this.buffer=t,this.offset=r,ft(Hn([Me,ci]),[t,r])}readUInt8(){const t=ai(this.buffer,this.offset);return this.offset++,t}readInt32(){const t=D5(this.buffer,this.offset,"LE");return this.offset+=4,t}readUInt32(){const t=io(this.buffer,this.offset,"LE");return this.offset+=4,t}readInt64(){const t=Wg(this.buffer,this.offset,"LE");return this.offset+=8,t}readVarInt(){const{bigintValue:t,bytes:r}=uo(this.buffer,this.offset);return this.offset+=r,t}readSlice(t){qT(t,WT);const r=Number(t);if(this.buffer.length<this.offset+r)throw new Error("Cannot read slice out of bounds");const n=this.buffer.slice(this.offset,this.offset+r);return this.offset+=r,n}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const t=this.readVarInt(),r=[];for(let n=0;n<t;n++)r.push(this.readVarSlice());return r}}const C1=192,XT=128,JT=e=>"left"in e&&"right"in e;function vf(e,t){if(e.length<33)throw new TypeError(`The control-block length is too small. Got ${e.length}, expected min 33.`);const r=(e.length-33)/32;let n=t;for(let i=0;i<r;i++){const o=e.slice(33+32*i,65+32*i);ee(n,o)<0?n=Af(n,o):n=Af(o,n)}return n}function Ef(e){if(cf(e))return{hash:fi(e)};const t=[Ef(e[0]),Ef(e[1])];t.sort((i,o)=>ee(i.hash,o.hash));const[r,n]=t;return{hash:Af(r.hash,n.hash),left:r,right:n}}function vu(e,t){if(JT(e)){const r=vu(e.left,t);if(r!==void 0)return[...r,e.right.hash];const n=vu(e.right,t);if(n!==void 0)return[...n,e.left.hash]}else if(ee(e.hash,t)===0)return[]}function fi(e){const t=e.version||C1;return wu("TapLeaf",ht([Uint8Array.from([t]),ZT(e.output)]))}function YT(e,t){return wu("TapTweak",ht(t?[e,t]:[e]))}function Eu(e,t){if(!(e instanceof Uint8Array)||e.length!==32||t&&t.length!==32)return null;const r=YT(e,t),n=bf().xOnlyPointAddTweak(e,r);return!n||n.xOnlyPubkey===null?null:{parity:n.parity,x:Uint8Array.from(n.xOnlyPubkey)}}function Af(e,t){return wu("TapBranch",ht([e,t]))}function ZT(e){const t=Vr(e.length),r=new Uint8Array(t);return Gi(e.length,r),ht([r,e])}const N1=Ge,B1=1,QT=80;function ya(e,t){if(!e.address&&!e.output&&!e.pubkey&&!e.internalPubkey&&!(e.witness&&e.witness.length>1))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ft(Vi(xt({address:Ss(),input:Bt(0),network:xt({}),output:Bt(34),internalPubkey:Bt(32),hash:Bt(32),pubkey:Bt(32),signature:af([Bt(64),Bt(65)]),witness:pr(Me),scriptTree:bn(n1,"Taptree is not of type isTaptree"),redeem:Vi(xt({output:Me,redeemVersion:yr(),witness:pr(Me)})),redeemVersion:yr()})),e);const r=Mr(()=>D1(e.address)),n=Mr(()=>{if(!(!e.witness||!e.witness.length))return e.witness.length>=2&&e.witness[e.witness.length-1][0]===QT?e.witness.slice(0,-1):e.witness.slice()}),i=Mr(()=>{if(e.scriptTree)return Ef(e.scriptTree);if(e.hash)return{hash:e.hash}}),o=e.network||wn,s={name:"p2tr",network:o};if(we(s,"address",()=>{if(!s.pubkey)return;const a=ha.toWords(s.pubkey);return a.unshift(B1),ha.encode(o.bech32,a)}),we(s,"hash",()=>{const a=i();if(a)return a.hash;const u=n();if(u&&u.length>1){const f=u[u.length-1],h=f[0]&lu,d=u[u.length-2],g=fi({output:d,version:h});return vf(f,g)}return null}),we(s,"output",()=>{if(s.pubkey)return gr([N1.OP_1,s.pubkey])}),we(s,"redeemVersion",()=>e.redeemVersion?e.redeemVersion:e.redeem&&e.redeem.redeemVersion!==void 0&&e.redeem.redeemVersion!==null?e.redeem.redeemVersion:C1),we(s,"redeem",()=>{const a=n();if(!(!a||a.length<2))return{output:a[a.length-2],witness:a.slice(0,-2),redeemVersion:a[a.length-1][0]&lu}}),we(s,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.output)return e.output.slice(2);if(e.address)return r().data;if(s.internalPubkey){const a=Eu(s.internalPubkey,s.hash);if(a)return a.x}}),we(s,"internalPubkey",()=>{if(e.internalPubkey)return e.internalPubkey;const a=n();if(a&&a.length>1)return a[a.length-1].slice(1,33)}),we(s,"signature",()=>{if(e.signature)return e.signature;const a=n();if(!(!a||a.length!==1))return a[0]}),we(s,"witness",()=>{if(e.witness)return e.witness;const a=i();if(a&&e.redeem&&e.redeem.output&&e.internalPubkey){const u=fi({output:e.redeem.output,version:s.redeemVersion}),f=vu(a,u);if(!f)return;const h=Eu(e.internalPubkey,a.hash);if(!h)return;const d=ht([Uint8Array.from([s.redeemVersion|h.parity]),e.internalPubkey].concat(f));return[e.redeem.output,d]}if(e.signature)return[e.signature]}),t.validate){let a=Uint8Array.from([]);if(e.address){if(o&&o.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==B1)throw new TypeError("Invalid address version");if(r().data.length!==32)throw new TypeError("Invalid address data");a=r().data}if(e.pubkey){if(a.length>0&&ee(a,e.pubkey)!==0)throw new TypeError("Pubkey mismatch");a=e.pubkey}if(e.output){if(e.output.length!==34||e.output[0]!==N1.OP_1||e.output[1]!==32)throw new TypeError("Output is invalid");if(a.length>0&&ee(a,e.output.slice(2))!==0)throw new TypeError("Pubkey mismatch");a=e.output.slice(2)}if(e.internalPubkey){const h=Eu(e.internalPubkey,s.hash);if(a.length>0&&ee(a,h.x)!==0)throw new TypeError("Pubkey mismatch");a=h.x}if(a&&a.length&&!bf().isXOnlyPoint(a))throw new TypeError("Invalid pubkey for p2tr");const u=i();if(e.hash&&u&&ee(e.hash,u.hash)!==0)throw new TypeError("Hash mismatch");if(e.redeem&&e.redeem.output&&u){const h=fi({output:e.redeem.output,version:s.redeemVersion});if(!vu(u,h))throw new TypeError("Redeem script not in tree")}const f=n();if(e.redeem&&s.redeem){if(e.redeem.redeemVersion&&e.redeem.redeemVersion!==s.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(e.redeem.output){if(mt(e.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(s.redeem.output&&ee(e.redeem.output,s.redeem.output)!==0)throw new TypeError("Redeem.output and witness mismatch")}if(e.redeem.witness&&s.redeem.witness&&!sa(e.redeem.witness,s.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(f&&f.length)if(f.length===1){if(e.signature&&ee(e.signature,f[0])!==0)throw new TypeError("Signature mismatch")}else{const h=f[f.length-1];if(h.length<33)throw new TypeError(`The control-block length is too small. Got ${h.length}, expected min 33.`);if((h.length-33)%32!==0)throw new TypeError(`The control-block length of ${h.length} is incorrect!`);const d=(h.length-33)/32;if(d>128)throw new TypeError(`The script path is too long. Got ${d}, expected max 128.`);const g=h.slice(1,33);if(e.internalPubkey&&ee(e.internalPubkey,g)!==0)throw new TypeError("Internal pubkey mismatch");if(!bf().isXOnlyPoint(g))throw new TypeError("Invalid internalPubkey for p2tr witness");const v=h[0]&lu,E=f[f.length-2],T=fi({output:E,version:v}),x=vf(h,T),N=Eu(g,x);if(!N)throw new TypeError("Invalid outputKey for p2tr witness");if(a.length&&ee(a,N.x)!==0)throw new TypeError("Pubkey mismatch for p2tr witness");if(N.parity!==(h[0]&1))throw new Error("Incorrect parity")}}return Object.assign(s,e)}const U1=40,R1=2,H1=16,L1=2,K1=80,j1="WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.";function e_(e,t){const r=e.slice(2);if(r.length<R1||r.length>U1)throw new TypeError("Invalid program length for segwit address");const n=e[0]-K1;if(n<L1||n>H1)throw new TypeError("Invalid version for segwit address");if(e[1]!==r.length)throw new TypeError("Invalid script for segwit address");return console.warn(j1),r_(r,n,t.bech32)}function t_(e){const t=aa.decode(e);if(t.length<21)throw new TypeError(e+" is too short");if(t.length>21)throw new TypeError(e+" is too long");const r=ai(t,0),n=t.slice(1);return{version:r,hash:n}}function D1(e){let t,r;try{t=Or.decode(e)}catch{}if(t){if(r=t.words[0],r!==0)throw new TypeError(e+" uses wrong encoding")}else if(t=ha.decode(e),r=t.words[0],r===0)throw new TypeError(e+" uses wrong encoding");const n=Or.fromWords(t.words.slice(1));return{version:r,prefix:t.prefix,data:Uint8Array.from(n)}}function r_(e,t,r){const n=Or.toWords(e);return n.unshift(t),t===0?Or.encode(r,n):ha.encode(r,n)}function ga(e,t){t=t||wn;try{return ca({output:e,network:t}).address}catch{}try{return ao({output:e,network:t}).address}catch{}try{return fa({output:e,network:t}).address}catch{}try{return da({output:e,network:t}).address}catch{}try{return ya({output:e,network:t}).address}catch{}try{return e_(e,t)}catch{}throw new Error(iT(e)+" has no matching Address")}function M1(e,t){t=t||wn;let r,n;try{r=t_(e)}catch{}if(r){if(r.version===t.pubKeyHash)return ca({hash:r.hash}).output;if(r.version===t.scriptHash)return ao({hash:r.hash}).output}else{try{n=D1(e)}catch{}if(n){if(n.prefix!==t.bech32)throw new Error(e+" has an invalid prefix");if(n.version===0){if(n.data.length===20)return fa({hash:n.data}).output;if(n.data.length===32)return da({hash:n.data}).output}else if(n.version===1){if(n.data.length===32)return ya({pubkey:n.data}).output}else if(n.version>=L1&&n.version<=H1&&n.data.length>=R1&&n.data.length<=U1)return console.warn(j1),gr([n.version+K1,n.data])}}throw new Error(e+" has no matching Script")}function Kn(e){const t=e.length;return Vr(t)+t}function n_(e){const t=e.length;return Vr(t)+e.reduce((r,n)=>r+Kn(n),0)}const Xi=new Uint8Array(0),F1=[],Sf=oi("0000000000000000000000000000000000000000000000000000000000000000"),V1=oi("0000000000000000000000000000000000000000000000000000000000000001"),i_=oi("ffffffffffffffff"),s_={script:Xi,valueBuffer:i_};function o_(e){return e.value!==void 0}const vn=class et{constructor(){ge(this,"version",1),ge(this,"locktime",0),ge(this,"ins",[]),ge(this,"outs",[])}static fromBuffer(t,r){const n=new GT(t),i=new et;i.version=n.readInt32();const o=n.readUInt8(),s=n.readUInt8();let a=!1;o===et.ADVANCED_TRANSACTION_MARKER&&s===et.ADVANCED_TRANSACTION_FLAG?a=!0:n.offset-=2;const u=n.readVarInt();for(let h=0;h<u;++h)i.ins.push({hash:n.readSlice(32),index:n.readUInt32(),script:n.readVarSlice(),sequence:n.readUInt32(),witness:F1});const f=n.readVarInt();for(let h=0;h<f;++h)i.outs.push({value:n.readInt64(),script:n.readVarSlice()});if(a){for(let h=0;h<u;++h)i.ins[h].witness=n.readVector();if(!i.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(i.locktime=n.readUInt32(),r)return i;if(n.offset!==t.length)throw new Error("Transaction has unexpected data");return i}static fromHex(t){return et.fromBuffer(oi(t),!1)}static isCoinbaseHash(t){ft(i1,t);for(let r=0;r<32;++r)if(t[r]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&et.isCoinbaseHash(this.ins[0].hash)}addInput(t,r,n,i){return ft(Hn([i1,ci,of(uu(ci)),of(uu(Me))]),[t,r,n,i]),n==null&&(n=et.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:r,script:i||Xi,sequence:n,witness:F1})-1}addOutput(t,r){return ft(Hn([Me,uf]),[t,r]),this.outs.push({script:t,value:r})-1}hasWitnesses(){return this.ins.some(t=>t.witness.length!==0)}weight(){const t=this.byteLength(!1),r=this.byteLength(!0);return t*3+r}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(t=!0){const r=t&&this.hasWitnesses();return(r?10:8)+Vr(this.ins.length)+Vr(this.outs.length)+this.ins.reduce((n,i)=>n+40+Kn(i.script),0)+this.outs.reduce((n,i)=>n+8+Kn(i.script),0)+(r?this.ins.reduce((n,i)=>n+n_(i.witness),0):0)}clone(){const t=new et;return t.version=this.version,t.locktime=this.locktime,t.ins=this.ins.map(r=>({hash:r.hash,index:r.index,script:r.script,sequence:r.sequence,witness:r.witness})),t.outs=this.outs.map(r=>({script:r.script,value:r.value})),t}hashForSignature(t,r,n){if(ft(Hn([ci,Me,yr()]),[t,r,n]),t>=this.ins.length)return V1;const i=gr(mt(r).filter(a=>a!==Ge.OP_CODESEPARATOR)),o=this.clone();if((n&31)===et.SIGHASH_NONE)o.outs=[],o.ins.forEach((a,u)=>{u!==t&&(a.sequence=0)});else if((n&31)===et.SIGHASH_SINGLE){if(t>=this.outs.length)return V1;o.outs.length=t+1;for(let a=0;a<t;a++)o.outs[a]=s_;o.ins.forEach((a,u)=>{u!==t&&(a.sequence=0)})}n&et.SIGHASH_ANYONECANPAY?(o.ins=[o.ins[t]],o.ins[0].script=i):(o.ins.forEach(a=>{a.script=Xi}),o.ins[t].script=i);const s=new Uint8Array(o.byteLength(!1)+4);return Vg(s,s.length-4,n,"LE"),o.__toBuffer(s,0,!1),Ts(s)}hashForWitnessV1(t,r,n,i,o,s){if(ft(Hn([ci,pr(Me),pr(uf),ci]),[t,r,n,i]),n.length!==this.ins.length||r.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const a=i===et.SIGHASH_DEFAULT?et.SIGHASH_ALL:i&et.SIGHASH_OUTPUT_MASK,u=(i&et.SIGHASH_INPUT_MASK)===et.SIGHASH_ANYONECANPAY,f=a===et.SIGHASH_NONE,h=a===et.SIGHASH_SINGLE;let d=Xi,g=Xi,v=Xi,E=Xi,T=Xi;if(!u){let k=qt.withCapacity(36*this.ins.length);this.ins.forEach(R=>{k.writeSlice(R.hash),k.writeUInt32(R.index)}),d=rr(k.end()),k=qt.withCapacity(8*this.ins.length),n.forEach(R=>k.writeInt64(R)),g=rr(k.end()),k=qt.withCapacity(r.map(Kn).reduce((R,W)=>R+W)),r.forEach(R=>k.writeVarSlice(R)),v=rr(k.end()),k=qt.withCapacity(4*this.ins.length),this.ins.forEach(R=>k.writeUInt32(R.sequence)),E=rr(k.end())}if(f||h){if(h&&t<this.outs.length){const k=this.outs[t],R=qt.withCapacity(8+Kn(k.script));R.writeInt64(k.value),R.writeVarSlice(k.script),T=rr(R.end())}}else{if(!this.outs.length)throw new Error("Add outputs to the transaction before signing.");const k=this.outs.map(W=>8+Kn(W.script)).reduce((W,V)=>W+V),R=qt.withCapacity(k);this.outs.forEach(W=>{R.writeInt64(W.value),R.writeVarSlice(W.script)}),T=rr(R.end())}const x=(o?2:0)+(s?1:0),N=174-(u?49:0)-(f?32:0)+(s?32:0)+(o?37:0),I=qt.withCapacity(N);if(I.writeUInt8(i),I.writeInt32(this.version),I.writeUInt32(this.locktime),I.writeSlice(d),I.writeSlice(g),I.writeSlice(v),I.writeSlice(E),f||h||I.writeSlice(T),I.writeUInt8(x),u){const k=this.ins[t];I.writeSlice(k.hash),I.writeUInt32(k.index),I.writeInt64(n[t]),I.writeVarSlice(r[t]),I.writeUInt32(k.sequence)}else I.writeUInt32(t);if(s){const k=qt.withCapacity(Kn(s));k.writeVarSlice(s),I.writeSlice(rr(k.end()))}return h&&I.writeSlice(T),o&&(I.writeSlice(o),I.writeUInt8(0),I.writeUInt32(4294967295)),wu("TapSighash",ht([Uint8Array.from([0]),I.end()]))}hashForWitnessV0(t,r,n,i){ft(Hn([ci,Me,uf,ci]),[t,r,n,i]);let o=Uint8Array.from([]),s,a=Sf,u=Sf,f=Sf;if(i&et.SIGHASH_ANYONECANPAY||(o=new Uint8Array(36*this.ins.length),s=new qt(o,0),this.ins.forEach(d=>{s.writeSlice(d.hash),s.writeUInt32(d.index)}),u=Ts(o)),!(i&et.SIGHASH_ANYONECANPAY)&&(i&31)!==et.SIGHASH_SINGLE&&(i&31)!==et.SIGHASH_NONE&&(o=new Uint8Array(4*this.ins.length),s=new qt(o,0),this.ins.forEach(d=>{s.writeUInt32(d.sequence)}),f=Ts(o)),(i&31)!==et.SIGHASH_SINGLE&&(i&31)!==et.SIGHASH_NONE){const d=this.outs.reduce((g,v)=>g+8+Kn(v.script),0);o=new Uint8Array(d),s=new qt(o,0),this.outs.forEach(g=>{s.writeInt64(g.value),s.writeVarSlice(g.script)}),a=Ts(o)}else if((i&31)===et.SIGHASH_SINGLE&&t<this.outs.length){const d=this.outs[t];o=new Uint8Array(8+Kn(d.script)),s=new qt(o,0),s.writeInt64(d.value),s.writeVarSlice(d.script),a=Ts(o)}o=new Uint8Array(156+Kn(r)),s=new qt(o,0);const h=this.ins[t];return s.writeInt32(this.version),s.writeSlice(u),s.writeSlice(f),s.writeSlice(h.hash),s.writeUInt32(h.index),s.writeVarSlice(r),s.writeInt64(n),s.writeUInt32(h.sequence),s.writeSlice(a),s.writeUInt32(this.locktime),s.writeUInt32(i),Ts(o)}getHash(t){return t&&this.isCoinbase()?new Uint8Array(32):Ts(this.__toBuffer(void 0,void 0,t))}getId(){return Ee(mf(this.getHash(!1)))}toBuffer(t,r){return this.__toBuffer(t,r,!0)}toHex(){return Ee(this.toBuffer(void 0,void 0))}setInputScript(t,r){ft(Hn([yr(),Me]),[t,r]),this.ins[t].script=r}setWitness(t,r){ft(Hn([yr(),pr(Me)]),[t,r]),this.ins[t].witness=r}__toBuffer(t,r,n=!1){t||(t=new Uint8Array(this.byteLength(n)));const i=new qt(t,r||0);i.writeInt32(this.version);const o=n&&this.hasWitnesses();return o&&(i.writeUInt8(et.ADVANCED_TRANSACTION_MARKER),i.writeUInt8(et.ADVANCED_TRANSACTION_FLAG)),i.writeVarInt(this.ins.length),this.ins.forEach(s=>{i.writeSlice(s.hash),i.writeUInt32(s.index),i.writeVarSlice(s.script),i.writeUInt32(s.sequence)}),i.writeVarInt(this.outs.length),this.outs.forEach(s=>{o_(s)?i.writeInt64(s.value):i.writeSlice(s.valueBuffer),i.writeVarSlice(s.script)}),o&&this.ins.forEach(s=>{i.writeVector(s.witness)}),i.writeUInt32(this.locktime),r!==void 0?t.slice(r,i.offset):t}};ge(vn,"DEFAULT_SEQUENCE",4294967295),ge(vn,"SIGHASH_DEFAULT",0),ge(vn,"SIGHASH_ALL",1),ge(vn,"SIGHASH_NONE",2),ge(vn,"SIGHASH_SINGLE",3),ge(vn,"SIGHASH_ANYONECANPAY",128),ge(vn,"SIGHASH_OUTPUT_MASK",3),ge(vn,"SIGHASH_INPUT_MASK",128),ge(vn,"ADVANCED_TRANSACTION_MARKER",0),ge(vn,"ADVANCED_TRANSACTION_FLAG",1);let _t=vn;var jn;(function(e){e[e.UNSIGNED_TX=0]="UNSIGNED_TX",e[e.GLOBAL_XPUB=1]="GLOBAL_XPUB"})(jn||(jn={}));var se;(function(e){e[e.NON_WITNESS_UTXO=0]="NON_WITNESS_UTXO",e[e.WITNESS_UTXO=1]="WITNESS_UTXO",e[e.PARTIAL_SIG=2]="PARTIAL_SIG",e[e.SIGHASH_TYPE=3]="SIGHASH_TYPE",e[e.REDEEM_SCRIPT=4]="REDEEM_SCRIPT",e[e.WITNESS_SCRIPT=5]="WITNESS_SCRIPT",e[e.BIP32_DERIVATION=6]="BIP32_DERIVATION",e[e.FINAL_SCRIPTSIG=7]="FINAL_SCRIPTSIG",e[e.FINAL_SCRIPTWITNESS=8]="FINAL_SCRIPTWITNESS",e[e.POR_COMMITMENT=9]="POR_COMMITMENT",e[e.TAP_KEY_SIG=19]="TAP_KEY_SIG",e[e.TAP_SCRIPT_SIG=20]="TAP_SCRIPT_SIG",e[e.TAP_LEAF_SCRIPT=21]="TAP_LEAF_SCRIPT",e[e.TAP_BIP32_DERIVATION=22]="TAP_BIP32_DERIVATION",e[e.TAP_INTERNAL_KEY=23]="TAP_INTERNAL_KEY",e[e.TAP_MERKLE_ROOT=24]="TAP_MERKLE_ROOT"})(se||(se={}));var kt;(function(e){e[e.REDEEM_SCRIPT=0]="REDEEM_SCRIPT",e[e.WITNESS_SCRIPT=1]="WITNESS_SCRIPT",e[e.BIP32_DERIVATION=2]="BIP32_DERIVATION",e[e.TAP_INTERNAL_KEY=5]="TAP_INTERNAL_KEY",e[e.TAP_TREE=6]="TAP_TREE",e[e.TAP_BIP32_DERIVATION=7]="TAP_BIP32_DERIVATION"})(kt||(kt={}));const a_=e=>[...Array(e).keys()];function c_(e){if(e.key[0]!==jn.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+Ee(e.key));if(e.key.length!==79||![2,3].includes(e.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+Ee(e.key));if(e.value.length/4%1!==0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const t=e.key.slice(1),r={masterFingerprint:e.value.slice(0,4),extendedPubkey:t,path:"m"};for(const n of a_(e.value.length/4-1)){const i=io(e.value,n*4+4,"LE"),o=!!(i&2147483648),s=i&2147483647;r.path+="/"+s.toString(10)+(o?"'":"")}return r}function u_(e){const t=new Uint8Array([jn.GLOBAL_XPUB]),r=ht([t,e.extendedPubkey]),n=e.path.split("/"),i=new Uint8Array(n.length*4);i.set(e.masterFingerprint,0);let o=4;return n.slice(1).forEach(s=>{const a=s.slice(-1)==="'";let u=2147483647&parseInt(a?s.slice(0,-1):s,10);a&&(u+=2147483648),na(i,o,u,"LE"),o+=4}),{key:r,value:i}}const l_="{ masterFingerprint: Uint8Array; extendedPubkey: Uint8Array; path: string; }";function h_(e){const t=e.extendedPubkey,r=e.masterFingerprint,n=e.path;return t instanceof Uint8Array&&t.length===78&&[2,3].indexOf(t[45])>-1&&r instanceof Uint8Array&&r.length===4&&typeof n=="string"&&!!n.match(/^m(\/\d+'?)*$/)}function f_(e,t,r){const n=Ee(t.extendedPubkey);return r.has(n)?!1:(r.add(n),e.filter(i=>ee(i.extendedPubkey,t.extendedPubkey)).length===0)}const d_=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:f_,check:h_,decode:c_,encode:u_,expected:l_},Symbol.toStringTag,{value:"Module"}));function p_(e){return{key:new Uint8Array([jn.UNSIGNED_TX]),value:e.toBuffer()}}const y_=Object.freeze(Object.defineProperty({__proto__:null,encode:p_},Symbol.toStringTag,{value:"Module"}));function g_(e){if(e.key[0]!==se.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+Ee(e.key));return e.value}function w_(e){return{key:new Uint8Array([se.FINAL_SCRIPTSIG]),value:e}}const b_="Uint8Array";function m_(e){return e instanceof Uint8Array}function v_(e,t){return!!e&&!!t&&e.finalScriptSig===void 0}const E_=Object.freeze(Object.defineProperty({__proto__:null,canAdd:v_,check:m_,decode:g_,encode:w_,expected:b_},Symbol.toStringTag,{value:"Module"}));function A_(e){if(e.key[0]!==se.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+Ee(e.key));return e.value}function S_(e){return{key:new Uint8Array([se.FINAL_SCRIPTWITNESS]),value:e}}const T_="Uint8Array";function __(e){return e instanceof Uint8Array}function k_(e,t){return!!e&&!!t&&e.finalScriptWitness===void 0}const P_=Object.freeze(Object.defineProperty({__proto__:null,canAdd:k_,check:__,decode:A_,encode:S_,expected:T_},Symbol.toStringTag,{value:"Module"}));function O_(e){if(e.key[0]!==se.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+Ee(e.key));return e.value}function I_(e){return{key:new Uint8Array([se.NON_WITNESS_UTXO]),value:e}}const x_="Uint8Array";function $_(e){return e instanceof Uint8Array}function C_(e,t){return!!e&&!!t&&e.nonWitnessUtxo===void 0}const N_=Object.freeze(Object.defineProperty({__proto__:null,canAdd:C_,check:$_,decode:O_,encode:I_,expected:x_},Symbol.toStringTag,{value:"Module"}));function B_(e){if(e.key[0]!==se.PARTIAL_SIG)throw new Error("Decode Error: could not decode partialSig with key 0x"+Ee(e.key));if(!(e.key.length===34||e.key.length===66)||![2,3,4].includes(e.key[1]))throw new Error("Decode Error: partialSig has invalid pubkey in key 0x"+Ee(e.key));return{pubkey:e.key.slice(1),signature:e.value}}function U_(e){const t=new Uint8Array([se.PARTIAL_SIG]);return{key:ht([t,e.pubkey]),value:e.signature}}const R_="{ pubkey: Uint8Array; signature: Uint8Array; }";function H_(e){return e.pubkey instanceof Uint8Array&&e.signature instanceof Uint8Array&&[33,65].includes(e.pubkey.length)&&[2,3,4].includes(e.pubkey[0])&&L_(e.signature)}function L_(e){if(!(e instanceof Uint8Array)||e.length<9||e[0]!==48||e.length!==e[1]+3||e[2]!==2)return!1;const t=e[3];if(t>33||t<1||e[3+t+1]!==2)return!1;const r=e[3+t+2];return!(r>33||r<1||e.length!==3+t+2+r+2)}function K_(e,t,r){const n=Ee(t.pubkey);return r.has(n)?!1:(r.add(n),e.filter(i=>ee(i.pubkey,t.pubkey)===0).length===0)}const j_=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:K_,check:H_,decode:B_,encode:U_,expected:R_},Symbol.toStringTag,{value:"Module"}));function D_(e){if(e.key[0]!==se.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+Ee(e.key));return N5(e.value)}function M_(e){return{key:new Uint8Array([se.POR_COMMITMENT]),value:B5(e)}}const F_="string";function V_(e){return typeof e=="string"}function z_(e,t){return!!e&&!!t&&e.porCommitment===void 0}const W_=Object.freeze(Object.defineProperty({__proto__:null,canAdd:z_,check:V_,decode:D_,encode:M_,expected:F_},Symbol.toStringTag,{value:"Module"}));function q_(e){if(e.key[0]!==se.SIGHASH_TYPE)throw new Error("Decode Error: could not decode sighashType with key 0x"+Ee(e.key));return Number(io(e.value,0,"LE"))}function G_(e){const t=Uint8Array.from([se.SIGHASH_TYPE]),r=new Uint8Array(4);return na(r,0,e,"LE"),{key:t,value:r}}const X_="number";function J_(e){return typeof e=="number"}function Y_(e,t){return!!e&&!!t&&e.sighashType===void 0}const Z_=Object.freeze(Object.defineProperty({__proto__:null,canAdd:Y_,check:J_,decode:q_,encode:G_,expected:X_},Symbol.toStringTag,{value:"Module"}));function Q_(e){if(e.key[0]!==se.TAP_KEY_SIG||e.key.length!==1)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+Ee(e.key));if(!z1(e.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return e.value}function ek(e){return{key:Uint8Array.from([se.TAP_KEY_SIG]),value:e}}const tk="Uint8Array";function z1(e){return e instanceof Uint8Array&&(e.length===64||e.length===65)}function rk(e,t){return!!e&&!!t&&e.tapKeySig===void 0}const nk=Object.freeze(Object.defineProperty({__proto__:null,canAdd:rk,check:z1,decode:Q_,encode:ek,expected:tk},Symbol.toStringTag,{value:"Module"}));function ik(e){if(e.key[0]!==se.TAP_LEAF_SCRIPT)throw new Error("Decode Error: could not decode tapLeafScript with key 0x"+Ee(e.key));if((e.key.length-2)%32!==0)throw new Error("Decode Error: tapLeafScript has invalid control block in key 0x"+Ee(e.key));const t=e.value[e.value.length-1];if((e.key[1]&254)!==t)throw new Error("Decode Error: tapLeafScript bad leaf version in key 0x"+Ee(e.key));const r=e.value.slice(0,-1);return{controlBlock:e.key.slice(1),script:r,leafVersion:t}}function sk(e){const t=Uint8Array.from([se.TAP_LEAF_SCRIPT]),r=Uint8Array.from([e.leafVersion]);return{key:ht([t,e.controlBlock]),value:ht([e.script,r])}}const ok="{ controlBlock: Uint8Array; leafVersion: number, script: Uint8Array; }";function ak(e){return e.controlBlock instanceof Uint8Array&&(e.controlBlock.length-1)%32===0&&(e.controlBlock[0]&254)===e.leafVersion&&e.script instanceof Uint8Array}function ck(e,t,r){const n=Ee(t.controlBlock);return r.has(n)?!1:(r.add(n),e.filter(i=>ee(i.controlBlock,t.controlBlock)===0).length===0)}const uk=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:ck,check:ak,decode:ik,encode:sk,expected:ok},Symbol.toStringTag,{value:"Module"}));function lk(e){if(e.key[0]!==se.TAP_MERKLE_ROOT||e.key.length!==1)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+Ee(e.key));if(!W1(e.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return e.value}function hk(e){return{key:Uint8Array.from([se.TAP_MERKLE_ROOT]),value:e}}const fk="Uint8Array";function W1(e){return e instanceof Uint8Array&&e.length===32}function dk(e,t){return!!e&&!!t&&e.tapMerkleRoot===void 0}const pk=Object.freeze(Object.defineProperty({__proto__:null,canAdd:dk,check:W1,decode:lk,encode:hk,expected:fk},Symbol.toStringTag,{value:"Module"}));function yk(e){if(e.key[0]!==se.TAP_SCRIPT_SIG)throw new Error("Decode Error: could not decode tapScriptSig with key 0x"+Ee(e.key));if(e.key.length!==65)throw new Error("Decode Error: tapScriptSig has invalid key 0x"+Ee(e.key));if(e.value.length!==64&&e.value.length!==65)throw new Error("Decode Error: tapScriptSig has invalid signature in key 0x"+Ee(e.key));const t=e.key.slice(1,33),r=e.key.slice(33);return{pubkey:t,leafHash:r,signature:e.value}}function gk(e){const t=Uint8Array.from([se.TAP_SCRIPT_SIG]);return{key:ht([t,e.pubkey,e.leafHash]),value:e.signature}}const wk="{ pubkey: Uint8Array; leafHash: Uint8Array; signature: Uint8Array; }";function bk(e){return e.pubkey instanceof Uint8Array&&e.leafHash instanceof Uint8Array&&e.signature instanceof Uint8Array&&e.pubkey.length===32&&e.leafHash.length===32&&(e.signature.length===64||e.signature.length===65)}function mk(e,t,r){const n=Ee(t.pubkey)+Ee(t.leafHash);return r.has(n)?!1:(r.add(n),e.filter(i=>ee(i.pubkey,t.pubkey)===0&&ee(i.leafHash,t.leafHash)===0).length===0)}const vk=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:mk,check:bk,decode:yk,encode:gk,expected:wk},Symbol.toStringTag,{value:"Module"}));function Ek(e){if(e.key[0]!==se.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+Ee(e.key));const t=Wg(e.value,0,"LE");let r=8;const{numberValue:n,bytes:i}=uo(e.value,r);r+=i;const o=e.value.slice(r);if(o.length!==n)throw new Error("Decode Error: WITNESS_UTXO script is not proper length");return{script:o,value:t}}function Ak(e){const{script:t,value:r}=e,n=Vr(t.length),i=new Uint8Array(8+n+t.length);return zg(i,0,BigInt(r),"LE"),Gi(t.length,i,8),i.set(t,8+n),{key:Uint8Array.from([se.WITNESS_UTXO]),value:i}}const Sk="{ script: Uint8Array; value: bigint; }";function Tk(e){return e.script instanceof Uint8Array&&typeof e.value=="bigint"}function _k(e,t){return!!e&&!!t&&e.witnessUtxo===void 0}const kk=Object.freeze(Object.defineProperty({__proto__:null,canAdd:_k,check:Tk,decode:Ek,encode:Ak,expected:Sk},Symbol.toStringTag,{value:"Module"}));function Pk(e){if(e.key[0]!==kt.TAP_TREE||e.key.length!==1)throw new Error("Decode Error: could not decode tapTree with key 0x"+Ee(e.key));let t=0;const r=[];for(;t<e.value.length;){const n=e.value[t++],i=e.value[t++],{numberValue:o,bytes:s}=uo(e.value,t);t+=s,r.push({depth:n,leafVersion:i,script:e.value.slice(t,t+o)}),t+=o}return{leaves:r}}function Ok(e){const t=Uint8Array.from([kt.TAP_TREE]),r=[].concat(...e.leaves.map(n=>[Uint8Array.of(n.depth,n.leafVersion),Gi(BigInt(n.script.length)).buffer,n.script]));return{key:t,value:ht(r)}}const Ik="{ leaves: [{ depth: number; leafVersion: number, script: Uint8Array; }] }";function xk(e){return Array.isArray(e.leaves)&&e.leaves.every(t=>t.depth>=0&&t.depth<=128&&(t.leafVersion&254)===t.leafVersion&&t.script instanceof Uint8Array)}function $k(e,t){return!!e&&!!t&&e.tapTree===void 0}const Ck=Object.freeze(Object.defineProperty({__proto__:null,canAdd:$k,check:xk,decode:Pk,encode:Ok,expected:Ik},Symbol.toStringTag,{value:"Module"})),Nk=e=>[...Array(e).keys()],Bk=e=>e.length===33&&[2,3].includes(e[0])||e.length===65&&e[0]===4;function Tf(e,t=Bk){function r(a){if(a.key[0]!==e)throw new Error("Decode Error: could not decode bip32Derivation with key 0x"+Ee(a.key));const u=a.key.slice(1);if(!t(u))throw new Error("Decode Error: bip32Derivation has invalid pubkey in key 0x"+Ee(a.key));if(a.value.length/4%1!==0)throw new Error("Decode Error: Input BIP32_DERIVATION value length should be multiple of 4");const f={masterFingerprint:a.value.slice(0,4),pubkey:u,path:"m"};for(const h of Nk(a.value.length/4-1)){const d=io(a.value,h*4+4,"LE"),g=!!(d&2147483648),v=d&2147483647;f.path+="/"+v.toString(10)+(g?"'":"")}return f}function n(a){const u=Uint8Array.from([e]),f=ht([u,a.pubkey]),h=a.path.split("/"),d=new Uint8Array(h.length*4);d.set(a.masterFingerprint,0);let g=4;return h.slice(1).forEach(v=>{const E=v.slice(-1)==="'";let T=2147483647&parseInt(E?v.slice(0,-1):v,10);E&&(T+=2147483648),na(d,g,T,"LE"),g+=4}),{key:f,value:d}}const i="{ masterFingerprint: Uint8Array; pubkey: Uint8Array; path: string; }";function o(a){return a.pubkey instanceof Uint8Array&&a.masterFingerprint instanceof Uint8Array&&typeof a.path=="string"&&t(a.pubkey)&&a.masterFingerprint.length===4}function s(a,u,f){const h=Ee(u.pubkey);return f.has(h)?!1:(f.add(h),a.filter(d=>ee(d.pubkey,u.pubkey)===0).length===0)}return{decode:r,encode:n,check:o,expected:i,canAddToArray:s}}function _f(e){return t;function t(r){let n;if(e.includes(r.key[0])&&(n=r.key.slice(1),!(n.length===33||n.length===65)||![2,3,4].includes(n[0])))throw new Error("Format Error: invalid pubkey in key 0x"+Ee(r.key));return n}}function q1(e){function t(s){if(s.key[0]!==e)throw new Error("Decode Error: could not decode redeemScript with key 0x"+Ee(s.key));return s.value}function r(s){return{key:Uint8Array.from([e]),value:s}}const n="Uint8Array";function i(s){return s instanceof Uint8Array}function o(s,a){return!!s&&!!a&&s.redeemScript===void 0}return{decode:t,encode:r,check:i,expected:n,canAdd:o}}const Uk=e=>e.length===32;function G1(e){const t=Tf(e,Uk);function r(s){const{numberValue:a,bytes:u}=uo(s.value),f=t.decode({key:s.key,value:s.value.slice(u+Number(a)*32)}),h=new Array(Number(a));for(let d=0,g=u;d<a;d++,g+=32)h[d]=s.value.slice(g,g+32);return{...f,leafHashes:h}}function n(s){const a=t.encode(s),u=Vr(s.leafHashes.length),f=new Uint8Array(u);Gi(s.leafHashes.length,f);const h=ht([f,...s.leafHashes,a.value]);return{...a,value:h}}const i="{ masterFingerprint: Uint8Array; pubkey: Uint8Array; path: string; leafHashes: Uint8Array[]; }";function o(s){return Array.isArray(s.leafHashes)&&s.leafHashes.every(a=>a instanceof Uint8Array&&a.length===32)&&t.check(s)}return{decode:r,encode:n,check:o,expected:i,canAddToArray:t.canAddToArray}}function X1(e){function t(s){if(s.key[0]!==e||s.key.length!==1)throw new Error("Decode Error: could not decode tapInternalKey with key 0x"+Ee(s.key));if(s.value.length!==32)throw new Error("Decode Error: tapInternalKey not a 32-byte x-only pubkey");return s.value}function r(s){return{key:Uint8Array.from([e]),value:s}}const n="Uint8Array";function i(s){return s instanceof Uint8Array&&s.length===32}function o(s,a){return!!s&&!!a&&s.tapInternalKey===void 0}return{decode:t,encode:r,check:i,expected:n,canAdd:o}}function J1(e){function t(s){if(s.key[0]!==e)throw new Error("Decode Error: could not decode witnessScript with key 0x"+Ee(s.key));return s.value}function r(s){return{key:Uint8Array.from([e]),value:s}}const n="Uint8Array";function i(s){return s instanceof Uint8Array}function o(s,a){return!!s&&!!a&&s.witnessScript===void 0}return{decode:t,encode:r,check:i,expected:n,canAdd:o}}const kf={unsignedTx:y_,globalXpub:d_,checkPubkey:_f([])},Ut={nonWitnessUtxo:N_,partialSig:j_,sighashType:Z_,finalScriptSig:E_,finalScriptWitness:P_,porCommitment:W_,witnessUtxo:kk,bip32Derivation:Tf(se.BIP32_DERIVATION),redeemScript:q1(se.REDEEM_SCRIPT),witnessScript:J1(se.WITNESS_SCRIPT),checkPubkey:_f([se.PARTIAL_SIG,se.BIP32_DERIVATION]),tapKeySig:nk,tapScriptSig:vk,tapLeafScript:uk,tapBip32Derivation:G1(se.TAP_BIP32_DERIVATION),tapInternalKey:X1(se.TAP_INTERNAL_KEY),tapMerkleRoot:pk},di={bip32Derivation:Tf(kt.BIP32_DERIVATION),redeemScript:q1(kt.REDEEM_SCRIPT),witnessScript:J1(kt.WITNESS_SCRIPT),checkPubkey:_f([kt.BIP32_DERIVATION]),tapBip32Derivation:G1(kt.TAP_BIP32_DERIVATION),tapTree:Ck,tapInternalKey:X1(kt.TAP_INTERNAL_KEY)},Rk=Object.freeze(Object.defineProperty({__proto__:null,globals:kf,inputs:Ut,outputs:di},Symbol.toStringTag,{value:"Module"})),Au=e=>[...Array(e).keys()];function Y1(e){const t=e.map(Hk);return t.push(Uint8Array.from([0])),ht(t)}function Hk(e){const t=e.key.length,r=e.value.length,n=Vr(t),i=Vr(r),o=new Uint8Array(n+t+i+r);return Gi(t,o,0),o.set(e.key,n),Gi(r,o,n+t),o.set(e.value,n+t+i),o}function Lk(e,t){let r=0;function n(){const{numberValue:x,bytes:N}=uo(e,r);r+=N;const I=e.slice(r,r+Number(x));return r+=Number(x),I}function i(){const x=io(e,r,"BE");return r+=4,x}function o(){const x=ai(e,r);return r+=1,x}function s(){const x=n(),N=n();return{key:x,value:N}}function a(){if(r>=e.length)throw new Error("Format Error: Unexpected End of PSBT");const x=ai(e,r)===0;return x&&r++,x}if(i()!==1886610036)throw new Error("Format Error: Invalid Magic Number");if(o()!==255)throw new Error("Format Error: Magic Number must be followed by 0xff separator");const u=[],f={};for(;!a();){const x=s(),N=Ee(x.key);if(f[N])throw new Error("Format Error: Keys must be unique for global keymap: key "+N);f[N]=1,u.push(x)}const h=u.filter(x=>x.key[0]===jn.UNSIGNED_TX);if(h.length!==1)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const d=t(h[0].value),{inputCount:g,outputCount:v}=d.getInputOutputCounts(),E=[],T=[];for(const x of Au(g)){const N={},I=[];for(;!a();){const k=s(),R=Ee(k.key);if(N[R])throw new Error("Format Error: Keys must be unique for each input: input index "+x+" key "+R);N[R]=1,I.push(k)}E.push(I)}for(const x of Au(v)){const N={},I=[];for(;!a();){const k=s(),R=Ee(k.key);if(N[R])throw new Error("Format Error: Keys must be unique for each output: output index "+x+" key "+R);N[R]=1,I.push(k)}T.push(I)}return Z1(d,{globalMapKeyVals:u,inputKeyVals:E,outputKeyVals:T})}function Gt(e,t,r){if(ee(t,Uint8Array.from([r])))throw new Error(`Format Error: Invalid ${e} key: ${Ee(t)}`)}function Z1(e,{globalMapKeyVals:t,inputKeyVals:r,outputKeyVals:n}){const i={unsignedTx:e};let o=0;for(const h of t)switch(h.key[0]){case jn.UNSIGNED_TX:if(Gt("global",h.key,jn.UNSIGNED_TX),o>0)throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");o++;break;case jn.GLOBAL_XPUB:i.globalXpub===void 0&&(i.globalXpub=[]),i.globalXpub.push(kf.globalXpub.decode(h));break;default:i.unknownKeyVals||(i.unknownKeyVals=[]),i.unknownKeyVals.push(h)}const s=r.length,a=n.length,u=[],f=[];for(const h of Au(s)){const d={};for(const g of r[h])switch(Ut.checkPubkey(g),g.key[0]){case se.NON_WITNESS_UTXO:if(Gt("input",g.key,se.NON_WITNESS_UTXO),d.nonWitnessUtxo!==void 0)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");d.nonWitnessUtxo=Ut.nonWitnessUtxo.decode(g);break;case se.WITNESS_UTXO:if(Gt("input",g.key,se.WITNESS_UTXO),d.witnessUtxo!==void 0)throw new Error("Format Error: Input has multiple WITNESS_UTXO");d.witnessUtxo=Ut.witnessUtxo.decode(g);break;case se.PARTIAL_SIG:d.partialSig===void 0&&(d.partialSig=[]),d.partialSig.push(Ut.partialSig.decode(g));break;case se.SIGHASH_TYPE:if(Gt("input",g.key,se.SIGHASH_TYPE),d.sighashType!==void 0)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");d.sighashType=Ut.sighashType.decode(g);break;case se.REDEEM_SCRIPT:if(Gt("input",g.key,se.REDEEM_SCRIPT),d.redeemScript!==void 0)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");d.redeemScript=Ut.redeemScript.decode(g);break;case se.WITNESS_SCRIPT:if(Gt("input",g.key,se.WITNESS_SCRIPT),d.witnessScript!==void 0)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");d.witnessScript=Ut.witnessScript.decode(g);break;case se.BIP32_DERIVATION:d.bip32Derivation===void 0&&(d.bip32Derivation=[]),d.bip32Derivation.push(Ut.bip32Derivation.decode(g));break;case se.FINAL_SCRIPTSIG:Gt("input",g.key,se.FINAL_SCRIPTSIG),d.finalScriptSig=Ut.finalScriptSig.decode(g);break;case se.FINAL_SCRIPTWITNESS:Gt("input",g.key,se.FINAL_SCRIPTWITNESS),d.finalScriptWitness=Ut.finalScriptWitness.decode(g);break;case se.POR_COMMITMENT:Gt("input",g.key,se.POR_COMMITMENT),d.porCommitment=Ut.porCommitment.decode(g);break;case se.TAP_KEY_SIG:Gt("input",g.key,se.TAP_KEY_SIG),d.tapKeySig=Ut.tapKeySig.decode(g);break;case se.TAP_SCRIPT_SIG:d.tapScriptSig===void 0&&(d.tapScriptSig=[]),d.tapScriptSig.push(Ut.tapScriptSig.decode(g));break;case se.TAP_LEAF_SCRIPT:d.tapLeafScript===void 0&&(d.tapLeafScript=[]),d.tapLeafScript.push(Ut.tapLeafScript.decode(g));break;case se.TAP_BIP32_DERIVATION:d.tapBip32Derivation===void 0&&(d.tapBip32Derivation=[]),d.tapBip32Derivation.push(Ut.tapBip32Derivation.decode(g));break;case se.TAP_INTERNAL_KEY:Gt("input",g.key,se.TAP_INTERNAL_KEY),d.tapInternalKey=Ut.tapInternalKey.decode(g);break;case se.TAP_MERKLE_ROOT:Gt("input",g.key,se.TAP_MERKLE_ROOT),d.tapMerkleRoot=Ut.tapMerkleRoot.decode(g);break;default:d.unknownKeyVals||(d.unknownKeyVals=[]),d.unknownKeyVals.push(g)}u.push(d)}for(const h of Au(a)){const d={};for(const g of n[h])switch(di.checkPubkey(g),g.key[0]){case kt.REDEEM_SCRIPT:if(Gt("output",g.key,kt.REDEEM_SCRIPT),d.redeemScript!==void 0)throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");d.redeemScript=di.redeemScript.decode(g);break;case kt.WITNESS_SCRIPT:if(Gt("output",g.key,kt.WITNESS_SCRIPT),d.witnessScript!==void 0)throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");d.witnessScript=di.witnessScript.decode(g);break;case kt.BIP32_DERIVATION:d.bip32Derivation===void 0&&(d.bip32Derivation=[]),d.bip32Derivation.push(di.bip32Derivation.decode(g));break;case kt.TAP_INTERNAL_KEY:Gt("output",g.key,kt.TAP_INTERNAL_KEY),d.tapInternalKey=di.tapInternalKey.decode(g);break;case kt.TAP_TREE:Gt("output",g.key,kt.TAP_TREE),d.tapTree=di.tapTree.decode(g);break;case kt.TAP_BIP32_DERIVATION:d.tapBip32Derivation===void 0&&(d.tapBip32Derivation=[]),d.tapBip32Derivation.push(di.tapBip32Derivation.decode(g));break;default:d.unknownKeyVals||(d.unknownKeyVals=[]),d.unknownKeyVals.push(g)}f.push(d)}return{globalMap:i,inputs:u,outputs:f}}function Kk({globalMap:e,inputs:t,outputs:r}){const{globalKeyVals:n,inputKeyVals:i,outputKeyVals:o}=Of({globalMap:e,inputs:t,outputs:r}),s=Y1(n),a=d=>d.length===0?[Uint8Array.from([0])]:d.map(Y1),u=a(i),f=a(o),h=new Uint8Array(5);return h.set([112,115,98,116,255],0),ht([h,s].concat(u,f))}const jk=(e,t)=>ee(e.key,t.key);function Pf(e,t){const r=new Set,n=Object.entries(e).reduce((o,[s,a])=>{if(s==="unknownKeyVals")return o;const u=t[s];if(u===void 0)return o;const f=(Array.isArray(a)?a:[a]).map(u.encode);return f.map(h=>Ee(h.key)).forEach(h=>{if(r.has(h))throw new Error("Serialize Error: Duplicate key: "+h);r.add(h)}),o.concat(f)},[]),i=e.unknownKeyVals?e.unknownKeyVals.filter(o=>!r.has(Ee(o.key))):[];return n.concat(i).sort(jk)}function Of({globalMap:e,inputs:t,outputs:r}){return{globalKeyVals:Pf(e,kf),inputKeyVals:t.map(n=>Pf(n,Ut)),outputKeyVals:r.map(n=>Pf(n,di))}}function Dk(e){const t=e[0],r=Of(t),n=e.slice(1);if(n.length===0)throw new Error("Combine: Nothing to combine");const i=Q1(t);if(i===void 0)throw new Error("Combine: Self missing transaction");const o=lo(r.globalKeyVals),s=r.inputKeyVals.map(lo),a=r.outputKeyVals.map(lo);for(const u of n){const f=Q1(u);if(f===void 0||ee(f.toBuffer(),i.toBuffer())!==0)throw new Error("Combine: One of the Psbts does not have the same transaction.");const h=Of(u);lo(h.globalKeyVals).forEach(If(o,r.globalKeyVals,h.globalKeyVals)),h.inputKeyVals.map(lo).forEach((d,g)=>d.forEach(If(s[g],r.inputKeyVals[g],h.inputKeyVals[g]))),h.outputKeyVals.map(lo).forEach((d,g)=>d.forEach(If(a[g],r.outputKeyVals[g],h.outputKeyVals[g])))}return Z1(i,{globalMapKeyVals:r.globalKeyVals,inputKeyVals:r.inputKeyVals,outputKeyVals:r.outputKeyVals})}function If(e,t,r){return n=>{if(e.has(n))return;const i=r.filter(o=>Ee(o.key)===n)[0];t.push(i),e.add(n)}}function Q1(e){return e.globalMap.unsignedTx}function lo(e){const t=new Set;return e.forEach(r=>{const n=Ee(r.key);if(t.has(n))throw new Error("Combine: KeyValue Map keys should be unique");t.add(n)}),t}function jt(e,t){const r=e[t];if(r===void 0)throw new Error(`No input #${t}`);return r}function wa(e,t){const r=e[t];if(r===void 0)throw new Error(`No output #${t}`);return r}function xf(e,t,r){if(e.key[0]<r)throw new Error("Use the method for your specific key instead of addUnknownKeyVal*");if(t&&t.filter(n=>ee(n.key,e.key)===0).length!==0)throw new Error(`Duplicate Key: ${Ee(e.key)}`)}function $f(e){let t=0;return Object.keys(e).forEach(r=>{Number(isNaN(Number(r)))&&t++}),t}function Mk(e,t){let r=!1;if(t.nonWitnessUtxo||t.witnessUtxo){const n=!!t.redeemScript,i=!!t.witnessScript,o=!n||!!t.finalScriptSig,s=!i||!!t.finalScriptWitness,a=!!t.finalScriptSig||!!t.finalScriptWitness;r=o&&s&&a}if(r===!1)throw new Error(`Input #${e} has too much or too little data to clean`)}function ew(e,t,r,n){throw new Error(`Data for ${e} key ${t} is incorrect: Expected ${r} and got ${JSON.stringify(n)}`)}function Cf(e){return(t,r)=>{for(const n of Object.keys(t)){const i=t[n],{canAdd:o,canAddToArray:s,check:a,expected:u}=Rk[e+"s"][n]||{},f=!!s;if(a)if(f){if(!Array.isArray(i)||r[n]&&!Array.isArray(r[n]))throw new Error(`Key type ${n} must be an array`);i.every(a)||ew(e,n,u,i);const h=r[n]||[],d=new Set;if(!i.every(g=>s(h,g,d)))throw new Error("Can not add duplicate data to array");r[n]=h.concat(i)}else{if(a(i)||ew(e,n,u,i),!o(r,i))throw new Error(`Can not add duplicate data to ${e}`);r[n]=i}}}}const Fk=Cf("global"),tw=Cf("input"),rw=Cf("output");function Vk(e,t){const r=e.length-1,n=jt(e,r);tw(t,n)}function zk(e,t){const r=e.length-1,n=wa(e,r);rw(t,n)}let nw=class{constructor(e){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:e}}static fromBase64(e,t){const r=Fg(e);return this.fromBuffer(r,t)}static fromHex(e,t){const r=oi(e);return this.fromBuffer(r,t)}static fromBuffer(e,t){const r=Lk(e,t),n=new this(r.globalMap.unsignedTx);return Object.assign(n,r),n}toBase64(){const e=this.toBuffer();return H5(e)}toHex(){const e=this.toBuffer();return Ee(e)}toBuffer(){return Kk(this)}updateGlobal(e){return Fk(e,this.globalMap),this}updateInput(e,t){const r=jt(this.inputs,e);return tw(t,r),this}updateOutput(e,t){const r=wa(this.outputs,e);return rw(t,r),this}addUnknownKeyValToGlobal(e){return xf(e,this.globalMap.unknownKeyVals,$f(jn)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(e),this}addUnknownKeyValToInput(e,t){const r=jt(this.inputs,e);return xf(t,r.unknownKeyVals,$f(se)),r.unknownKeyVals||(r.unknownKeyVals=[]),r.unknownKeyVals.push(t),this}addUnknownKeyValToOutput(e,t){const r=wa(this.outputs,e);return xf(t,r.unknownKeyVals,$f(kt)),r.unknownKeyVals||(r.unknownKeyVals=[]),r.unknownKeyVals.push(t),this}addInput(e){this.globalMap.unsignedTx.addInput(e),this.inputs.push({unknownKeyVals:[]});const t=e.unknownKeyVals||[],r=this.inputs.length-1;if(!Array.isArray(t))throw new Error("unknownKeyVals must be an Array");return t.forEach(n=>this.addUnknownKeyValToInput(r,n)),Vk(this.inputs,e),this}addOutput(e){this.globalMap.unsignedTx.addOutput(e),this.outputs.push({unknownKeyVals:[]});const t=e.unknownKeyVals||[],r=this.outputs.length-1;if(!Array.isArray(t))throw new Error("unknownKeyVals must be an Array");return t.forEach(n=>this.addUnknownKeyValToOutput(r,n)),zk(this.outputs,e),this}clearFinalizedInput(e){const t=jt(this.inputs,e);Mk(e,t);for(const r of Object.keys(t))["witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknownKeyVals"].includes(r)||delete t[r];return this}combine(...e){const t=Dk([this].concat(e));return Object.assign(this,t),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}};function _s(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}const Wk=_s(pu),qk=_s(y1),Gk=_s(ca),Su=_s(fa),iw=_s(da),sw=_s(ao),ow=_s(ya);function Tu(e){let t=new Uint8Array(0);function r(s){t=ht([t,s])}function n(s){const a=t.length,u=Vr(s);t=ht([t,new Uint8Array(u)]),Gi(s,t,a)}function i(s){n(s.length),r(s)}function o(s){n(s.length),s.forEach(i)}return o(e),t}function aw(e,t){const r=li(e),n=e.slice(1,33),i=mt(t);if(i===null)throw new Error("Unknown script error");return i.findIndex(o=>typeof o=="number"?!1:ee(e,o)===0||ee(r,o)===0||ee(n,o)===0)}function _u(e,t){return aw(e,t)!==-1}function Xk(e,t){return Jk(e).some(r=>cw(r,oa.decode,t))}function cw(e,t,r){const{hashType:n}=t(e),i=[];switch(n&_t.SIGHASH_ANYONECANPAY&&i.push("addInput"),n&31){case _t.SIGHASH_ALL:break;case _t.SIGHASH_SINGLE:case _t.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence");break}return i.indexOf(r)===-1}function Jk(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=Yk(e)}else t=e.partialSig;return t.map(r=>r.signature)}function Yk(e){const t=e.finalScriptSig?mt(e.finalScriptSig)||[]:[],r=e.finalScriptWitness?mt(e.finalScriptWitness)||[]:[];return t.concat(r).filter(n=>n instanceof Uint8Array&&ui(n)).map(n=>({signature:n}))}const ku=e=>e.length===32?e:e.slice(1,33);function uw(e,t,r){const n=hP(t,e,r);try{const i=uP(t,n).concat(n.script).concat(n.controlBlock);return{finalScriptWitness:Tu(i)}}catch(i){throw new Error(`Can not finalize taproot input #${e}: ${i}`)}}function Pu(e,t){const r=t?Uint8Array.from([t]):Uint8Array.from([]);return ht([e,r])}function En(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&ow(e.witnessUtxo.script))}function Nf(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t)}function lw(e,t,r){oP(e,t,r),cP(e,t,r)}function hw(e,t,r){aP(e,t,r),Zk(e,t)}function Zk(e,t){if(!t.tapTree&&!t.tapInternalKey)return;const r=t.tapInternalKey||e.tapInternalKey,n=t.tapTree||e.tapTree;if(r){const{script:i}=e,o=Qk(r,n);if(i&&ee(o,i)!==0)throw new Error("Error adding output. Script or address mismatch.")}}function Qk(e,t){const r=t&&eP(t.leaves),{output:n}=ya({internalPubkey:e,scriptTree:r});return n}function eP(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:sP(e)}function tP(e,t){return nP(e).some(r=>cw(r,rP,t))}function rP(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||_t.SIGHASH_DEFAULT}}function nP(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(r=>r.signature)),!t.length){const r=iP(e.finalScriptWitness);r&&t.push(r)}return t}function iP(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function sP(e){let t;for(const r of e)if(t=Bf(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function Bf(e,t,r=0){if(r>XT)throw new Error("Max taptree depth exceeded.");if(e.depth===r)return t?void 0:{output:e.script,version:e.leafVersion};if(cf(t))return;const n=Bf(e,t&&t[0],r+1);if(n)return[n,t&&t[1]];const i=Bf(e,t&&t[1],r+1);if(i)return[t&&t[0],i]}function oP(e,t,r){const n=En(e)&&ho(t),i=ho(e)&&En(t),o=e===t&&En(t)&&ho(t);if(n||i||o)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function aP(e,t,r){const n=Nf(e)&&ho(t),i=ho(e)&&Nf(t),o=e===t&&Nf(t)&&ho(t);if(n||i||o)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function cP(e,t,r){if(t.tapMerkleRoot){const n=(t.tapLeafScript||[]).every(o=>Uf(o,t.tapMerkleRoot)),i=(e.tapLeafScript||[]).every(o=>Uf(o,t.tapMerkleRoot));if(!n||!i)throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}else if(e.tapMerkleRoot&&!(t.tapLeafScript||[]).every(n=>Uf(n,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}function Uf(e,t){if(!t)return!0;const r=fi({output:e.script,version:e.leafVersion}),n=vf(e.controlBlock,r);return ee(n,t)===0}function uP(e,t){const r=fi({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(n=>ee(n.leafHash,r)===0).map(n=>lP(t.script,n)).sort((n,i)=>i.positionInScript-n.positionInScript).map(n=>n.signature)}function lP(e,t){return Object.assign({positionInScript:aw(t.pubkey,e)},t)}function hP(e,t,r){if(!e.tapScriptSig||!e.tapScriptSig.length)throw new Error(`Can not finalize taproot input #${t}. No tapleaf script signature provided.`);const n=(e.tapLeafScript||[]).sort((i,o)=>i.controlBlock.length-o.controlBlock.length).find(i=>fP(i,e.tapScriptSig,r));if(!n)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return n}function fP(e,t,r){const n=fi({output:e.script,version:e.leafVersion});return(!r||ee(n,r)===0)&&t.find(i=>ee(i.leafHash,n)===0)!==void 0}function ho(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const dP={network:wn,maximumFeeRate:5e3};class dt{constructor(t={},r=new nw(new fw)){ge(this,"data"),ge(this,"__CACHE"),ge(this,"opts"),this.data=r,this.opts=Object.assign({},dP,t),this.__CACHE={__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:this.data.globalMap.unsignedTx.tx,__UNSAFE_SIGN_NONSEGWIT:!1},this.data.inputs.length===0&&this.setVersion(2);const n=(i,o,s,a)=>Object.defineProperty(i,o,{enumerable:s,writable:a});n(this,"__CACHE",!1,!0),n(this,"opts",!1,!0)}static fromBase64(t,r={}){const n=Fg(t);return this.fromBuffer(n,r)}static fromHex(t,r={}){const n=oi(t);return this.fromBuffer(n,r)}static fromBuffer(t,r={}){const n=nw.fromBuffer(t,pP),i=new dt(r,n);return mP(i.__CACHE.__TX,i.__CACHE),i}get inputCount(){return this.data.inputs.length}get version(){return this.__CACHE.__TX.version}set version(t){this.setVersion(t)}get locktime(){return this.__CACHE.__TX.locktime}set locktime(t){this.setLocktime(t)}get txInputs(){return this.__CACHE.__TX.ins.map(t=>({hash:$1(t.hash),index:t.index,sequence:t.sequence}))}get txOutputs(){return this.__CACHE.__TX.outs.map(t=>{let r;try{r=ga(t.script,this.opts.network)}catch{}return{script:$1(t.script),value:t.value,address:r}})}combine(...t){return this.data.combine(...t.map(r=>r.data)),this}clone(){const t=dt.fromBuffer(this.data.toBuffer());return t.opts=JSON.parse(JSON.stringify(this.opts)),t}setMaximumFeeRate(t){Ou(t),this.opts.maximumFeeRate=t}setVersion(t){Ou(t),ba(this.data.inputs,"setVersion");const r=this.__CACHE;return r.__TX.version=t,r.__EXTRACTED_TX=void 0,this}setLocktime(t){Ou(t),ba(this.data.inputs,"setLocktime");const r=this.__CACHE;return r.__TX.locktime=t,r.__EXTRACTED_TX=void 0,this}setInputSequence(t,r){Ou(r),ba(this.data.inputs,"setInputSequence");const n=this.__CACHE;if(n.__TX.ins.length<=t)throw new Error("Input index too high");return n.__TX.ins[t].sequence=r,n.__EXTRACTED_TX=void 0,this}addInputs(t){return t.forEach(r=>this.addInput(r)),this}addInput(t){if(arguments.length>1||!t||t.hash===void 0||t.index===void 0)throw new Error("Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]");lw(t,t,"addInput"),ba(this.data.inputs,"addInput"),t.witnessScript&&$u(t.witnessScript);const r=this.__CACHE;this.data.addInput(t);const n=r.__TX.ins[r.__TX.ins.length-1];ww(r,n);const i=this.data.inputs.length-1,o=this.data.inputs[i];return o.nonWitnessUtxo&&Lf(this.__CACHE,o,i),r.__FEE=void 0,r.__FEE_RATE=void 0,r.__EXTRACTED_TX=void 0,this}addOutputs(t){return t.forEach(r=>this.addOutput(r)),this}addOutput(t){if(arguments.length>1||!t||t.value===void 0||t.address===void 0&&t.script===void 0)throw new Error("Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]");ba(this.data.inputs,"addOutput");const{address:r}=t;if(typeof r=="string"){const{network:i}=this.opts,o=M1(r,i);t=Object.assign({},t,{script:o})}hw(t,t,"addOutput");const n=this.__CACHE;return this.data.addOutput(t),n.__FEE=void 0,n.__FEE_RATE=void 0,n.__EXTRACTED_TX=void 0,this}extractTransaction(t){if(!this.data.inputs.every(pw))throw new Error("Not finalized");const r=this.__CACHE;if(t||gP(this,r,this.opts),r.__EXTRACTED_TX)return r.__EXTRACTED_TX;const n=r.__TX.clone();return Iw(this.data.inputs,n,r,!0),n}getFeeRate(){return Ew("__FEE_RATE","fee rate",this.data.inputs,this.__CACHE)}getFee(){return Ew("__FEE","fee",this.data.inputs,this.__CACHE)}finalizeAllInputs(){return jt(this.data.inputs,0),ma(this.data.inputs.length).forEach(t=>this.finalizeInput(t)),this}finalizeInput(t,r){const n=jt(this.data.inputs,t);return En(n)?this._finalizeTaprootInput(t,n,void 0,r):this._finalizeInput(t,n,r)}finalizeTaprootInput(t,r,n=uw){const i=jt(this.data.inputs,t);if(En(i))return this._finalizeTaprootInput(t,i,r,n);throw new Error(`Cannot finalize input #${t}. Not Taproot.`)}_finalizeInput(t,r,n=vP){const{script:i,isP2SH:o,isP2WSH:s,isSegwit:a}=TP(t,r,this.__CACHE);if(!i)throw new Error(`No script found for input #${t}`);wP(r);const{finalScriptSig:u,finalScriptWitness:f}=n(t,r,i,a,o,s);if(u&&this.data.updateInput(t,{finalScriptSig:u}),f&&this.data.updateInput(t,{finalScriptWitness:f}),!u&&!f)throw new Error(`Unknown error finalizing input #${t}`);return this.data.clearFinalizedInput(t),this}_finalizeTaprootInput(t,r,n,i=uw){if(!r.witnessUtxo)throw new Error(`Cannot finalize input #${t}. Missing withness utxo.`);if(r.tapKeySig){const o=ya({output:r.witnessUtxo.script,signature:r.tapKeySig}),s=Tu(o.witness);this.data.updateInput(t,{finalScriptWitness:s})}else{const{finalScriptWitness:o}=i(t,r,n);this.data.updateInput(t,{finalScriptWitness:o})}return this.data.clearFinalizedInput(t),this}getInputType(t){const r=jt(this.data.inputs,t),n=xw(t,r,this.__CACHE),i=xu(n,t,"input",r.redeemScript||IP(r.finalScriptSig),r.witnessScript||xP(r.finalScriptWitness)),o=i.type==="raw"?"":i.type+"-",s=Cw(i.meaningfulScript);return o+s}inputHasPubkey(t,r){const n=jt(this.data.inputs,t);return PP(r,n,t,this.__CACHE)}inputHasHDKey(t,r){const n=jt(this.data.inputs,t),i=yw(r);return!!n.bip32Derivation&&n.bip32Derivation.some(i)}outputHasPubkey(t,r){const n=wa(this.data.outputs,t);return OP(r,n,t,this.__CACHE)}outputHasHDKey(t,r){const n=wa(this.data.outputs,t),i=yw(r);return!!n.bip32Derivation&&n.bip32Derivation.some(i)}validateSignaturesOfAllInputs(t){return jt(this.data.inputs,0),ma(this.data.inputs.length).map(r=>this.validateSignaturesOfInput(r,t)).reduce((r,n)=>n===!0&&r,!0)}validateSignaturesOfInput(t,r,n){const i=this.data.inputs[t];return En(i)?this.validateSignaturesOfTaprootInput(t,r,n):this._validateSignaturesOfInput(t,r,n)}_validateSignaturesOfInput(t,r,n){const i=this.data.inputs[t],o=(i||{}).partialSig;if(!i||!o||o.length<1)throw new Error("No signatures to validate");if(typeof r!="function")throw new Error("Need validator function to validate signatures");const s=n?o.filter(d=>ee(d.pubkey,n)===0):o;if(s.length<1)throw new Error("No signatures for this pubkey");const a=[];let u,f,h;for(const d of s){const g=oa.decode(d.signature),{hash:v,script:E}=h!==g.hashType?Sw(t,Object.assign({},i,{sighashType:g.hashType}),this.__CACHE,!0):{hash:u,script:f};h=g.hashType,u=v,f=E,gw(d.pubkey,E,"verify"),a.push(r(d.pubkey,v,g.signature))}return a.every(d=>d===!0)}validateSignaturesOfTaprootInput(t,r,n){const i=this.data.inputs[t],o=(i||{}).tapKeySig,s=(i||{}).tapScriptSig;if(!i&&!o&&!(s&&!s.length))throw new Error("No signatures to validate");if(typeof r!="function")throw new Error("Need validator function to validate signatures");n=n&&ku(n);const a=n?Hf(t,i,this.data.inputs,n,this.__CACHE):AP(t,i,this.data.inputs,this.__CACHE);if(!a.length)throw new Error("No signatures for this pubkey");const u=a.find(h=>!h.leafHash);let f=0;if(o&&u){if(!r(u.pubkey,u.hash,_w(o)))return!1;f++}if(s)for(const h of s){const d=a.find(g=>ee(g.pubkey,h.pubkey)===0);if(d){if(!r(h.pubkey,d.hash,_w(h.signature)))return!1;f++}}return f>0}signAllInputsHD(t,r=[_t.SIGHASH_ALL]){if(!t||!t.publicKey||!t.fingerprint)throw new Error("Need HDSigner to sign input");const n=[];for(const i of ma(this.data.inputs.length))try{this.signInputHD(i,t,r),n.push(!0)}catch{n.push(!1)}if(n.every(i=>i===!1))throw new Error("No inputs were signed");return this}signAllInputsHDAsync(t,r=[_t.SIGHASH_ALL]){return new Promise((n,i)=>{if(!t||!t.publicKey||!t.fingerprint)return i(new Error("Need HDSigner to sign input"));const o=[],s=[];for(const a of ma(this.data.inputs.length))s.push(this.signInputHDAsync(a,t,r).then(()=>{o.push(!0)},()=>{o.push(!1)}));return Promise.all(s).then(()=>{if(o.every(a=>a===!1))return i(new Error("No inputs were signed"));n()})})}signInputHD(t,r,n=[_t.SIGHASH_ALL]){if(!r||!r.publicKey||!r.fingerprint)throw new Error("Need HDSigner to sign input");return Pw(t,this.data.inputs,r).forEach(i=>this.signInput(t,i,n)),this}signInputHDAsync(t,r,n=[_t.SIGHASH_ALL]){return new Promise((i,o)=>{if(!r||!r.publicKey||!r.fingerprint)return o(new Error("Need HDSigner to sign input"));const s=Pw(t,this.data.inputs,r).map(a=>this.signInputAsync(t,a,n));return Promise.all(s).then(()=>{i()}).catch(o)})}signAllInputs(t,r){if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const n=[];for(const i of ma(this.data.inputs.length))try{this.signInput(i,t,r),n.push(!0)}catch{n.push(!1)}if(n.every(i=>i===!1))throw new Error("No inputs were signed");return this}signAllInputsAsync(t,r){return new Promise((n,i)=>{if(!t||!t.publicKey)return i(new Error("Need Signer to sign input"));const o=[],s=[];for(const[a]of this.data.inputs.entries())s.push(this.signInputAsync(a,t,r).then(()=>{o.push(!0)},()=>{o.push(!1)}));return Promise.all(s).then(()=>{if(o.every(a=>a===!1))return i(new Error("No inputs were signed"));n()})})}signInput(t,r,n){if(!r||!r.publicKey)throw new Error("Need Signer to sign input");const i=jt(this.data.inputs,t);return En(i)?this._signTaprootInput(t,i,r,void 0,n):this._signInput(t,r,n)}signTaprootInput(t,r,n,i){if(!r||!r.publicKey)throw new Error("Need Signer to sign input");const o=jt(this.data.inputs,t);if(En(o))return this._signTaprootInput(t,o,r,n,i);throw new Error(`Input #${t} is not of type Taproot.`)}_signInput(t,r,n=[_t.SIGHASH_ALL]){const{hash:i,sighashType:o}=Aw(this.data.inputs,t,r.publicKey,this.__CACHE,n),s=[{pubkey:r.publicKey,signature:oa.encode(r.sign(i),o)}];return this.data.updateInput(t,{partialSig:s}),this}_signTaprootInput(t,r,n,i,o=[_t.SIGHASH_DEFAULT]){const s=this.checkTaprootHashesForSig(t,r,n,i,o),a=s.filter(f=>!f.leafHash).map(f=>Pu(n.signSchnorr(f.hash),r.sighashType))[0],u=s.filter(f=>!!f.leafHash).map(f=>({pubkey:ku(n.publicKey),signature:Pu(n.signSchnorr(f.hash),r.sighashType),leafHash:f.leafHash}));return a&&this.data.updateInput(t,{tapKeySig:a}),u.length&&this.data.updateInput(t,{tapScriptSig:u}),this}signInputAsync(t,r,n){return Promise.resolve().then(()=>{if(!r||!r.publicKey)throw new Error("Need Signer to sign input");const i=jt(this.data.inputs,t);return En(i)?this._signTaprootInputAsync(t,i,r,void 0,n):this._signInputAsync(t,r,n)})}signTaprootInputAsync(t,r,n,i){return Promise.resolve().then(()=>{if(!r||!r.publicKey)throw new Error("Need Signer to sign input");const o=jt(this.data.inputs,t);if(En(o))return this._signTaprootInputAsync(t,o,r,n,i);throw new Error(`Input #${t} is not of type Taproot.`)})}_signInputAsync(t,r,n=[_t.SIGHASH_ALL]){const{hash:i,sighashType:o}=Aw(this.data.inputs,t,r.publicKey,this.__CACHE,n);return Promise.resolve(r.sign(i)).then(s=>{const a=[{pubkey:r.publicKey,signature:oa.encode(s,o)}];this.data.updateInput(t,{partialSig:a})})}async _signTaprootInputAsync(t,r,n,i,o=[_t.SIGHASH_DEFAULT]){const s=this.checkTaprootHashesForSig(t,r,n,i,o),a=[],u=s.filter(h=>!h.leafHash)[0];if(u){const h=Promise.resolve(n.signSchnorr(u.hash)).then(d=>({tapKeySig:Pu(d,r.sighashType)}));a.push(h)}const f=s.filter(h=>!!h.leafHash);if(f.length){const h=f.map(d=>Promise.resolve(n.signSchnorr(d.hash)).then(g=>({tapScriptSig:[{pubkey:ku(n.publicKey),signature:Pu(g,r.sighashType),leafHash:d.leafHash}]})));a.push(...h)}return Promise.all(a).then(h=>{h.forEach(d=>this.data.updateInput(t,d))})}checkTaprootHashesForSig(t,r,n,i,o){if(typeof n.signSchnorr!="function")throw new Error(`Need Schnorr Signer to sign taproot input #${t}.`);const s=Hf(t,r,this.data.inputs,n.publicKey,this.__CACHE,i,o);if(!s||!s.length)throw new Error(`Can not sign for input #${t} with the key ${Ee(n.publicKey)}`);return s}toBuffer(){return Rf(this.__CACHE),this.data.toBuffer()}toHex(){return Rf(this.__CACHE),this.data.toHex()}toBase64(){return Rf(this.__CACHE),this.data.toBase64()}updateGlobal(t){return this.data.updateGlobal(t),this}updateInput(t,r){return r.witnessScript&&$u(r.witnessScript),lw(this.data.inputs[t],r,"updateInput"),this.data.updateInput(t,r),r.nonWitnessUtxo&&Lf(this.__CACHE,this.data.inputs[t],t),this}updateOutput(t,r){const n=this.data.outputs[t];return hw(n,r,"updateOutput"),this.data.updateOutput(t,r),this}addUnknownKeyValToGlobal(t){return this.data.addUnknownKeyValToGlobal(t),this}addUnknownKeyValToInput(t,r){return this.data.addUnknownKeyValToInput(t,r),this}addUnknownKeyValToOutput(t,r){return this.data.addUnknownKeyValToOutput(t,r),this}clearFinalizedInput(t){return this.data.clearFinalizedInput(t),this}}const pP=e=>new fw(e);class fw{constructor(t=Uint8Array.from([2,0,0,0,0,0,0,0,0,0])){ge(this,"tx"),this.tx=_t.fromBuffer(t),bP(this.tx),Object.defineProperty(this,"tx",{enumerable:!1,writable:!0})}getInputOutputCounts(){return{inputCount:this.tx.ins.length,outputCount:this.tx.outs.length}}addInput(t){if(t.hash===void 0||t.index===void 0||!(t.hash instanceof Uint8Array)&&typeof t.hash!="string"||typeof t.index!="number")throw new Error("Error adding input.");const r=typeof t.hash=="string"?mf(oi(t.hash)):t.hash;this.tx.addInput(r,t.index,t.sequence)}addOutput(t){if(t.script===void 0||t.value===void 0||!(t.script instanceof Uint8Array)||typeof t.value!="bigint")throw new Error("Error adding output.");this.tx.addOutput(t.script,t.value)}toBuffer(){return this.tx.toBuffer()}}function yP(e,t,r){switch(r){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return dw(1,e.partialSig);case"multisig":const n=pu({output:t});return dw(n.m,e.partialSig,n.pubkeys);default:return!1}}function Rf(e){if(e.__UNSAFE_SIGN_NONSEGWIT!==!1)throw new Error("Not BIP174 compliant, can not export")}function dw(e,t,r){if(!t)return!1;let n;if(r?n=r.map(i=>{const o=$P(i);return t.find(s=>ee(s.pubkey,o)===0)}).filter(i=>!!i):n=t,n.length>e)throw new Error("Too many signatures");return n.length===e}function pw(e){return!!e.finalScriptSig||!!e.finalScriptWitness}function yw(e){return t=>!(ee(e.fingerprint,t.masterFingerprint)||ee(e.derivePath(t.path).publicKey,t.pubkey))}function Ou(e){if(typeof e!="number"||e!==Math.floor(e)||e>4294967295||e<0)throw new Error("Invalid 32 bit integer")}function gP(e,t,r){const n=t.__FEE_RATE||e.getFeeRate(),i=t.__EXTRACTED_TX.virtualSize(),o=n*i;if(n>=r.maximumFeeRate)throw new Error(`Warning: You are paying around ${(o/1e8).toFixed(8)} in fees, which is ${n} satoshi per byte for a transaction with a VSize of ${i} bytes (segwit counted as 0.25 byte per byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.`)}function ba(e,t){e.forEach(r=>{if(En(r)?tP(r,t):Xk(r,t))throw new Error("Can not modify transaction, signatures exist.")})}function wP(e){if(!e.sighashType||!e.partialSig)return;const{partialSig:t,sighashType:r}=e;t.forEach(n=>{const{hashType:i}=oa.decode(n.signature);if(r!==i)throw new Error("Signature sighash does not match input sighash type")})}function gw(e,t,r){if(!_u(e,t))throw new Error(`Can not ${r} for this input with the key ${Ee(e)}`)}function bP(e){if(!e.ins.every(t=>t.script&&t.script.length===0&&t.witness&&t.witness.length===0))throw new Error("Format Error: Transaction ScriptSigs are not empty")}function mP(e,t){e.ins.forEach(r=>{ww(t,r)})}function ww(e,t){const r=Ee(mf(Uint8Array.from(t.hash)))+":"+t.index;if(e.__TX_IN_CACHE[r])throw new Error("Duplicate input detected.");e.__TX_IN_CACHE[r]=1}function bw(e,t){return(r,n,i,o)=>{const s=e({redeem:{output:i}}).output;if(ee(n,s))throw new Error(`${t} for ${o} #${r} doesn't match the scriptPubKey in the prevout`)}}const mw=bw(ao,"Redeem script"),vw=bw(da,"Witness script");function Ew(e,t,r,n){if(!r.every(pw))throw new Error(`PSBT must be finalized to calculate ${t}`);if(e==="__FEE_RATE"&&n.__FEE_RATE)return n.__FEE_RATE;if(e==="__FEE"&&n.__FEE)return n.__FEE;let i,o=!0;if(n.__EXTRACTED_TX?(i=n.__EXTRACTED_TX,o=!1):i=n.__TX.clone(),Iw(r,i,n,o),e==="__FEE_RATE")return n.__FEE_RATE;if(e==="__FEE")return n.__FEE}function vP(e,t,r,n,i,o){const s=Cw(r);if(!yP(t,r,s))throw new Error(`Can not finalize input #${e}`);return EP(r,s,t.partialSig,n,i,o)}function EP(e,t,r,n,i,o){let s,a;const u=SP(e,t,r),f=o?da({redeem:u}):null,h=i?ao({redeem:f||u}):null;return n?(f?a=Tu(f.witness):a=Tu(u.witness),h&&(s=h.input)):h?s=h.input:s=u.input,{finalScriptSig:s,finalScriptWitness:a}}function Aw(e,t,r,n,i){const o=jt(e,t),{hash:s,sighashType:a,script:u}=Sw(t,o,n,!1,i);return gw(r,u,"sign"),{hash:s,sighashType:a}}function Sw(e,t,r,n,i){const o=r.__TX,s=t.sighashType||_t.SIGHASH_ALL;kw(s,i);let a,u;if(t.nonWitnessUtxo){const d=Iu(r,t,e),g=o.ins[e].hash,v=d.getHash();if(ee(g,v)!==0)throw new Error(`Non-witness UTXO hash for input #${e} doesn't match the hash specified in the prevout`);const E=o.ins[e].index;u=d.outs[E]}else if(t.witnessUtxo)u=t.witnessUtxo;else throw new Error("Need a Utxo input item for signing");const{meaningfulScript:f,type:h}=xu(u.script,e,"input",t.redeemScript,t.witnessScript);if(["p2sh-p2wsh","p2wsh"].indexOf(h)>=0)a=o.hashForWitnessV0(e,f,u.value,s);else if(Su(f)){const d=ca({hash:f.slice(2)}).output;a=o.hashForWitnessV0(e,d,u.value,s)}else{if(t.nonWitnessUtxo===void 0&&r.__UNSAFE_SIGN_NONSEGWIT===!1)throw new Error(`Input #${e} has witnessUtxo but non-segwit script: ${Ee(f)}`);!n&&r.__UNSAFE_SIGN_NONSEGWIT!==!1&&console.warn(`Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecessor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.
|
|
32
32
|
*********************
|
|
@@ -54,7 +54,7 @@ PROCEED WITH CAUTION!
|
|
|
54
54
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
55
55
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
56
56
|
PERFORMANCE OF THIS SOFTWARE.
|
|
57
|
-
***************************************************************************** */var db="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";(()=>{const e=Array(256).fill(-1);for(let t=0;t<db.length;++t)e[db.charCodeAt(t)]=t})();var pb,Pd,il,Od=(pb=function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.bech32m=t.bech32=void 0;const r="qpzry9x8gf2tvdw0s3jn54khce6mua7l",n={};for(let d=0;d<32;d++){const g=r.charAt(d);n[g]=d}function i(d){const g=d>>25;return(33554431&d)<<5^996825010&-(g>>0&1)^642813549&-(g>>1&1)^513874426&-(g>>2&1)^1027748829&-(g>>3&1)^705979059&-(g>>4&1)}function o(d){let g=1;for(let v=0;v<d.length;++v){const E=d.charCodeAt(v);if(E<33||E>126)return"Invalid prefix ("+d+")";g=i(g)^E>>5}g=i(g);for(let v=0;v<d.length;++v){const E=d.charCodeAt(v);g=i(g)^31&E}return g}function s(d,g,v,E){let T=0,x=0;const N=(1<<v)-1,I=[];for(let k=0;k<d.length;++k)for(T=T<<g|d[k],x+=g;x>=v;)x-=v,I.push(T>>x&N);if(E)x>0&&I.push(T<<v-x&N);else{if(x>=g)return"Excess padding";if(T<<v-x&N)return"Non-zero padding"}return I}function a(d){return s(d,8,5,!0)}function u(d){const g=s(d,5,8,!1);if(Array.isArray(g))return g}function f(d){const g=s(d,5,8,!1);if(Array.isArray(g))return g;throw new Error(g)}function h(d){let g;function v(E,T){if(T=T||90,E.length<8)return E+" too short";if(E.length>T)return"Exceeds length limit";const x=E.toLowerCase(),N=E.toUpperCase();if(E!==x&&E!==N)return"Mixed-case string "+E;const I=(E=x).lastIndexOf("1");if(I===-1)return"No separator character for "+E;if(I===0)return"Missing prefix for "+E;const k=E.slice(0,I),R=E.slice(I+1);if(R.length<6)return"Data too short";let W=o(k);if(typeof W=="string")return W;const V=[];for(let Be=0;Be<R.length;++Be){const Le=R.charAt(Be),Je=n[Le];if(Je===void 0)return"Unknown character "+Le;W=i(W)^Je,Be+6>=R.length||V.push(Je)}return W!==g?"Invalid checksum for "+E:{prefix:k,words:V}}return g=d==="bech32"?1:734539939,{decodeUnsafe:function(E,T){const x=v(E,T);if(typeof x=="object")return x},decode:function(E,T){const x=v(E,T);if(typeof x=="object")return x;throw new Error(x)},encode:function(E,T,x){if(x=x||90,E.length+7+T.length>x)throw new TypeError("Exceeds length limit");let N=o(E=E.toLowerCase());if(typeof N=="string")throw new Error(N);let I=E+"1";for(let k=0;k<T.length;++k){const R=T[k];if(R>>5)throw new Error("Non 5-bit word");N=i(N)^R,I+=r.charAt(R)}for(let k=0;k<6;++k)N=i(N);N^=g;for(let k=0;k<6;++k)I+=r.charAt(N>>5*(5-k)&31);return I},toWords:a,fromWordsUnsafe:u,fromWords:f}}t.bech32=h("bech32"),t.bech32m=h("bech32m")},pb(Pd={exports:{}},Pd.exports),Pd.exports);(il=Od)&&il.__esModule&&Object.prototype.hasOwnProperty.call(il,"default")&&il.default,Od.bech32m,Od.bech32,new Uint8Array(new Uint16Array([65279]).buffer)[0];var Ao,So;(function(e){e.mainnet="mainnet",e.testnet="testnet",e.regtest="regtest"})(Ao||(Ao={})),function(e){e.p2pkh="p2pkh",e.p2sh="p2sh",e.p2wpkh="p2wpkh",e.p2wsh="p2wsh",e.p2tr="p2tr"}(So||(So={})),So.p2pkh,Ao.mainnet,So.p2pkh,Ao.testnet,So.p2sh,Ao.mainnet,So.p2sh,Ao.testnet;var v$="accountChange";fe({type:yt(v$)});var E$="networkChange";fe({type:yt(E$)});var A$="disconnect";fe({type:yt(A$)});async function Id(e){var t;const r=await(e==null?void 0:e())||((t=window.XverseProviders)==null?void 0:t.BitcoinProvider)||window.BitcoinProvider;if(!r)throw new Error("No Bitcoin wallet installed");return r}var yb=(e=>(e.Mainnet="Mainnet",e.Testnet="Testnet",e.Signet="Signet",e))(yb||{}),xd=_n(qu([be(),Vn(),$s()])),vr=fe({jsonrpc:yt("2.0"),method:be(),params:_n(qu([Tn(Gu()),W2({}),$s()])),id:xd}),sl=(e=>(e[e.PARSE_ERROR=-32700]="PARSE_ERROR",e[e.INVALID_REQUEST=-32600]="INVALID_REQUEST",e[e.METHOD_NOT_FOUND=-32601]="METHOD_NOT_FOUND",e[e.INVALID_PARAMS=-32602]="INVALID_PARAMS",e[e.INTERNAL_ERROR=-32603]="INTERNAL_ERROR",e[e.USER_REJECTION=-32e3]="USER_REJECTION",e[e.METHOD_NOT_SUPPORTED=-32001]="METHOD_NOT_SUPPORTED",e[e.ACCESS_DENIED=-32002]="ACCESS_DENIED",e))(sl||{}),gb=fe({jsonrpc:yt("2.0"),result:Ed(Gu()),id:xd}),wb=fe({jsonrpc:yt("2.0"),error:Ed(Gu()),id:xd});qu([gb,wb]);var ol=(e=>(e.Ordinals="ordinals",e.Payment="payment",e.Stacks="stacks",e))(ol||{}),bb=(e=>(e.p2pkh="p2pkh",e.p2sh="p2sh",e.p2wpkh="p2wpkh",e.p2wsh="p2wsh",e.p2tr="p2tr",e.stacks="stacks",e))(bb||{}),S$=fe({address:be(),publicKey:be(),purpose:xs(ol),addressType:xs(bb)}),mb=async e=>{var t,r;const n=await Id(e.getProvider),{purposes:i}=e.payload;if(!i)throw new Error("Address purposes are required");try{const o=Gr.createUnsecuredToken(e.payload),s=await n.connect(o);(t=e.onFinish)==null||t.call(e,s)}catch(o){console.error("[Connect] Error during address request",o),(r=e.onCancel)==null||r.call(e)}},T$="stx_getAddresses",_$=Cs(fe({message:_n(be())}));fe({...vr.entries,...fe({method:yt(T$),params:_$,id:be()}).entries});var k$="stx_signTransaction",P$=fe({transaction:be(),pubkey:_n(be()),broadcast:_n(z2())});fe({...vr.entries,...fe({method:yt(k$),params:P$,id:be()}).entries});var O$=["software","ledger"],I$=q2(O$),x$="getInfo",$$=Cs($s());fe({version:be(),methods:_n(Tn(be())),supports:Tn(be())}),fe({...vr.entries,...fe({method:yt(x$),params:$$,id:be()}).entries});var C$="getAddresses",N$=fe({purposes:Tn(xs(ol)),message:_n(be())});fe({...vr.entries,...fe({method:yt(C$),params:N$,id:be()}).entries});var B$="signMessage",al=(e=>(e.ECDSA="ECDSA",e.BIP322="BIP322",e))(al||{}),U$=fe({address:be(),message:be(),protocol:_n(xs(al))});fe({signature:be(),messageHash:be(),address:be(),protocol:xs(al)}),fe({...vr.entries,...fe({method:yt(B$),params:U$,id:be()}).entries});var R$="getAccounts",H$=fe({purposes:Tn(xs(ol)),message:_n(be())});Tn(fe({...S$.entries,...fe({walletType:I$}).entries})),fe({...vr.entries,...fe({method:yt(R$),params:H$,id:be()}).entries});var L$="getBalance";Cs($s()),fe({...vr.entries,...fe({method:yt(L$),id:be()}).entries});var K$="wallet_requestPermissions",j$=Ad();yt(!0),fe({...vr.entries,...fe({method:yt(K$),params:j$,id:be()}).entries});var D$="wallet_renouncePermissions",M$=Ad();yt(!0),fe({...vr.entries,...fe({method:yt(D$),params:M$,id:be()}).entries});var F$="wallet_getWalletType";Cs($s()),fe({...vr.entries,...fe({method:yt(F$),id:be()}).entries});var V$="runes_getBalance",z$=Cs($s());fe({balances:Tn(fe({runeName:be(),amount:be(),divisibility:Vn(),symbol:be(),inscriptionId:Cs(be())}))}),fe({...vr.entries,...fe({method:yt(V$),params:z$,id:be()}).entries});var W$="runes_transfer",q$=fe({recipients:Tn(fe({runeName:be(),amount:be(),address:be()}))});fe({...vr.entries,...fe({method:yt(W$),params:q$,id:be()}).entries});var G$="ord_getInscriptions",X$=fe({offset:Vn(),limit:Vn()});fe({total:Vn(),limit:Vn(),offset:Vn(),inscriptions:Tn(fe({inscriptionId:be(),inscriptionNumber:be(),address:be(),collectionName:_n(be()),postage:be(),contentLength:be(),contentType:be(),timestamp:Vn(),offset:Vn(),genesisTransaction:be(),output:be()}))}),fe({...vr.entries,...fe({method:yt(G$),params:X$,id:be()}).entries});var J$="ord_sendInscriptions",Y$=fe({transfers:Tn(fe({address:be(),inscriptionId:be()}))});fe({...vr.entries,...fe({method:yt(J$),params:Y$,id:be()}).entries});var vb=async(e,t,r)=>{var n;let i=((n=window.XverseProviders)==null?void 0:n.BitcoinProvider)||window.BitcoinProvider;if(!i)throw new Error("no wallet provider was found");if(!e)throw new Error("A wallet method is required");const o=await i.request(e,t);return V2(wb,o)?{status:"error",error:o.error}:V2(gb,o)?{status:"success",result:o.result}:{status:"error",error:{code:-32603,message:"Received unknown response from provider.",data:o}}},Z$=async e=>{var t,r;const n=await Id(e.getProvider),{address:i,message:o}=e.payload;if(!i)throw new Error("An address is required to sign a message");if(!o)throw new Error("A message to be signed is required");try{const s=Gr.createUnsecuredToken(e.payload),a=await n.signMessage(s);(t=e.onFinish)==null||t.call(e,a)}catch(s){console.error("[Connect] Error during sign message request",s),(r=e.onCancel)==null||r.call(e)}},Q$=e=>e.map(t=>{const{address:r,amountSats:n}=t;return{address:r,amountSats:n.toString()}}),e7=async e=>{var t,r;const n=await Id(e.getProvider),{recipients:i,senderAddress:o,network:s,message:a}=e.payload;if(!i||i.length===0)throw new Error("At least one recipient is required");if(i.some(u=>typeof u.address!="string"||typeof u.amountSats!="bigint"))throw new Error("Incorrect recipient format");if(!o)throw new Error("The sender address is required");try{const u=Q$(i),f={network:s,senderAddress:o,message:a,recipients:u},h=Gr.createUnsecuredToken(f),d=await n.sendBtcTransaction(h);(t=e.onFinish)==null||t.call(e,d)}catch(u){console.error("[Connect] Error during send BTC transaction request",u),(r=e.onCancel)==null||r.call(e)}};let Eb=e=>e,Ca={},ns={addEventListener(){},removeEventListener(){}};function t7(){try{return typeof localStorage<"u"}catch{return!1}}t7()&&(Ca=localStorage),typeof window<"u"&&(ns={addEventListener(e,t,r){window.addEventListener("storage",t),window.addEventListener("pageshow",r)},removeEventListener(e,t,r){window.removeEventListener("storage",t),window.removeEventListener("pageshow",r)}});function To(e,t={},r={}){let n=r.encode||Eb,i=r.decode||Eb,o=Lg(),s=o.setKey,a=(d,g)=>{typeof g>"u"?(r.listen!==!1&&ns.perKey&&ns.removeEventListener(e+d,f,h),delete Ca[e+d]):(r.listen!==!1&&ns.perKey&&!(d in o.value)&&ns.addEventListener(e+d,f,h),Ca[e+d]=n(g))};o.setKey=(d,g)=>{a(d,g),s(d,g)};let u=o.set;o.set=function(d){for(let g in d)a(g,d[g]);for(let g in o.value)g in d||a(g,void 0);u(d)};function f(d){d.key?d.key.startsWith(e)&&(d.newValue===null?s(d.key.slice(e.length),void 0):s(d.key.slice(e.length),i(d.newValue))):u({})}function h(){let d={...t};for(let g in Ca)g.startsWith(e)&&(d[g.slice(e.length)]=i(Ca[g]));for(let g in d)o.setKey(g,d[g])}return O5(o,()=>{if(h(),r.listen!==!1)return ns.addEventListener(e,f,h),()=>{ns.removeEventListener(e,f,h);for(let d in o.value)ns.removeEventListener(e+d,f,h)}}),o}const Ab=["address","paymentAddress","publicKey","paymentPublicKey","balance"],r7="XVERSE_CONNECTED_WALLET_STATE";class n7 extends Dn{constructor(){super(...arguments),ge(this,"observer"),ge(this,"$valueStore",To(r7,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),ge(this,"removeSubscriber")}get library(){return window.BitcoinProvider}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Ab)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===ii&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Ab.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){gn(this.$store,["provider"],t=>{t.provider!==ii?this.removeSubscriber&&(this.$valueStore.set({address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))}),typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t,r;(t=window==null?void 0:window.XverseProviders)!=null&&t.BitcoinProvider&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[ii]:!0}),(r=this.observer)==null||r.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0}))}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){const{address:r,paymentAddress:n}=this.$valueStore.get();try{if(r){this.restorePersistedValues(),Xt(n,this.network).then(o=>{this.$store.setKey("balance",o)});return}let i=va(this.network||vt);await mb({payload:{purposes:["ordinals","payment"],message:"Address for receiving Ordinals and payments",network:{type:i}},onFinish:o=>{const s=md(o.addresses),a=vd(o.addresses);s&&a&&(this.$store.setKey("provider",ii),this.$store.setKey("address",s.address),this.$store.setKey("paymentAddress",a.address)),this.$store.setKey("publicKey",String(o.addresses[0].publicKey)),this.$store.setKey("paymentPublicKey",String(o.addresses[1].publicKey)),Xt(a.address,this.network).then(u=>{this.$store.setKey("balance",u)})},onCancel:()=>{throw new Error(`User canceled lasereyes to ${ii} wallet`)},onError:o=>{throw new Error(`Can't lasereyes to ${ii} wallet`)}}),this.$store.setKey("connected",!0)}catch(i){throw i}}async requestAccounts(){return[this.$store.get().address,this.$store.get().paymentAddress]}async getNetwork(){const{address:t}=this.$store.get();return t.slice(0,1)==="t"&&[Rt,xr,Ir,$r].includes(this.network)?this.network:vt}getPublicKey(){throw An}async getBalance(){const{paymentAddress:t}=this.$store.get();return await Xt(t,this.network)}getInscriptions(){throw An}async sendBTC(t,r){const n=await vb("sendTransfer",{recipients:[{address:t,amount:r}]});if(n.status==="success")return n.result.txid;throw n.error.code===sl.USER_REJECTION?new Error("User rejected the request"):new Error("Error sending BTC: "+n.error.message)}async signMessage(t,r){const n=r||this.$store.get().paymentAddress,i=await vb("signMessage",{address:n,message:t});if(i.status==="success")return i.result.signature;throw i.error.code===sl.USER_REJECTION?new Error("User rejected the request"):new Error("Error signing message: "+i.error.message)}async signPsbt(t,r,n,i,o){const{address:s,paymentAddress:a}=this.$store.get(),u=dt.fromBase64(String(n),{network:nr(this.network)}),f=u.data.inputs,h=[],d={address:s,signingIndexes:[]},g={address:a,signingIndexes:[]};let v=0;for await(let I of f){if(I.witnessUtxo===void 0)g.signingIndexes.push(Number(v));else{const{script:k}=I.witnessUtxo,R=ga(k,nr(this.network));R===a?g.signingIndexes.push(Number(v)):R===s&&d.signingIndexes.push(Number(v))}v++}d.signingIndexes.length>0&&h.push(d),g.signingIndexes.length>0&&h.push(g);let E,T,x;const N={payload:{network:{type:va(this.network)},message:"Sign Transaction",psbtBase64:u.toBase64(),broadcast:o,inputsToSign:h},onFinish:I=>{if(I.txId)E=I.txId;else if(I.psbtBase64){const k=dt.fromBase64(String(I.psbtBase64),{network:nr(this.network)});T=k.toHex(),x=k.toBase64()}},onCancel:()=>console.log("Canceled")};return await signTransaction(N),{signedPsbtHex:T,signedPsbtBase64:x,txId:E}}pushPsbt(t){throw An}}class i7 extends Dn{constructor(){super(...arguments),ge(this,"observer")}get library(){return window.wizz}get network(){return this.$network.get()}handleNetworkChanged(t){this.parent.connect(As)}handleAccountsChanged(t){if(!t.length){this.parent.disconnect();return}this.$store.get().accounts[0]!==t[0]&&this.$store.setKey("accounts",t)}initialize(){gn(this.$store,["provider"],t=>{t.provider===As?this.addLibraryListeners():this.removeLibraryListeners()}),typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;this.library&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[As]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0}))}removeLibraryListeners(){var t,r;(t=this.library)==null||t.removeListener("networkChanged",this.handleNetworkChanged.bind(this)),(r=this.library)==null||r.removeListener("accountsChanged",this.handleAccountsChanged.bind(this))}addLibraryListeners(){var t,r;(t=this.library)==null||t.on("networkChanged",this.handleNetworkChanged.bind(this)),(r=this.library)==null||r.on("accountsChanged",this.handleAccountsChanged.bind(this))}dispose(){var t;(t=this.observer)==null||t.disconnect(),this.removeLibraryListeners()}async connect(){if(!this.library)throw NP;const t=await this.library.requestAccounts();if(!t)throw new Error("No accounts found");const r=await this.library.getPublicKey();if(!r)throw new Error("No public key found");this.$store.setKey("accounts",t),this.$store.setKey("address",t[0]),this.$store.setKey("paymentAddress",t[0]),this.$store.setKey("publicKey",r),this.$store.setKey("paymentPublicKey",r),this.$store.setKey("provider",As),await this.getNetwork().then(n=>{var i;n&&((i=this.config)==null?void 0:i.network)!==n&&this.parent.switchNetwork(n)}),await this.parent.getBalance(),this.$store.setKey("connected",!0)}async requestAccounts(){return await this.library.requestAccounts()}async getNetwork(){var t;const r=await((t=this.library)==null?void 0:t.getNetwork());return r?Dw(r):void 0}async switchNetwork(t){var r;if(t===$r||t===fo)return await this.library.switchNetwork(Kw);const n=Dw(t);await((r=this.library)==null?void 0:r.switchNetwork(n)),this.$network.set(t),await this.parent.getBalance()}async getPublicKey(){var t;return await((t=this.library)==null?void 0:t.getPublicKey())}async getBalance(){return(await this.library.getBalance()).total}async getInscriptions(){return await this.library.getInscriptions(0,10)}async sendBTC(t,r){var n;const i=await((n=this.library)==null?void 0:n.sendBitcoin(t,r));if(i)return i;throw new Error("Error sending BTC")}async signMessage(t){var r;return await((r=this.library)==null?void 0:r.signMessage(t))}async signPsbt(t,r,n,i,o){var s;const a=await((s=this.library)==null?void 0:s.signPsbt(r,{autoFinalized:i,broadcast:!1})),u=dt.fromHex(a);let f;return i&&o&&(f=await this.pushPsbt(a)),{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:f}}async pushPsbt(t){return await Xe.post(`${pi(this.$network.get())}/api/tx`,t).then(r=>r.data)}}const Sb=["address","paymentAddress","publicKey","paymentPublicKey","balance"],s7="OYL_CONNECTED_WALLET_STATE";class o7 extends Dn{constructor(){super(...arguments),ge(this,"observer"),ge(this,"$valueStore",To(s7,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),ge(this,"removeSubscriber")}get library(){return window.oyl}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Sb)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===ms&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Sb.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;window!=null&&window.oyl&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[ms]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),gn(this.$store,["provider"],t=>{t.provider!==ms?this.removeSubscriber&&(this.$valueStore.set({address:"",publicKey:"",paymentAddress:"",paymentPublicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){if(!this.library)throw new Error("Oyl isn't installed");const{nativeSegwit:r,taproot:n}=await this.library.getAddresses();if(!r||!n)throw new Error("No accounts found");this.$store.setKey("address",n.address),this.$store.setKey("paymentAddress",r.address),this.$store.setKey("publicKey",n.publicKey),this.$store.setKey("paymentPublicKey",r.publicKey),this.$store.setKey("provider",ms),Xt(r.address,this.network).then(o=>{this.$store.setKey("balance",o)}),this.$store.setKey("connected",!0);const i=await this.getBalance();i&&this.$store.setKey("balance",i)}async getNetwork(){return this.network}async sendBTC(t,r){const{psbtHex:n}=await M2(this.$store.get().address,this.$store.get().paymentAddress,t,r,this.$store.get().paymentPublicKey,this.network,7),i=await this.signPsbt("",n,"",!0,!0);if(!i)throw new Error("Error sending BTC");return i.txId}async signMessage(t,r){const n=r||this.$store.get().paymentAddress;return(await this.library.signMessage({address:n,message:t})).signature}async signPsbt(t,r,n,i,o){const{psbt:s,txid:a}=await this.library.signPsbt({psbt:r,finalize:i,broadcast:o}),u=dt.fromHex(s);return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:a}}async pushPsbt(t){return(await this.library.pushPsbt({psbt:t})).txid}async getPublicKey(){var t;return await((t=this.library)==null?void 0:t.getPublicKey())}async getBalance(){const{total:t}=await this.library.getBalance();return this.$store.setKey("balance",t),t}async getInscriptions(){return await this.library.getInscriptions(0,10)}async requestAccounts(){return await this.library.requestAccounts()}async switchNetwork(){throw An}}const Tb=["address","paymentAddress","publicKey","paymentPublicKey","balance"],a7="LEATHER_CONNECTED_WALLET_STATE";class c7 extends Dn{constructor(){super(...arguments),ge(this,"observer"),ge(this,"$valueStore",To(a7,{address:"",publicKey:"",paymentAddress:"",paymentPublicKey:"",balance:""})),ge(this,"removeSubscriber")}get library(){return window.LeatherProvider}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Tb)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===vs&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Tb.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;window!=null&&window.LeatherProvider&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[vs]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),gn(this.$store,["provider"],t=>{t.provider!==vs?this.removeSubscriber&&(this.$valueStore.set({address:"",publicKey:"",paymentAddress:"",paymentPublicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){var r;if(!this.library)throw new Error("Leather isn't installed");const n=await this.library.request("getAddresses");if(!n)throw new Error("No accounts found");const i=n.result.addresses,o=i.map(u=>u.address),s=i.find(u=>u.type===tf),a=i.find(u=>u.type===Kg);if(!(s!=null&&s.publicKey)||!(a!=null&&a.publicKey))throw new Error("No accounts found");if((r=String(s==null?void 0:s.address))!=null&&r.startsWith("tb")&&this.network!==Rt&&this.network!==xr&&this.network!==Ir)throw new Error(`Please switch networks to ${this.network} in the wallet settings.`);this.$store.setKey("accounts",o),this.$store.setKey("address",s.address),this.$store.setKey("paymentAddress",a.address),this.$store.setKey("publicKey",s.publicKey),this.$store.setKey("paymentPublicKey",a.publicKey),this.$store.setKey("provider",vs),Xt(a.address,this.network).then(u=>{this.$store.setKey("balance",u)}),this.$store.setKey("connected",!0)}async getNetwork(){return this.network}async sendBTC(t,r){var n,i;const o=await((n=this.library)==null?void 0:n.request("sendTransfer",{recipients:[{address:t,amount:r}]}));if((i=o==null?void 0:o.result)!=null&&i.txid)return o.result.txid;throw o.error.code===sl.USER_REJECTION?new Error("User rejected the request"):new Error("Error sending BTC: "+o.error.message)}async signMessage(t,r){var n;const i=r===this.$store.get().address?tf:Kg;if(r!==this.$store.get().address&&r!==this.$store.get().paymentAddress)throw new Error("Invalid address to sign message");const o=await this.library.request("signMessage",{message:t,paymentType:i});return(n=o==null?void 0:o.result)==null?void 0:n.signature}async signPsbt(t,r,n,i,o){const s={hex:r,broadcast:!1,network:this.network},a=(await this.library.request("signPsbt",s)).result.hex,u=dt.fromHex(String(a));if(i&&o){const f=u.finalizeAllInputs(),h=await this.pushPsbt(f.toHex());return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:h}}else if(i){const f=u.finalizeAllInputs();return{signedPsbtHex:f.toHex(),signedPsbtBase64:f.toBase64(),txId:void 0}}else return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:void 0}}async pushPsbt(t){const r=dt.fromHex(t).extractTransaction();return await Xe.post(`${pi(this.network)}/api/tx`,r.toHex()).then(n=>n.data)}async getPublicKey(){const{result:t}=await this.library.request("getAddresses"),r=t.addresses.find(n=>n.type===tf);if(!(r!=null&&r.publicKey))throw new Error("No accounts found");return r.publicKey}async getBalance(){const t=await Xt(this.$store.get().paymentAddress,this.network);return this.$store.setKey("balance",t),t.toString()}async getInscriptions(){throw An}async requestAccounts(){const{result:t}=await this.library.request("getAddresses"),r=t.addresses.map(n=>n.address);return this.$store.setKey("accounts",r),r}async switchNetwork(){throw An}}var $d={},_b={},kn={},kb={};Object.defineProperty(kb,"__esModule",{value:!0}),function(e){var t=Te&&Te.__createBinding||(Object.create?function(s,a,u,f){f===void 0&&(f=u);var h=Object.getOwnPropertyDescriptor(a,u);(!h||("get"in h?!a.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(s,f,h)}:function(s,a,u,f){f===void 0&&(f=u),s[f]=a[u]}),r=Te&&Te.__exportStar||function(s,a){for(var u in s)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,s,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.getProviderById=e.getProviders=e.getProviderOrThrow=void 0;async function n(s){var a,u;if(s){const h=await s();if(h)return h}const f=window.OrangeBitcoinProvider||((a=window.OrangecryptoProviders)==null?void 0:a.BitcoinProvider)||((u=window.OrangeWalletProviders)==null?void 0:u.OrangeBitcoinProvider);if(!f)throw new Error("No Orange Bitcoin wallet installed");return f}e.getProviderOrThrow=n;function i(){return window.btc_providers||(window.btc_providers=[]),window.btc_providers}e.getProviders=i;function o(s){var a;if(Array.isArray(window.btc_providers)){const u=window.btc_providers.find(f=>f.id===s);return(a=u==null?void 0:u.id)==null?void 0:a.split(".").reduce((f,h)=>f==null?void 0:f[h],window)}else{console.log("window.btc_providers is not defined or not an array");return}}e.getProviderById=o,r(kb,e)}(kn);var Pb={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.AddressType=e.AddressPurpose=void 0,function(t){t.Ordinals="ordinals",t.Payment="payment",t.Stacks="stacks"}(e.AddressPurpose||(e.AddressPurpose={})),function(t){t.p2pkh="p2pkh",t.p2sh="p2sh",t.p2wpkh="p2wpkh",t.p2wsh="p2wsh",t.p2tr="p2tr",t.stacks="stacks"}(e.AddressType||(e.AddressType={}))})(Pb),function(e){var t=Te&&Te.__createBinding||(Object.create?function(s,a,u,f){f===void 0&&(f=u);var h=Object.getOwnPropertyDescriptor(a,u);(!h||("get"in h?!a.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(s,f,h)}:function(s,a,u,f){f===void 0&&(f=u),s[f]=a[u]}),r=Te&&Te.__exportStar||function(s,a){for(var u in s)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,s,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.getAddress=void 0;const n=Gr,i=kn,o=async s=>{var a,u;const f=await(0,i.getProviderOrThrow)(s.getProvider),{purposes:h}=s.payload;if(!h)throw new Error("Address purposes are required");try{const d=(0,n.createUnsecuredToken)(s.payload),g=await f.connect(d);(a=s.onFinish)==null||a.call(s,g)}catch(d){console.error("[Connect] Error during address request",d),(u=s.onCancel)==null||u.call(s)}};e.getAddress=o,r(Pb,e)}(_b);var Ob={},Ib={},xb={};Object.defineProperty(xb,"__esModule",{value:!0});var $b={};Object.defineProperty($b,"__esModule",{value:!0}),function(e){var t=Te&&Te.__createBinding||(Object.create?function(n,i,o,s){s===void 0&&(s=o);var a=Object.getOwnPropertyDescriptor(i,o);(!a||("get"in a?!i.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return i[o]}}),Object.defineProperty(n,s,a)}:function(n,i,o,s){s===void 0&&(s=o),n[s]=i[o]}),r=Te&&Te.__exportStar||function(n,i){for(var o in n)o!=="default"&&!Object.prototype.hasOwnProperty.call(i,o)&&t(i,n,o)};Object.defineProperty(e,"__esModule",{value:!0}),r(xb,e),r($b,e)}(Ib),function(e){var t=Te&&Te.__createBinding||(Object.create?function(s,a,u,f){f===void 0&&(f=u);var h=Object.getOwnPropertyDescriptor(a,u);(!h||("get"in h?!a.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(s,f,h)}:function(s,a,u,f){f===void 0&&(f=u),s[f]=a[u]}),r=Te&&Te.__exportStar||function(s,a){for(var u in s)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,s,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.request=void 0;const n=kn,i=async(s,a,u)=>{var f;let h=((f=window.OrangecryptoProviders)==null?void 0:f.BitcoinProvider)||window.OrangeBitcoinProvider;if(u&&(h=await(0,n.getProviderById)(u)),!h)throw new Error("no wallet provider was found");if(!s)throw new Error("A wallet method is required");const d=await h.request(s,a);return o(d)?{status:"success",result:d.result}:{status:"error",error:d.error}};e.request=i;const o=s=>Object.hasOwn(s,"result")&&!!s.result;r(Ib,e)}(Ob);var Cb={},Nb={};Object.defineProperty(Nb,"__esModule",{value:!0}),function(e){var t=Te&&Te.__createBinding||(Object.create?function(a,u,f,h){h===void 0&&(h=f);var d=Object.getOwnPropertyDescriptor(u,f);(!d||("get"in d?!u.__esModule:d.writable||d.configurable))&&(d={enumerable:!0,get:function(){return u[f]}}),Object.defineProperty(a,h,d)}:function(a,u,f,h){h===void 0&&(h=f),a[h]=u[f]}),r=Te&&Te.__exportStar||function(a,u){for(var f in a)f!=="default"&&!Object.prototype.hasOwnProperty.call(u,f)&&t(u,a,f)};Object.defineProperty(e,"__esModule",{value:!0}),e.getCapabilities=void 0;const n=Gr,i=kn,o=(a,u)=>{const f=d=>!(!a[d]||u&&!u.has(d)),h={request:f("request"),connect:f("connect"),signMessage:f("signMessage"),signTransaction:f("signTransaction"),sendBtcTransaction:f("sendBtcTransaction"),createInscription:f("createInscription"),createRepeatInscriptions:f("createRepeatInscriptions"),signMultipleTransactions:f("signMultipleTransactions")};return Object.entries(h).reduce((d,[g,v])=>v?[...d,g]:d,[])},s=async a=>{var u,f,h;const d=await(0,i.getProviderOrThrow)(a.getProvider),g=(0,n.createUnsecuredToken)(a.payload);if(d.getCapabilities)try{const v=await d.getCapabilities(g);(u=a.onFinish)==null||u.call(a,o(d,new Set(v)))}catch(v){console.error("[Connect] Error during capabilities request",v)}try{const v=o(d);(f=a.onFinish)==null||f.call(a,v)}catch(v){console.error("[Connect] Error during capabilities request",v),(h=a.onCancel)==null||h.call(a)}};e.getCapabilities=s,r(Nb,e)}(Cb);var Bb={},cl={},Na={};Object.defineProperty(Na,"__esModule",{value:!0}),Na.validateInscriptionPayload=void 0;const u7=4e5,l7=6e4,h7=e=>{const{contentType:t,content:r,payloadType:n,network:i,appFeeAddress:o,appFee:s}=e;if(!/^[a-z]+\/[a-z0-9\-\.\+]+(?=;.*|$)/.test(t))throw new Error("Invalid content type detected");if(!r||r.length===0)throw new Error("Empty content not allowed");if(!n||n!=="BASE_64"&&n!=="PLAIN_TEXT")throw new Error("Empty invalid payloadType specified");if(r.length>(i.type==="Mainnet"?u7:l7))throw new Error("Content too large");if(((o==null?void 0:o.length)??0)>0&&(s??0)<=0)throw new Error("Invalid combination of app fee address and fee provided")};Na.validateInscriptionPayload=h7,Object.defineProperty(cl,"__esModule",{value:!0}),cl.createInscription=void 0;const f7=Gr,d7=kn,p7=Na,y7=async e=>{var t,r;const{getProvider:n}=e,i=await(0,d7.getProviderOrThrow)(n);(0,p7.validateInscriptionPayload)(e.payload);try{const o=(0,f7.createUnsecuredToken)(e.payload),s=await i.createInscription(o);(t=e.onFinish)==null||t.call(e,s)}catch(o){console.error("[Connect] Error during create inscription",o),(r=e.onCancel)==null||r.call(e)}};cl.createInscription=y7;var ul={};Object.defineProperty(ul,"__esModule",{value:!0}),ul.createRepeatInscriptions=void 0;const g7=kn,w7=Gr,b7=Na,m7=async e=>{var t,r;const{getProvider:n}=e,i=await(0,g7.getProviderOrThrow)(n);(0,b7.validateInscriptionPayload)(e.payload);try{const o=(0,w7.createUnsecuredToken)(e.payload),s=await i.createRepeatInscriptions(o);(t=e.onFinish)==null||t.call(e,s)}catch(o){console.error("[Connect] Error during create repeat inscriptions",o),(r=e.onCancel)==null||r.call(e)}};ul.createRepeatInscriptions=m7;var Ub={};Object.defineProperty(Ub,"__esModule",{value:!0}),function(e){var t=Te&&Te.__createBinding||(Object.create?function(n,i,o,s){s===void 0&&(s=o);var a=Object.getOwnPropertyDescriptor(i,o);(!a||("get"in a?!i.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return i[o]}}),Object.defineProperty(n,s,a)}:function(n,i,o,s){s===void 0&&(s=o),n[s]=i[o]}),r=Te&&Te.__exportStar||function(n,i){for(var o in n)o!=="default"&&!Object.prototype.hasOwnProperty.call(i,o)&&t(i,n,o)};Object.defineProperty(e,"__esModule",{value:!0}),r(cl,e),r(ul,e),r(Ub,e)}(Bb);var Rb={},Hb={};Object.defineProperty(Hb,"__esModule",{value:!0}),function(e){var t=Te&&Te.__createBinding||(Object.create?function(s,a,u,f){f===void 0&&(f=u);var h=Object.getOwnPropertyDescriptor(a,u);(!h||("get"in h?!a.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(s,f,h)}:function(s,a,u,f){f===void 0&&(f=u),s[f]=a[u]}),r=Te&&Te.__exportStar||function(s,a){for(var u in s)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,s,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.signMessage=void 0;const n=Gr,i=kn,o=async s=>{var a,u;const f=await(0,i.getProviderOrThrow)(s.getProvider),{address:h,message:d}=s.payload;if(!h)throw new Error("An address is required to sign a message");if(!d)throw new Error("A message to be signed is required");try{const g=(0,n.createUnsecuredToken)(s.payload),v=await f.signMessage(g);(a=s.onFinish)==null||a.call(s,v)}catch(g){console.error("[Connect] Error during sign message request",g),(u=s.onCancel)==null||u.call(s)}};e.signMessage=o,r(Hb,e)}(Rb);var Lb={},ll={};Object.defineProperty(ll,"__esModule",{value:!0}),ll.sendBtcTransaction=void 0;const v7=Gr,E7=kn,A7=e=>e.map(t=>{const{address:r,amountSats:n}=t;return{address:r,amountSats:n.toString()}}),S7=async e=>{var t,r;const n=await(0,E7.getProviderOrThrow)(e.getProvider),{recipients:i,senderAddress:o,network:s,message:a}=e.payload;if(!i||i.length===0)throw new Error("At least one recipient is required");if(i.some(u=>typeof u.address!="string"||typeof u.amountSats!="bigint"))throw new Error("Incorrect recipient format");if(!o)throw new Error("The sender address is required");try{const u=A7(i),f={network:s,senderAddress:o,message:a,recipients:u},h=(0,v7.createUnsecuredToken)(f),d=await n.sendBtcTransaction(h);(t=e.onFinish)==null||t.call(e,d)}catch(u){console.error("[Connect] Error during send BTC transaction request",u),(r=e.onCancel)==null||r.call(e)}};ll.sendBtcTransaction=S7;var hl={};Object.defineProperty(hl,"__esModule",{value:!0}),hl.signTransaction=void 0;const T7=Gr,_7=kn,k7=async e=>{var t,r;const n=await(0,_7.getProviderOrThrow)(e.getProvider),{psbtBase64:i,inputsToSign:o}=e.payload;if(!i)throw new Error("A value for psbtBase64 representing the tx hash is required");if(!o)throw new Error("An array specifying the inputs to be signed by the wallet is required");try{const s=(0,T7.createUnsecuredToken)(e.payload),a=await n.signTransaction(s);(t=e.onFinish)==null||t.call(e,a)}catch(s){console.error("[Connect] Error during sign transaction request",s),(r=e.onCancel)==null||r.call(e)}};hl.signTransaction=k7;var fl={};Object.defineProperty(fl,"__esModule",{value:!0}),fl.signMultipleTransactions=void 0;const P7=Gr,O7=kn,I7=async e=>{var t,r;const n=await(0,O7.getProviderOrThrow)(e.getProvider),{psbts:i}=e.payload;if(!i||!i.length)throw new Error("psbts array is required");if(i.length>100)throw new Error("psbts array must contain less than 100 psbts");try{const o=(0,P7.createUnsecuredToken)(e.payload),s=await n.signMultipleTransactions(o);(t=e.onFinish)==null||t.call(e,s)}catch(o){console.error("[Connect] Error during sign Multiple transactions request",o),(r=e.onCancel)==null||r.call(e)}};fl.signMultipleTransactions=I7;var Kb={};Object.defineProperty(Kb,"__esModule",{value:!0}),function(e){var t=Te&&Te.__createBinding||(Object.create?function(n,i,o,s){s===void 0&&(s=o);var a=Object.getOwnPropertyDescriptor(i,o);(!a||("get"in a?!i.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return i[o]}}),Object.defineProperty(n,s,a)}:function(n,i,o,s){s===void 0&&(s=o),n[s]=i[o]}),r=Te&&Te.__exportStar||function(n,i){for(var o in n)o!=="default"&&!Object.prototype.hasOwnProperty.call(i,o)&&t(i,n,o)};Object.defineProperty(e,"__esModule",{value:!0}),r(ll,e),r(hl,e),r(fl,e),r(Kb,e)}(Lb);var jb={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.RpcErrorCode=e.BitcoinNetworkType=void 0,function(t){t.Mainnet="Mainnet",t.Testnet="Testnet"}(e.BitcoinNetworkType||(e.BitcoinNetworkType={})),function(t){t[t.PARSE_ERROR=-32700]="PARSE_ERROR",t[t.INVALID_REQUEST=-32600]="INVALID_REQUEST",t[t.METHOD_NOT_FOUND=-32601]="METHOD_NOT_FOUND",t[t.INVALID_PARAMS=-32602]="INVALID_PARAMS",t[t.INTERNAL_ERROR=-32603]="INTERNAL_ERROR",t[t.USER_REJECTION=-32e3]="USER_REJECTION",t[t.METHOD_NOT_SUPPORTED=-32001]="METHOD_NOT_SUPPORTED"}(e.RpcErrorCode||(e.RpcErrorCode={}))})(jb),function(e){var t=Te&&Te.__createBinding||(Object.create?function(n,i,o,s){s===void 0&&(s=o);var a=Object.getOwnPropertyDescriptor(i,o);(!a||("get"in a?!i.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return i[o]}}),Object.defineProperty(n,s,a)}:function(n,i,o,s){s===void 0&&(s=o),n[s]=i[o]}),r=Te&&Te.__exportStar||function(n,i){for(var o in n)o!=="default"&&!Object.prototype.hasOwnProperty.call(i,o)&&t(i,n,o)};Object.defineProperty(e,"__esModule",{value:!0}),r(_b,e),r(Ob,e),r(Cb,e),r(Bb,e),r(Rb,e),r(kn,e),r(Lb,e),r(jb,e)}($d);const x7=IT($d),Db=["address","paymentAddress","publicKey","paymentPublicKey","balance"],{signMessage:$7,sendBtcTransaction:C7,signTransaction:N7}=x7,B7="ORANGE_CONNECTED_WALLET_STATE";class U7 extends Dn{constructor(){super(...arguments),ge(this,"observer"),ge(this,"$valueStore",To(B7,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),ge(this,"removeSubscriber")}get library(){var t;return(t=window==null?void 0:window.OrangeWalletProviders)==null?void 0:t.OrangeBitcoinProvider}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Db)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===Mi&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Db.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){var t;typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var r,n;(r=window==null?void 0:window.OrangeWalletProviders)!=null&&r.OrangeBitcoinProvider&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Mi]:!0}),(n=this.observer)==null||n.disconnect())}),(t=this.observer)==null||t.observe(document,{childList:!0,subtree:!0})),gn(this.$store,["provider"],r=>{r.provider!==Mi?this.removeSubscriber&&(this.$valueStore.set({address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){const{address:r,paymentAddress:n}=this.$valueStore.get();try{if(r){this.restorePersistedValues(),Xt(n,this.network).then(s=>{this.$store.setKey("balance",s)});return}let i=Cu(this.network||vt);const o={payload:{purposes:["ordinals","payment"],message:"Address for receiving Ordinals and payments",network:{type:i}},onFinish:s=>{const a=md(s.addresses),u=vd(s.addresses);a&&u&&(this.$store.setKey("publicKey",String(s.addresses[0].publicKey)),this.$store.setKey("paymentPublicKey",String(s.addresses[1].publicKey)),this.$store.setKey("provider",Mi),this.$store.setKey("address",a.address),this.$store.setKey("paymentAddress",u.address)),Xt(u.address,this.network).then(f=>{this.$store.setKey("balance",f)})},onCancel:()=>{throw new Error(`User canceled lasereyes to ${Mi} wallet`)}};await $d.getAddress(o),this.$store.setKey("connected",!0)}catch(i){throw i}}async requestAccounts(){return[this.$store.get().address,this.$store.get().paymentAddress]}async getNetwork(){const{address:t}=this.$store.get();return t.slice(0,1)==="t"&&[Rt,xr,Ir,$r].includes(this.network)?this.network:vt}getPublicKey(){throw An}async getBalance(){const{paymentAddress:t}=this.$store.get();return await Xt(t,this.network)}getInscriptions(){throw An}async sendBTC(t,r){let n="";const i={payload:{network:{type:Cu(this.network)},recipients:[{address:t,amountSats:BigInt(r)}],senderAddress:this.$store.get().paymentAddress},onFinish:o=>{console.log(o),n=o},onCancel:()=>{throw new Error("User canceled the request")}};return await C7(i),n}async signMessage(t,r){let n="";const i=r||this.$store.get().paymentAddress,o={payload:{network:{type:Cu(this.network)},address:i,message:t},onFinish:s=>{n=s},onCancel:()=>alert("Signature request canceled")};return await $7(o),n}async signPsbt(t,r,n,i,o){const s=dt.fromBase64(String(n),{network:nr(this.network)}),a=this.$store.get().address,u=this.$store.get().paymentAddress,f=s.data.inputs,h=[],d={address:a,signingIndexes:[]},g={address:u,signingIndexes:[]};let v=0;for await(let I of f){if(I.witnessUtxo===void 0)g.signingIndexes.push(Number(v));else{const{script:k}=I.witnessUtxo,R=ga(k,nr(this.network));R===u?g.signingIndexes.push(Number(v)):R===a&&d.signingIndexes.push(Number(v))}v++}d.signingIndexes.length>0&&h.push(d),g.signingIndexes.length>0&&h.push(g);let E,T,x;const N={payload:{network:{type:Cu(this.network)},psbtBase64:s.toBase64(),broadcast:o,inputsToSign:h},onFinish:I=>{if(console.log(I),I.txId)E=I.txId;else if(I.psbtBase64){const k=dt.fromBase64(String(I.psbtBase64),{network:nr(this.network)});T=k.toHex(),x=k.toBase64()}},onCancel:()=>console.log("Canceled")};return await N7(N),{signedPsbtHex:T,signedPsbtBase64:x,txId:E}}async pushPsbt(t){let r=t;if(!r.startsWith("02")){const n=dt.fromHex(r);n.finalizeAllInputs(),r=n.extractTransaction().toHex()}return await Xe.post(`${pi(this.network)}/api/tx`,r).then(n=>n.data)}}const Mb=["address","paymentAddress","publicKey","paymentPublicKey","balance"],R7="OKX_CONNECTED_WALLET_STATE";class H7 extends Dn{constructor(){super(...arguments),ge(this,"observer"),ge(this,"$valueStore",To(R7,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),ge(this,"removeSubscriber")}get library(){var t,r;let n;return this.network===Rt||this.network===xr||this.network===Ir||this.network===$r?n=(t=window==null?void 0:window.okxwallet)==null?void 0:t.bitcoinTestnet:(this.network===vt||this.network===fo)&&(n=(r=window==null?void 0:window.okxwallet)==null?void 0:r.bitcoin),n}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Mb)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===Es&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Mb.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){var t;typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var r;this.library&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Es]:!0}),(r=this.observer)==null||r.disconnect())}),(t=this.observer)==null||t.observe(document,{childList:!0,subtree:!0})),gn(this.$store,["provider"],r=>{r.provider!==Es?this.removeSubscriber&&(this.$valueStore.set({address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){var r;try{const n=await this.library.connect();if(!n)throw new Error("No accounts found");this.$store.setKey("address",n.address),this.$store.setKey("paymentAddress",n.address),this.$store.setKey("publicKey",n.publicKey),this.$store.setKey("paymentPublicKey",n.publicKey),this.$store.setKey("accounts",[n]);const i=await((r=this.library)==null?void 0:r.getBalance());this.$store.setKey("balance",i.total),this.$store.setKey("provider",Es),this.$store.setKey("connected",!0)}catch(n){throw n}}async requestAccounts(){const t=this.library,r=this.network;return r===Rt||r===xr||r===$r?await t.connect():await t.requestAccounts()}async getNetwork(){const{address:t}=this.$store.get(),r=this.network;if(t.slice(0,1)==="t")return r===Rt?Rt:r===xr?xr:r===Ir?Ir:r===$r?$r:Rt;const n=await this.library.getNetwork();return MP(n)}async getPublicKey(){const t=this.library;return await(t==null?void 0:t.getPublicKey())}async getBalance(){const{paymentAddress:t}=this.$store.get();return await Xt(t,this.network)}async getInscriptions(){return await this.library.getInscriptions(0,10)}async sendBTC(t,r){const n=await this.library.sendBitcoin(t,r);if(!n)throw new Error("Transaction failed");return n}async signMessage(t,r){const n=this.library;return await(n==null?void 0:n.signMessage(t))}async signPsbt(t,r,n,i,o){const s=await this.library.signPsbt(r,{autoFinalized:i}),a=dt.fromHex(s);if(i&&o){const u=await this.pushPsbt(s);return{signedPsbtHex:a.toHex(),signedPsbtBase64:a.toBase64(),txId:u}}return{signedPsbtHex:a.toHex(),signedPsbtBase64:a.toBase64(),txId:void 0}}async pushPsbt(t){return await Xe.post(`${pi(this.network)}/api/tx`,t).then(r=>r.data)}}const Fb=["address","paymentAddress","publicKey","paymentPublicKey","balance"],L7="MAGIC_EDEN_CONNECTED_WALLET_STATE";class K7 extends Dn{constructor(){super(...arguments),ge(this,"observer"),ge(this,"$valueStore",To(L7,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),ge(this,"removeSubscriber")}get library(){return window.magicEden.bitcoin}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Fb)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===si&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Fb.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;window!=null&&window.magicEden.bitcoin&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[si]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),gn(this.$store,["provider"],t=>{t.provider!==si?this.removeSubscriber&&(this.$valueStore.set({address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){const{address:r,paymentAddress:n}=this.$valueStore.get();try{if(r){this.restorePersistedValues(),Xt(n,this.network).then(o=>{this.$store.setKey("balance",o)});return}let i=va(this.network||vt);await mb({getProvider:async()=>this.library,payload:{purposes:["ordinals","payment"],message:"Address for receiving Ordinals and payments",network:{type:i}},onFinish:o=>{const s=md(o.addresses),a=vd(o.addresses);s&&a&&(this.$store.setKey("provider",si),this.$store.setKey("address",s.address),this.$store.setKey("paymentAddress",a.address)),this.$store.setKey("publicKey",String(o.addresses[0].publicKey)),this.$store.setKey("paymentPublicKey",String(o.addresses[1].publicKey)),Xt(a.address,this.network).then(u=>{this.$store.setKey("balance",u)})},onCancel:()=>{throw new Error(`User canceled lasereyes to ${si} wallet`)},onError:o=>{throw new Error(`Can't lasereyes to ${si} wallet`)}}),this.$store.setKey("connected",!0)}catch(i){throw i}}async requestAccounts(){return[this.$store.get().address,this.$store.get().paymentAddress]}async getNetwork(){const{address:t}=this.$store.get();return t.slice(0,1)==="t"&&[Rt,xr,Ir,$r].includes(this.network)?this.network:vt}getPublicKey(){throw An}async getBalance(){const{paymentAddress:t}=this.$store.get();return await Xt(t,this.network)}getInscriptions(){throw An}async sendBTC(t,r){let n;if(await e7({getProvider:async()=>this.library,payload:{network:{type:va(this.network)},recipients:[{address:t,amountSats:BigInt(r)}],senderAddress:this.$store.get().paymentAddress},onFinish:i=>{n=i},onCancel:()=>alert("Canceled")}),!n)throw new Error("Error sending BTC");return n.txid}async signMessage(t,r){try{const n=r||this.$store.get().paymentAddress;let i="";return await Z$({getProvider:async()=>this.library,payload:{network:{type:yb.Mainnet},address:n,message:t,protocol:al.BIP322},onFinish:o=>{i=o},onCancel:()=>{alert("Request canceled")}}),i}catch(n){throw n}}async signPsbt(t,r,n,i,o){const{address:s,paymentAddress:a}=this.$store.get(),u=dt.fromBase64(String(n),{network:nr(this.network)}),f=u.data.inputs,h=[],d={address:s,signingIndexes:[]},g={address:a,signingIndexes:[]};let v=0;for await(let k of f){const{script:R}=k.witnessUtxo,W=ga(R,nr(this.network));W===a?g.signingIndexes.push(Number(v)):W===s&&d.signingIndexes.push(Number(v)),v++}d.signingIndexes.length>0&&h.push(d),g.signingIndexes.length>0&&h.push(g);let E,T,x;const N=va(this.network),I={getProvider:async()=>this.library,payload:{network:{type:N},message:"Sign Transaction",psbtBase64:u.toBase64(),broadcast:o,inputsToSign:h},onFinish:k=>{if(k.psbtBase64){const R=dt.fromBase64(String(k.psbtBase64),{network:nr(this.network)});T=R.toHex(),x=R.toBase64()}},onCancel:()=>{throw console.log("Canceled"),new Error("User canceled the request")},onError:k=>{throw console.log("error",k),k}};if(await signTransaction(I),o){const k=dt.fromBase64(String(x)).finalizeAllInputs().extractTransaction(),R=await this.pushPsbt(k.toHex());return{signedPsbtHex:k.toHex(),signedPsbtBase64:"test",txId:R}}else return{signedPsbtHex:T,signedPsbtBase64:x,txId:E}}async pushPsbt(t){return await Xe.post(`${pi(this.network)}/api/tx`,t).then(r=>r.data)}}class j7 extends Dn{constructor(){super(...arguments),ge(this,"observer")}get library(){return window.phantom.bitcoin}get network(){return this.$network.get()}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;this.library&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Di]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),gn(this.$store,["provider"],t=>{if(t.provider!==Di){this.removeListeners();return}this.library.requestAccounts().then(r=>{this.handleAccountsChanged(r)}),this.addListeners()})}addListeners(){this.library.on("accountsChanged",this.handleAccountsChanged.bind(this)),this.library.on("networkChanged",this.handleNetworkChanged.bind(this))}removeListeners(){this.library.removeListener("accountsChanged",this.handleAccountsChanged.bind(this)),this.library.removeListener("networkChanged",this.handleNetworkChanged.bind(this))}dispose(){var t;(t=this.observer)==null||t.disconnect(),this.removeListeners()}handleAccountsChanged(t){if(!t.length){this.parent.disconnect();return}this.$store.get().accounts[0]!==t[0]&&(this.$store.setKey("accounts",t),t.length>0?this.parent.connect(Di):this.parent.disconnect())}handleNetworkChanged(t){const r=Ea(t);this.network!==r&&this.switchNetwork(r),this.parent.connect(Di)}async connect(t){if(!this.library)throw new Error("Unisat isn't installed");const r=await this.library.requestAccounts();if(console.log("phantomAccounts",r),!r)throw new Error("No accounts found");this.$store.setKey("accounts",r);const n=r.find(o=>o.purpose==="ordinals"),i=r.find(o=>o.purpose==="payment");this.$store.setKey("address",n.address),this.$store.setKey("paymentAddress",i.address),this.$store.setKey("publicKey",n.publicKey),this.$store.setKey("paymentPublicKey",i.publicKey),this.$store.setKey("provider",Di),Xt(r[0],this.network).then(o=>{this.$store.setKey("balance",o)}),this.$store.setKey("connected",!0)}async getNetwork(){return this.$store.get().address.slice(0,1)==="t"?Rt:vt}async sendBTC(t,r){const{psbtHex:n}=await M2(this.$store.get().address,this.$store.get().paymentAddress,t,r,this.$store.get().paymentPublicKey,this.network,7),i=await this.signPsbt("",n,"",!0,!0);if(!i)throw new Error("Error sending BTC");return i.txId}async signMessage(t,r){var n;const i=new TextEncoder().encode(t),o=new Uint8Array(i),s=r||this.$store.get().paymentAddress,a=await((n=this.library)==null?void 0:n.signMessage(s,o)),u=String.fromCharCode(...a.signature);return btoa(u)}async signPsbt(t,r,n,i,o){const{address:s,paymentAddress:a}=this.$store.get(),u=dt.fromHex(String(r),{network:nr(this.network)}).data.inputs,f=[],h={address:s,signingIndexes:[]},d={address:a,signingIndexes:[]};let g=0;for await(let T of u){const{script:x}=T.witnessUtxo,N=ga(x,nr(this.network));N===a?d.signingIndexes.push(Number(g)):N===s&&h.signingIndexes.push(Number(g)),g++}h.signingIndexes.length>0&&f.push(h),d.signingIndexes.length>0&&f.push(d);const v=await this.library.signPsbt(r,{inputsToSign:f}),E=dt.fromHex(v);if(i&&o){const T=await this.pushPsbt(v);return{signedPsbtHex:E.toHex(),signedPsbtBase64:E.toBase64(),txId:T}}return{signedPsbtHex:E.toHex(),signedPsbtBase64:E.toBase64(),txId:void 0}}async pushPsbt(t){return await Xe.post(`${pi(this.network)}/api/tx`,t).then(r=>r.data)}async getPublicKey(){return this.$store.get().publicKey}async getBalance(){return(await this.library.getBalance()).total}async getInscriptions(){return await this.library.getInscriptions(0,10)}async requestAccounts(){return await this.library.requestAccounts()}async switchNetwork(t){var r;const n=Df(t);await((r=this.library)==null?void 0:r.switchChain(n)),this.$network.set(t),await this.getBalance()}}class D7 extends Dn{constructor(){super(...arguments),ge(this,"observer")}get library(){return window.opnet}get network(){return this.$network.get()}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;this.library&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Fi]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),gn(this.$store,["provider"],t=>{if(t.provider!==Fi){this.removeListeners();return}this.library.getAccounts().then(r=>{this.handleAccountsChanged(r)}),this.addListeners()})}addListeners(){this.library.on("accountsChanged",this.handleAccountsChanged.bind(this)),this.library.on("networkChanged",this.handleNetworkChanged.bind(this))}removeListeners(){this.library.removeListener("accountsChanged",this.handleAccountsChanged.bind(this)),this.library.removeListener("networkChanged",this.handleNetworkChanged.bind(this))}dispose(){var t;(t=this.observer)==null||t.disconnect(),this.removeListeners()}handleAccountsChanged(t){if(!t.length){this.parent.disconnect();return}this.$store.get().accounts[0]!==t[0]&&(this.$store.setKey("accounts",t),t.length>0?this.parent.connect(Fi):this.parent.disconnect())}handleNetworkChanged(t){const r=Ea(t);this.network!==r&&this.switchNetwork(r),this.parent.connect(Fi)}async connect(t){if(!this.library)throw new Error("OP_NET isn't installed");const r=await this.library.requestAccounts();if(!r)throw new Error("No accounts found");const n=await this.library.getPublicKey();if(!n)throw new Error("No public key found");this.$store.setKey("accounts",r),this.$store.setKey("address",r[0]),this.$store.setKey("paymentAddress",r[0]),this.$store.setKey("publicKey",n),this.$store.setKey("paymentPublicKey",n),this.$store.setKey("provider",Fi),await this.getNetwork().then(i=>{var o;((o=this.config)==null?void 0:o.network)!==i&&this.switchNetwork(i)}),Xt(r[0],this.network).then(i=>{this.$store.setKey("balance",i)}),this.$store.setKey("connected",!0)}async getNetwork(){var t;const r=await((t=this.library)==null?void 0:t.getChain());return r?Ea(r.enum):this.network}async sendBTC(t,r){var n;const i=await((n=this.library)==null?void 0:n.sendBitcoin(t,r));if(!i)throw new Error("Transaction failed");return i}async signMessage(t,r){var n;return await((n=this.library)==null?void 0:n.signMessage(t))}async signPsbt(t,r,n,i,o){var s;const a=await((s=this.library)==null?void 0:s.signPsbt(r,{autoFinalized:i})),u=dt.fromHex(a);if(i&&o){const f=await this.pushPsbt(a);return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:f}}return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:void 0}}async pushPsbt(t){return await Xe.post(`${pi(this.network)}/api/tx`,t).then(r=>r.data)}async getPublicKey(){var t;return await((t=this.library)==null?void 0:t.getPublicKey())}async getBalance(){return(await this.library.getBalance()).total}async getInscriptions(){return await this.library.getInscriptions(0,10)}async requestAccounts(){return await this.library.requestAccounts()}async switchNetwork(t){var r;const n=Df(t);await((r=this.library)==null?void 0:r.switchChain(n)),this.$network.set(t),await this.getBalance()}}class M7{constructor(t,r){ge(this,"$store"),ge(this,"$network"),ge(this,"$providerMap"),this.config=r,this.$store=t.$store,this.$network=t.$network,this.$providerMap={[vs]:new c7(t,this,r),[si]:new K7(t,this,r),[Es]:new H7(t,this,r),[Fi]:new D7(t,this,r),[Mi]:new U7(t,this,r),[ms]:new o7(t,this,r),[Di]:new j7(t,this,r),[ji]:new zx(t,this,r),[ii]:new n7(t,this,r),[As]:new i7(t,this,r)},this.$network.subscribe(this.watchNetworkChange.bind(this)),Hg(this.$store,["isInitializing"],n=>this.handleIsInitializingChanged(n.isInitializing)),r&&r.network&&(this.$network.set(r.network),this.getNetwork().then(n=>{try{r.network!==n&&this.switchNetwork(r.network)}catch{this.disconnect()}})),Hg(this.$store,["hasProvider"],this.checkInitializationComplete.bind(this)),Wx()}dispose(){Object.values(this.$providerMap).forEach(t=>t==null?void 0:t.dispose())}handleIsInitializingChanged(t){if(typeof window<"u"&&typeof localStorage<"u"&&!t){const r=localStorage==null?void 0:localStorage.getItem(rf);r&&(this.$store.setKey("provider",r),this.connect(r))}}async connect(t){this.$store.setKey("isConnecting",!0);try{if(localStorage==null||localStorage.setItem(rf,t),!this.$providerMap[t])throw new Error("Unsupported wallet provider");const r=this.$providerMap[t];await(r==null?void 0:r.connect(t)),this.$store.setKey("connected",!0)}catch(r){throw console.error(r),this.$store.setKey("isConnecting",!1),this.disconnect(),r}finally{this.$store.setKey("isConnecting",!1)}}async requestAccounts(){var t;if(!this.$store.get().provider)throw new Error("No wallet provider connected");if(!this.$providerMap[this.$store.get().provider])throw new Error("The connected wallet doesn't support this method");try{return await((t=this.$providerMap[this.$store.get().provider])==null?void 0:t.requestAccounts())}catch(r){throw r instanceof Error&&r.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support this method"):r}}disconnect(){this.$store.setKey("connected",!1),this.$store.setKey("provider",void 0),this.$store.setKey("address",""),this.$store.setKey("paymentAddress",""),this.$store.setKey("publicKey",""),this.$store.setKey("paymentPublicKey",""),this.$store.setKey("balance",void 0),this.$store.setKey("accounts",[]),localStorage==null||localStorage.removeItem(rf)}switchNetwork(t){var r;try{this.$store.get().provider&&((r=this.$providerMap[this.$store.get().provider])==null||r.switchNetwork(t))}catch(n){throw n instanceof Error&&n.message.toLowerCase().includes("not implemented")?(this.disconnect(),new Error("The connected wallet doesn't support programmatic network changes..")):n}}checkInitializationComplete(){Object.values(this.$store.get().hasProvider).every(t=>t!==void 0)&&this.$store.setKey("isInitializing",!1)}watchNetworkChange(){this.$store.setKey("balance",void 0)}async getNetwork(){var t;return this.$store.get().provider&&this.$providerMap[this.$store.get().provider]?await((t=this.$providerMap[this.$store.get().provider])==null?void 0:t.getNetwork()):this.$network.get()}async sendBTC(t,r){var n;if(r<=0)throw new Error("Amount must be greater than 0");if(!Number.isInteger(r))throw new Error("Amount must be an integer");if(!this.$store.get().provider)throw new Error("No wallet connected");if(this.$providerMap[this.$store.get().provider])try{return await((n=this.$providerMap[this.$store.get().provider])==null?void 0:n.sendBTC(t,r))}catch(i){throw i instanceof Error&&i.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support sending BTC..."):i}}async signMessage(t,r){var n;if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((n=this.$providerMap[this.$store.get().provider])==null?void 0:n.signMessage(t,r))}catch(i){throw i instanceof Error&&i.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support message signing..."):i}}async signPsbt(t,r=!1,n=!1){var i;let o,s;if(!t)throw new Error("No PSBT provided");if(Mx(t))s=dt.fromHex(t).toBase64(),o=t;else if(Dx(t))s=t,o=dt.fromBase64(t).toHex();else throw new Error("Invalid PSBT format");if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((i=this.$providerMap[this.$store.get().provider])==null?void 0:i.signPsbt(t,o,s,r,n))}catch(a){throw a instanceof Error&&a.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support PSBT signing..."):a}else throw new Error("No wallet provider connected")}async pushPsbt(t){var r;if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((r=this.$providerMap[this.$store.get().provider])==null?void 0:r.pushPsbt(t))}catch(n){throw n instanceof Error&&n.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support PSBT signing..."):n}}async getPublicKey(){var t;if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((t=this.$providerMap[this.$store.get().provider])==null?void 0:t.getPublicKey())}catch(r){throw r instanceof Error&&r.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support this method"):r}}async getBalance(){if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{const t=await this.$providerMap[this.$store.get().provider].getBalance();return this.$store.setKey("balance",BigInt(t)),t}catch(t){throw t instanceof Error&&t.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support this method"):t}}async getInscriptions(){var t;if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((t=this.$providerMap[this.$store.get().provider])==null?void 0:t.getInscriptions())}catch(r){throw r instanceof Error&&r.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support this method"):r}}}const F7={hasUnisat:!1,hasXverse:!1,hasOyl:!1,hasMagicEden:!1,hasOkx:!1,hasOrange:!1,hasOpNet:!1,hasLeather:!1,hasPhantom:!1,hasWizz:!1,isInitializing:!0,connected:!1,isConnecting:!1,publicKey:"",address:"",paymentAddress:"",paymentPublicKey:"",balance:void 0,network:vt,library:null,provider:null,accounts:[],connect:async e=>{},disconnect:()=>{},requestAccounts:async()=>[],getNetwork:async()=>vt,switchNetwork:async e=>{},getPublicKey:async()=>"",getBalance:async()=>"",getInscriptions:async()=>[],sendBTC:async(e,t)=>"",signMessage:async e=>"",signPsbt:async e=>({signedPsbtHex:"",signedPsbtBase64:"",txId:""}),pushPsbt:async e=>"",inscribe:async e=>"",isCreatingCommit:!1,isInscribing:!1},Vb=tn.createContext(F7),V7=()=>tn.useContext(Vb);var Cd={exports:{}},Ba={};/**
|
|
57
|
+
***************************************************************************** */var db="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";(()=>{const e=Array(256).fill(-1);for(let t=0;t<db.length;++t)e[db.charCodeAt(t)]=t})();var pb,Pd,il,Od=(pb=function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.bech32m=t.bech32=void 0;const r="qpzry9x8gf2tvdw0s3jn54khce6mua7l",n={};for(let d=0;d<32;d++){const g=r.charAt(d);n[g]=d}function i(d){const g=d>>25;return(33554431&d)<<5^996825010&-(g>>0&1)^642813549&-(g>>1&1)^513874426&-(g>>2&1)^1027748829&-(g>>3&1)^705979059&-(g>>4&1)}function o(d){let g=1;for(let v=0;v<d.length;++v){const E=d.charCodeAt(v);if(E<33||E>126)return"Invalid prefix ("+d+")";g=i(g)^E>>5}g=i(g);for(let v=0;v<d.length;++v){const E=d.charCodeAt(v);g=i(g)^31&E}return g}function s(d,g,v,E){let T=0,x=0;const N=(1<<v)-1,I=[];for(let k=0;k<d.length;++k)for(T=T<<g|d[k],x+=g;x>=v;)x-=v,I.push(T>>x&N);if(E)x>0&&I.push(T<<v-x&N);else{if(x>=g)return"Excess padding";if(T<<v-x&N)return"Non-zero padding"}return I}function a(d){return s(d,8,5,!0)}function u(d){const g=s(d,5,8,!1);if(Array.isArray(g))return g}function f(d){const g=s(d,5,8,!1);if(Array.isArray(g))return g;throw new Error(g)}function h(d){let g;function v(E,T){if(T=T||90,E.length<8)return E+" too short";if(E.length>T)return"Exceeds length limit";const x=E.toLowerCase(),N=E.toUpperCase();if(E!==x&&E!==N)return"Mixed-case string "+E;const I=(E=x).lastIndexOf("1");if(I===-1)return"No separator character for "+E;if(I===0)return"Missing prefix for "+E;const k=E.slice(0,I),R=E.slice(I+1);if(R.length<6)return"Data too short";let W=o(k);if(typeof W=="string")return W;const V=[];for(let Be=0;Be<R.length;++Be){const Le=R.charAt(Be),Je=n[Le];if(Je===void 0)return"Unknown character "+Le;W=i(W)^Je,Be+6>=R.length||V.push(Je)}return W!==g?"Invalid checksum for "+E:{prefix:k,words:V}}return g=d==="bech32"?1:734539939,{decodeUnsafe:function(E,T){const x=v(E,T);if(typeof x=="object")return x},decode:function(E,T){const x=v(E,T);if(typeof x=="object")return x;throw new Error(x)},encode:function(E,T,x){if(x=x||90,E.length+7+T.length>x)throw new TypeError("Exceeds length limit");let N=o(E=E.toLowerCase());if(typeof N=="string")throw new Error(N);let I=E+"1";for(let k=0;k<T.length;++k){const R=T[k];if(R>>5)throw new Error("Non 5-bit word");N=i(N)^R,I+=r.charAt(R)}for(let k=0;k<6;++k)N=i(N);N^=g;for(let k=0;k<6;++k)I+=r.charAt(N>>5*(5-k)&31);return I},toWords:a,fromWordsUnsafe:u,fromWords:f}}t.bech32=h("bech32"),t.bech32m=h("bech32m")},pb(Pd={exports:{}},Pd.exports),Pd.exports);(il=Od)&&il.__esModule&&Object.prototype.hasOwnProperty.call(il,"default")&&il.default,Od.bech32m,Od.bech32,new Uint8Array(new Uint16Array([65279]).buffer)[0];var Ao,So;(function(e){e.mainnet="mainnet",e.testnet="testnet",e.regtest="regtest"})(Ao||(Ao={})),function(e){e.p2pkh="p2pkh",e.p2sh="p2sh",e.p2wpkh="p2wpkh",e.p2wsh="p2wsh",e.p2tr="p2tr"}(So||(So={})),So.p2pkh,Ao.mainnet,So.p2pkh,Ao.testnet,So.p2sh,Ao.mainnet,So.p2sh,Ao.testnet;var v$="accountChange";fe({type:yt(v$)});var E$="networkChange";fe({type:yt(E$)});var A$="disconnect";fe({type:yt(A$)});async function Id(e){var t;const r=await(e==null?void 0:e())||((t=window.XverseProviders)==null?void 0:t.BitcoinProvider)||window.BitcoinProvider;if(!r)throw new Error("No Bitcoin wallet installed");return r}var yb=(e=>(e.Mainnet="Mainnet",e.Testnet="Testnet",e.Signet="Signet",e))(yb||{}),xd=_n(qu([be(),Vn(),$s()])),vr=fe({jsonrpc:yt("2.0"),method:be(),params:_n(qu([Tn(Gu()),W2({}),$s()])),id:xd}),sl=(e=>(e[e.PARSE_ERROR=-32700]="PARSE_ERROR",e[e.INVALID_REQUEST=-32600]="INVALID_REQUEST",e[e.METHOD_NOT_FOUND=-32601]="METHOD_NOT_FOUND",e[e.INVALID_PARAMS=-32602]="INVALID_PARAMS",e[e.INTERNAL_ERROR=-32603]="INTERNAL_ERROR",e[e.USER_REJECTION=-32e3]="USER_REJECTION",e[e.METHOD_NOT_SUPPORTED=-32001]="METHOD_NOT_SUPPORTED",e[e.ACCESS_DENIED=-32002]="ACCESS_DENIED",e))(sl||{}),gb=fe({jsonrpc:yt("2.0"),result:Ed(Gu()),id:xd}),wb=fe({jsonrpc:yt("2.0"),error:Ed(Gu()),id:xd});qu([gb,wb]);var ol=(e=>(e.Ordinals="ordinals",e.Payment="payment",e.Stacks="stacks",e))(ol||{}),bb=(e=>(e.p2pkh="p2pkh",e.p2sh="p2sh",e.p2wpkh="p2wpkh",e.p2wsh="p2wsh",e.p2tr="p2tr",e.stacks="stacks",e))(bb||{}),S$=fe({address:be(),publicKey:be(),purpose:xs(ol),addressType:xs(bb)}),mb=async e=>{var t,r;const n=await Id(e.getProvider),{purposes:i}=e.payload;if(!i)throw new Error("Address purposes are required");try{const o=Gr.createUnsecuredToken(e.payload),s=await n.connect(o);(t=e.onFinish)==null||t.call(e,s)}catch(o){console.error("[Connect] Error during address request",o),(r=e.onCancel)==null||r.call(e)}},T$="stx_getAddresses",_$=Cs(fe({message:_n(be())}));fe({...vr.entries,...fe({method:yt(T$),params:_$,id:be()}).entries});var k$="stx_signTransaction",P$=fe({transaction:be(),pubkey:_n(be()),broadcast:_n(z2())});fe({...vr.entries,...fe({method:yt(k$),params:P$,id:be()}).entries});var O$=["software","ledger"],I$=q2(O$),x$="getInfo",$$=Cs($s());fe({version:be(),methods:_n(Tn(be())),supports:Tn(be())}),fe({...vr.entries,...fe({method:yt(x$),params:$$,id:be()}).entries});var C$="getAddresses",N$=fe({purposes:Tn(xs(ol)),message:_n(be())});fe({...vr.entries,...fe({method:yt(C$),params:N$,id:be()}).entries});var B$="signMessage",al=(e=>(e.ECDSA="ECDSA",e.BIP322="BIP322",e))(al||{}),U$=fe({address:be(),message:be(),protocol:_n(xs(al))});fe({signature:be(),messageHash:be(),address:be(),protocol:xs(al)}),fe({...vr.entries,...fe({method:yt(B$),params:U$,id:be()}).entries});var R$="getAccounts",H$=fe({purposes:Tn(xs(ol)),message:_n(be())});Tn(fe({...S$.entries,...fe({walletType:I$}).entries})),fe({...vr.entries,...fe({method:yt(R$),params:H$,id:be()}).entries});var L$="getBalance";Cs($s()),fe({...vr.entries,...fe({method:yt(L$),id:be()}).entries});var K$="wallet_requestPermissions",j$=Ad();yt(!0),fe({...vr.entries,...fe({method:yt(K$),params:j$,id:be()}).entries});var D$="wallet_renouncePermissions",M$=Ad();yt(!0),fe({...vr.entries,...fe({method:yt(D$),params:M$,id:be()}).entries});var F$="wallet_getWalletType";Cs($s()),fe({...vr.entries,...fe({method:yt(F$),id:be()}).entries});var V$="runes_getBalance",z$=Cs($s());fe({balances:Tn(fe({runeName:be(),amount:be(),divisibility:Vn(),symbol:be(),inscriptionId:Cs(be())}))}),fe({...vr.entries,...fe({method:yt(V$),params:z$,id:be()}).entries});var W$="runes_transfer",q$=fe({recipients:Tn(fe({runeName:be(),amount:be(),address:be()}))});fe({...vr.entries,...fe({method:yt(W$),params:q$,id:be()}).entries});var G$="ord_getInscriptions",X$=fe({offset:Vn(),limit:Vn()});fe({total:Vn(),limit:Vn(),offset:Vn(),inscriptions:Tn(fe({inscriptionId:be(),inscriptionNumber:be(),address:be(),collectionName:_n(be()),postage:be(),contentLength:be(),contentType:be(),timestamp:Vn(),offset:Vn(),genesisTransaction:be(),output:be()}))}),fe({...vr.entries,...fe({method:yt(G$),params:X$,id:be()}).entries});var J$="ord_sendInscriptions",Y$=fe({transfers:Tn(fe({address:be(),inscriptionId:be()}))});fe({...vr.entries,...fe({method:yt(J$),params:Y$,id:be()}).entries});var vb=async(e,t,r)=>{var n;let i=((n=window.XverseProviders)==null?void 0:n.BitcoinProvider)||window.BitcoinProvider;if(!i)throw new Error("no wallet provider was found");if(!e)throw new Error("A wallet method is required");const o=await i.request(e,t);return V2(wb,o)?{status:"error",error:o.error}:V2(gb,o)?{status:"success",result:o.result}:{status:"error",error:{code:-32603,message:"Received unknown response from provider.",data:o}}},Z$=async e=>{var t,r;const n=await Id(e.getProvider),{address:i,message:o}=e.payload;if(!i)throw new Error("An address is required to sign a message");if(!o)throw new Error("A message to be signed is required");try{const s=Gr.createUnsecuredToken(e.payload),a=await n.signMessage(s);(t=e.onFinish)==null||t.call(e,a)}catch(s){console.error("[Connect] Error during sign message request",s),(r=e.onCancel)==null||r.call(e)}},Q$=e=>e.map(t=>{const{address:r,amountSats:n}=t;return{address:r,amountSats:n.toString()}}),e7=async e=>{var t,r;const n=await Id(e.getProvider),{recipients:i,senderAddress:o,network:s,message:a}=e.payload;if(!i||i.length===0)throw new Error("At least one recipient is required");if(i.some(u=>typeof u.address!="string"||typeof u.amountSats!="bigint"))throw new Error("Incorrect recipient format");if(!o)throw new Error("The sender address is required");try{const u=Q$(i),f={network:s,senderAddress:o,message:a,recipients:u},h=Gr.createUnsecuredToken(f),d=await n.sendBtcTransaction(h);(t=e.onFinish)==null||t.call(e,d)}catch(u){console.error("[Connect] Error during send BTC transaction request",u),(r=e.onCancel)==null||r.call(e)}};let Eb=e=>e,Ca={},ns={addEventListener(){},removeEventListener(){}};function t7(){try{return typeof localStorage<"u"}catch{return!1}}t7()&&(Ca=localStorage),typeof window<"u"&&(ns={addEventListener(e,t,r){window.addEventListener("storage",t),window.addEventListener("pageshow",r)},removeEventListener(e,t,r){window.removeEventListener("storage",t),window.removeEventListener("pageshow",r)}});function To(e,t={},r={}){let n=r.encode||Eb,i=r.decode||Eb,o=Lg(),s=o.setKey,a=(d,g)=>{typeof g>"u"?(r.listen!==!1&&ns.perKey&&ns.removeEventListener(e+d,f,h),delete Ca[e+d]):(r.listen!==!1&&ns.perKey&&!(d in o.value)&&ns.addEventListener(e+d,f,h),Ca[e+d]=n(g))};o.setKey=(d,g)=>{a(d,g),s(d,g)};let u=o.set;o.set=function(d){for(let g in d)a(g,d[g]);for(let g in o.value)g in d||a(g,void 0);u(d)};function f(d){d.key?d.key.startsWith(e)&&(d.newValue===null?s(d.key.slice(e.length),void 0):s(d.key.slice(e.length),i(d.newValue))):u({})}function h(){let d={...t};for(let g in Ca)g.startsWith(e)&&(d[g.slice(e.length)]=i(Ca[g]));for(let g in d)o.setKey(g,d[g])}return O5(o,()=>{if(h(),r.listen!==!1)return ns.addEventListener(e,f,h),()=>{ns.removeEventListener(e,f,h);for(let d in o.value)ns.removeEventListener(e+d,f,h)}}),o}const Ab=["address","paymentAddress","publicKey","paymentPublicKey","balance"],r7="XVERSE_CONNECTED_WALLET_STATE";class n7 extends Dn{constructor(){super(...arguments),ge(this,"observer"),ge(this,"$valueStore",To(r7,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),ge(this,"removeSubscriber")}get library(){return window==null?void 0:window.BitcoinProvider}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Ab)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===ii&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Ab.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){gn(this.$store,["provider"],t=>{t.provider!==ii?this.removeSubscriber&&(this.$valueStore.set({address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))}),typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t,r;(t=window==null?void 0:window.XverseProviders)!=null&&t.BitcoinProvider&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[ii]:!0}),(r=this.observer)==null||r.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0}))}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){const{address:r,paymentAddress:n}=this.$valueStore.get();try{if(r){this.restorePersistedValues(),Xt(n,this.network).then(o=>{this.$store.setKey("balance",o)});return}let i=va(this.network||vt);await mb({payload:{purposes:["ordinals","payment"],message:"Address for receiving Ordinals and payments",network:{type:i}},onFinish:o=>{const s=md(o.addresses),a=vd(o.addresses);s&&a&&(this.$store.setKey("provider",ii),this.$store.setKey("address",s.address),this.$store.setKey("paymentAddress",a.address)),this.$store.setKey("publicKey",String(o.addresses[0].publicKey)),this.$store.setKey("paymentPublicKey",String(o.addresses[1].publicKey)),Xt(a.address,this.network).then(u=>{this.$store.setKey("balance",u)})},onCancel:()=>{throw new Error(`User canceled lasereyes to ${ii} wallet`)},onError:o=>{throw new Error(`Can't lasereyes to ${ii} wallet`)}}),this.$store.setKey("connected",!0)}catch(i){throw i}}async requestAccounts(){return[this.$store.get().address,this.$store.get().paymentAddress]}async getNetwork(){const{address:t}=this.$store.get();return t.slice(0,1)==="t"&&[Rt,xr,Ir,$r].includes(this.network)?this.network:vt}getPublicKey(){throw An}async getBalance(){const{paymentAddress:t}=this.$store.get();return await Xt(t,this.network)}getInscriptions(){throw An}async sendBTC(t,r){const n=await vb("sendTransfer",{recipients:[{address:t,amount:r}]});if(n.status==="success")return n.result.txid;throw n.error.code===sl.USER_REJECTION?new Error("User rejected the request"):new Error("Error sending BTC: "+n.error.message)}async signMessage(t,r){const n=r||this.$store.get().paymentAddress,i=await vb("signMessage",{address:n,message:t});if(i.status==="success")return i.result.signature;throw i.error.code===sl.USER_REJECTION?new Error("User rejected the request"):new Error("Error signing message: "+i.error.message)}async signPsbt(t,r,n,i,o){const{address:s,paymentAddress:a}=this.$store.get(),u=dt.fromBase64(String(n),{network:nr(this.network)}),f=u.data.inputs,h=[],d={address:s,signingIndexes:[]},g={address:a,signingIndexes:[]};let v=0;for await(let I of f){if(I.witnessUtxo===void 0)g.signingIndexes.push(Number(v));else{const{script:k}=I.witnessUtxo,R=ga(k,nr(this.network));R===a?g.signingIndexes.push(Number(v)):R===s&&d.signingIndexes.push(Number(v))}v++}d.signingIndexes.length>0&&h.push(d),g.signingIndexes.length>0&&h.push(g);let E,T,x;const N={payload:{network:{type:va(this.network)},message:"Sign Transaction",psbtBase64:u.toBase64(),broadcast:o,inputsToSign:h},onFinish:I=>{if(I.txId)E=I.txId;else if(I.psbtBase64){const k=dt.fromBase64(String(I.psbtBase64),{network:nr(this.network)});T=k.toHex(),x=k.toBase64()}},onCancel:()=>console.log("Canceled")};return await signTransaction(N),{signedPsbtHex:T,signedPsbtBase64:x,txId:E}}pushPsbt(t){throw An}}class i7 extends Dn{constructor(){super(...arguments),ge(this,"observer")}get library(){return window.wizz}get network(){return this.$network.get()}handleNetworkChanged(t){this.parent.connect(As)}handleAccountsChanged(t){if(!t.length){this.parent.disconnect();return}this.$store.get().accounts[0]!==t[0]&&this.$store.setKey("accounts",t)}initialize(){gn(this.$store,["provider"],t=>{t.provider===As?this.addLibraryListeners():this.removeLibraryListeners()}),typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;this.library&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[As]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0}))}removeLibraryListeners(){var t,r;(t=this.library)==null||t.removeListener("networkChanged",this.handleNetworkChanged.bind(this)),(r=this.library)==null||r.removeListener("accountsChanged",this.handleAccountsChanged.bind(this))}addLibraryListeners(){var t,r;(t=this.library)==null||t.on("networkChanged",this.handleNetworkChanged.bind(this)),(r=this.library)==null||r.on("accountsChanged",this.handleAccountsChanged.bind(this))}dispose(){var t;(t=this.observer)==null||t.disconnect(),this.removeLibraryListeners()}async connect(){if(!this.library)throw NP;const t=await this.library.requestAccounts();if(!t)throw new Error("No accounts found");const r=await this.library.getPublicKey();if(!r)throw new Error("No public key found");this.$store.setKey("accounts",t),this.$store.setKey("address",t[0]),this.$store.setKey("paymentAddress",t[0]),this.$store.setKey("publicKey",r),this.$store.setKey("paymentPublicKey",r),this.$store.setKey("provider",As),await this.getNetwork().then(n=>{var i;n&&((i=this.config)==null?void 0:i.network)!==n&&this.parent.switchNetwork(n)}),await this.parent.getBalance(),this.$store.setKey("connected",!0)}async requestAccounts(){return await this.library.requestAccounts()}async getNetwork(){var t;const r=await((t=this.library)==null?void 0:t.getNetwork());return r?Dw(r):void 0}async switchNetwork(t){var r;if(t===$r||t===fo)return await this.library.switchNetwork(Kw);const n=Dw(t);await((r=this.library)==null?void 0:r.switchNetwork(n)),this.$network.set(t),await this.parent.getBalance()}async getPublicKey(){var t;return await((t=this.library)==null?void 0:t.getPublicKey())}async getBalance(){return(await this.library.getBalance()).total}async getInscriptions(){return await this.library.getInscriptions(0,10)}async sendBTC(t,r){var n;const i=await((n=this.library)==null?void 0:n.sendBitcoin(t,r));if(i)return i;throw new Error("Error sending BTC")}async signMessage(t){var r;return await((r=this.library)==null?void 0:r.signMessage(t))}async signPsbt(t,r,n,i,o){var s;const a=await((s=this.library)==null?void 0:s.signPsbt(r,{autoFinalized:i,broadcast:!1})),u=dt.fromHex(a);let f;return i&&o&&(f=await this.pushPsbt(a)),{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:f}}async pushPsbt(t){return await Xe.post(`${pi(this.$network.get())}/api/tx`,t).then(r=>r.data)}}const Sb=["address","paymentAddress","publicKey","paymentPublicKey","balance"],s7="OYL_CONNECTED_WALLET_STATE";class o7 extends Dn{constructor(){super(...arguments),ge(this,"observer"),ge(this,"$valueStore",To(s7,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),ge(this,"removeSubscriber")}get library(){return window.oyl}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Sb)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===ms&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Sb.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;window!=null&&window.oyl&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[ms]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),gn(this.$store,["provider"],t=>{t.provider!==ms?this.removeSubscriber&&(this.$valueStore.set({address:"",publicKey:"",paymentAddress:"",paymentPublicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){if(!this.library)throw new Error("Oyl isn't installed");const{nativeSegwit:r,taproot:n}=await this.library.getAddresses();if(!r||!n)throw new Error("No accounts found");this.$store.setKey("address",n.address),this.$store.setKey("paymentAddress",r.address),this.$store.setKey("publicKey",n.publicKey),this.$store.setKey("paymentPublicKey",r.publicKey),this.$store.setKey("provider",ms),Xt(r.address,this.network).then(o=>{this.$store.setKey("balance",o)}),this.$store.setKey("connected",!0);const i=await this.getBalance();i&&this.$store.setKey("balance",i)}async getNetwork(){return this.network}async sendBTC(t,r){const{psbtHex:n}=await M2(this.$store.get().address,this.$store.get().paymentAddress,t,r,this.$store.get().paymentPublicKey,this.network,7),i=await this.signPsbt("",n,"",!0,!0);if(!i)throw new Error("Error sending BTC");return i.txId}async signMessage(t,r){const n=r||this.$store.get().paymentAddress;return(await this.library.signMessage({address:n,message:t})).signature}async signPsbt(t,r,n,i,o){const{psbt:s,txid:a}=await this.library.signPsbt({psbt:r,finalize:i,broadcast:o}),u=dt.fromHex(s);return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:a}}async pushPsbt(t){return(await this.library.pushPsbt({psbt:t})).txid}async getPublicKey(){var t;return await((t=this.library)==null?void 0:t.getPublicKey())}async getBalance(){const{total:t}=await this.library.getBalance();return this.$store.setKey("balance",t),t}async getInscriptions(){return await this.library.getInscriptions(0,10)}async requestAccounts(){return await this.library.requestAccounts()}async switchNetwork(){throw An}}const Tb=["address","paymentAddress","publicKey","paymentPublicKey","balance"],a7="LEATHER_CONNECTED_WALLET_STATE";class c7 extends Dn{constructor(){super(...arguments),ge(this,"observer"),ge(this,"$valueStore",To(a7,{address:"",publicKey:"",paymentAddress:"",paymentPublicKey:"",balance:""})),ge(this,"removeSubscriber")}get library(){return window.LeatherProvider}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Tb)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===vs&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Tb.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;window!=null&&window.LeatherProvider&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[vs]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),gn(this.$store,["provider"],t=>{t.provider!==vs?this.removeSubscriber&&(this.$valueStore.set({address:"",publicKey:"",paymentAddress:"",paymentPublicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){var r;if(!this.library)throw new Error("Leather isn't installed");const n=await this.library.request("getAddresses");if(!n)throw new Error("No accounts found");const i=n.result.addresses,o=i.map(u=>u.address),s=i.find(u=>u.type===tf),a=i.find(u=>u.type===Kg);if(!(s!=null&&s.publicKey)||!(a!=null&&a.publicKey))throw new Error("No accounts found");if((r=String(s==null?void 0:s.address))!=null&&r.startsWith("tb")&&this.network!==Rt&&this.network!==xr&&this.network!==Ir)throw new Error(`Please switch networks to ${this.network} in the wallet settings.`);this.$store.setKey("accounts",o),this.$store.setKey("address",s.address),this.$store.setKey("paymentAddress",a.address),this.$store.setKey("publicKey",s.publicKey),this.$store.setKey("paymentPublicKey",a.publicKey),this.$store.setKey("provider",vs),Xt(a.address,this.network).then(u=>{this.$store.setKey("balance",u)}),this.$store.setKey("connected",!0)}async getNetwork(){return this.network}async sendBTC(t,r){var n,i;const o=await((n=this.library)==null?void 0:n.request("sendTransfer",{recipients:[{address:t,amount:r}]}));if((i=o==null?void 0:o.result)!=null&&i.txid)return o.result.txid;throw o.error.code===sl.USER_REJECTION?new Error("User rejected the request"):new Error("Error sending BTC: "+o.error.message)}async signMessage(t,r){var n;const i=r===this.$store.get().address?tf:Kg;if(r!==this.$store.get().address&&r!==this.$store.get().paymentAddress)throw new Error("Invalid address to sign message");const o=await this.library.request("signMessage",{message:t,paymentType:i});return(n=o==null?void 0:o.result)==null?void 0:n.signature}async signPsbt(t,r,n,i,o){const s={hex:r,broadcast:!1,network:this.network},a=(await this.library.request("signPsbt",s)).result.hex,u=dt.fromHex(String(a));if(i&&o){const f=u.finalizeAllInputs(),h=await this.pushPsbt(f.toHex());return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:h}}else if(i){const f=u.finalizeAllInputs();return{signedPsbtHex:f.toHex(),signedPsbtBase64:f.toBase64(),txId:void 0}}else return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:void 0}}async pushPsbt(t){const r=dt.fromHex(t).extractTransaction();return await Xe.post(`${pi(this.network)}/api/tx`,r.toHex()).then(n=>n.data)}async getPublicKey(){const{result:t}=await this.library.request("getAddresses"),r=t.addresses.find(n=>n.type===tf);if(!(r!=null&&r.publicKey))throw new Error("No accounts found");return r.publicKey}async getBalance(){const t=await Xt(this.$store.get().paymentAddress,this.network);return this.$store.setKey("balance",t),t.toString()}async getInscriptions(){throw An}async requestAccounts(){const{result:t}=await this.library.request("getAddresses"),r=t.addresses.map(n=>n.address);return this.$store.setKey("accounts",r),r}async switchNetwork(){throw An}}var $d={},_b={},kn={},kb={};Object.defineProperty(kb,"__esModule",{value:!0}),function(e){var t=Te&&Te.__createBinding||(Object.create?function(s,a,u,f){f===void 0&&(f=u);var h=Object.getOwnPropertyDescriptor(a,u);(!h||("get"in h?!a.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(s,f,h)}:function(s,a,u,f){f===void 0&&(f=u),s[f]=a[u]}),r=Te&&Te.__exportStar||function(s,a){for(var u in s)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,s,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.getProviderById=e.getProviders=e.getProviderOrThrow=void 0;async function n(s){var a,u;if(s){const h=await s();if(h)return h}const f=window.OrangeBitcoinProvider||((a=window.OrangecryptoProviders)==null?void 0:a.BitcoinProvider)||((u=window.OrangeWalletProviders)==null?void 0:u.OrangeBitcoinProvider);if(!f)throw new Error("No Orange Bitcoin wallet installed");return f}e.getProviderOrThrow=n;function i(){return window.btc_providers||(window.btc_providers=[]),window.btc_providers}e.getProviders=i;function o(s){var a;if(Array.isArray(window.btc_providers)){const u=window.btc_providers.find(f=>f.id===s);return(a=u==null?void 0:u.id)==null?void 0:a.split(".").reduce((f,h)=>f==null?void 0:f[h],window)}else{console.log("window.btc_providers is not defined or not an array");return}}e.getProviderById=o,r(kb,e)}(kn);var Pb={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.AddressType=e.AddressPurpose=void 0,function(t){t.Ordinals="ordinals",t.Payment="payment",t.Stacks="stacks"}(e.AddressPurpose||(e.AddressPurpose={})),function(t){t.p2pkh="p2pkh",t.p2sh="p2sh",t.p2wpkh="p2wpkh",t.p2wsh="p2wsh",t.p2tr="p2tr",t.stacks="stacks"}(e.AddressType||(e.AddressType={}))})(Pb),function(e){var t=Te&&Te.__createBinding||(Object.create?function(s,a,u,f){f===void 0&&(f=u);var h=Object.getOwnPropertyDescriptor(a,u);(!h||("get"in h?!a.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(s,f,h)}:function(s,a,u,f){f===void 0&&(f=u),s[f]=a[u]}),r=Te&&Te.__exportStar||function(s,a){for(var u in s)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,s,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.getAddress=void 0;const n=Gr,i=kn,o=async s=>{var a,u;const f=await(0,i.getProviderOrThrow)(s.getProvider),{purposes:h}=s.payload;if(!h)throw new Error("Address purposes are required");try{const d=(0,n.createUnsecuredToken)(s.payload),g=await f.connect(d);(a=s.onFinish)==null||a.call(s,g)}catch(d){console.error("[Connect] Error during address request",d),(u=s.onCancel)==null||u.call(s)}};e.getAddress=o,r(Pb,e)}(_b);var Ob={},Ib={},xb={};Object.defineProperty(xb,"__esModule",{value:!0});var $b={};Object.defineProperty($b,"__esModule",{value:!0}),function(e){var t=Te&&Te.__createBinding||(Object.create?function(n,i,o,s){s===void 0&&(s=o);var a=Object.getOwnPropertyDescriptor(i,o);(!a||("get"in a?!i.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return i[o]}}),Object.defineProperty(n,s,a)}:function(n,i,o,s){s===void 0&&(s=o),n[s]=i[o]}),r=Te&&Te.__exportStar||function(n,i){for(var o in n)o!=="default"&&!Object.prototype.hasOwnProperty.call(i,o)&&t(i,n,o)};Object.defineProperty(e,"__esModule",{value:!0}),r(xb,e),r($b,e)}(Ib),function(e){var t=Te&&Te.__createBinding||(Object.create?function(s,a,u,f){f===void 0&&(f=u);var h=Object.getOwnPropertyDescriptor(a,u);(!h||("get"in h?!a.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(s,f,h)}:function(s,a,u,f){f===void 0&&(f=u),s[f]=a[u]}),r=Te&&Te.__exportStar||function(s,a){for(var u in s)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,s,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.request=void 0;const n=kn,i=async(s,a,u)=>{var f;let h=((f=window.OrangecryptoProviders)==null?void 0:f.BitcoinProvider)||window.OrangeBitcoinProvider;if(u&&(h=await(0,n.getProviderById)(u)),!h)throw new Error("no wallet provider was found");if(!s)throw new Error("A wallet method is required");const d=await h.request(s,a);return o(d)?{status:"success",result:d.result}:{status:"error",error:d.error}};e.request=i;const o=s=>Object.hasOwn(s,"result")&&!!s.result;r(Ib,e)}(Ob);var Cb={},Nb={};Object.defineProperty(Nb,"__esModule",{value:!0}),function(e){var t=Te&&Te.__createBinding||(Object.create?function(a,u,f,h){h===void 0&&(h=f);var d=Object.getOwnPropertyDescriptor(u,f);(!d||("get"in d?!u.__esModule:d.writable||d.configurable))&&(d={enumerable:!0,get:function(){return u[f]}}),Object.defineProperty(a,h,d)}:function(a,u,f,h){h===void 0&&(h=f),a[h]=u[f]}),r=Te&&Te.__exportStar||function(a,u){for(var f in a)f!=="default"&&!Object.prototype.hasOwnProperty.call(u,f)&&t(u,a,f)};Object.defineProperty(e,"__esModule",{value:!0}),e.getCapabilities=void 0;const n=Gr,i=kn,o=(a,u)=>{const f=d=>!(!a[d]||u&&!u.has(d)),h={request:f("request"),connect:f("connect"),signMessage:f("signMessage"),signTransaction:f("signTransaction"),sendBtcTransaction:f("sendBtcTransaction"),createInscription:f("createInscription"),createRepeatInscriptions:f("createRepeatInscriptions"),signMultipleTransactions:f("signMultipleTransactions")};return Object.entries(h).reduce((d,[g,v])=>v?[...d,g]:d,[])},s=async a=>{var u,f,h;const d=await(0,i.getProviderOrThrow)(a.getProvider),g=(0,n.createUnsecuredToken)(a.payload);if(d.getCapabilities)try{const v=await d.getCapabilities(g);(u=a.onFinish)==null||u.call(a,o(d,new Set(v)))}catch(v){console.error("[Connect] Error during capabilities request",v)}try{const v=o(d);(f=a.onFinish)==null||f.call(a,v)}catch(v){console.error("[Connect] Error during capabilities request",v),(h=a.onCancel)==null||h.call(a)}};e.getCapabilities=s,r(Nb,e)}(Cb);var Bb={},cl={},Na={};Object.defineProperty(Na,"__esModule",{value:!0}),Na.validateInscriptionPayload=void 0;const u7=4e5,l7=6e4,h7=e=>{const{contentType:t,content:r,payloadType:n,network:i,appFeeAddress:o,appFee:s}=e;if(!/^[a-z]+\/[a-z0-9\-\.\+]+(?=;.*|$)/.test(t))throw new Error("Invalid content type detected");if(!r||r.length===0)throw new Error("Empty content not allowed");if(!n||n!=="BASE_64"&&n!=="PLAIN_TEXT")throw new Error("Empty invalid payloadType specified");if(r.length>(i.type==="Mainnet"?u7:l7))throw new Error("Content too large");if(((o==null?void 0:o.length)??0)>0&&(s??0)<=0)throw new Error("Invalid combination of app fee address and fee provided")};Na.validateInscriptionPayload=h7,Object.defineProperty(cl,"__esModule",{value:!0}),cl.createInscription=void 0;const f7=Gr,d7=kn,p7=Na,y7=async e=>{var t,r;const{getProvider:n}=e,i=await(0,d7.getProviderOrThrow)(n);(0,p7.validateInscriptionPayload)(e.payload);try{const o=(0,f7.createUnsecuredToken)(e.payload),s=await i.createInscription(o);(t=e.onFinish)==null||t.call(e,s)}catch(o){console.error("[Connect] Error during create inscription",o),(r=e.onCancel)==null||r.call(e)}};cl.createInscription=y7;var ul={};Object.defineProperty(ul,"__esModule",{value:!0}),ul.createRepeatInscriptions=void 0;const g7=kn,w7=Gr,b7=Na,m7=async e=>{var t,r;const{getProvider:n}=e,i=await(0,g7.getProviderOrThrow)(n);(0,b7.validateInscriptionPayload)(e.payload);try{const o=(0,w7.createUnsecuredToken)(e.payload),s=await i.createRepeatInscriptions(o);(t=e.onFinish)==null||t.call(e,s)}catch(o){console.error("[Connect] Error during create repeat inscriptions",o),(r=e.onCancel)==null||r.call(e)}};ul.createRepeatInscriptions=m7;var Ub={};Object.defineProperty(Ub,"__esModule",{value:!0}),function(e){var t=Te&&Te.__createBinding||(Object.create?function(n,i,o,s){s===void 0&&(s=o);var a=Object.getOwnPropertyDescriptor(i,o);(!a||("get"in a?!i.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return i[o]}}),Object.defineProperty(n,s,a)}:function(n,i,o,s){s===void 0&&(s=o),n[s]=i[o]}),r=Te&&Te.__exportStar||function(n,i){for(var o in n)o!=="default"&&!Object.prototype.hasOwnProperty.call(i,o)&&t(i,n,o)};Object.defineProperty(e,"__esModule",{value:!0}),r(cl,e),r(ul,e),r(Ub,e)}(Bb);var Rb={},Hb={};Object.defineProperty(Hb,"__esModule",{value:!0}),function(e){var t=Te&&Te.__createBinding||(Object.create?function(s,a,u,f){f===void 0&&(f=u);var h=Object.getOwnPropertyDescriptor(a,u);(!h||("get"in h?!a.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return a[u]}}),Object.defineProperty(s,f,h)}:function(s,a,u,f){f===void 0&&(f=u),s[f]=a[u]}),r=Te&&Te.__exportStar||function(s,a){for(var u in s)u!=="default"&&!Object.prototype.hasOwnProperty.call(a,u)&&t(a,s,u)};Object.defineProperty(e,"__esModule",{value:!0}),e.signMessage=void 0;const n=Gr,i=kn,o=async s=>{var a,u;const f=await(0,i.getProviderOrThrow)(s.getProvider),{address:h,message:d}=s.payload;if(!h)throw new Error("An address is required to sign a message");if(!d)throw new Error("A message to be signed is required");try{const g=(0,n.createUnsecuredToken)(s.payload),v=await f.signMessage(g);(a=s.onFinish)==null||a.call(s,v)}catch(g){console.error("[Connect] Error during sign message request",g),(u=s.onCancel)==null||u.call(s)}};e.signMessage=o,r(Hb,e)}(Rb);var Lb={},ll={};Object.defineProperty(ll,"__esModule",{value:!0}),ll.sendBtcTransaction=void 0;const v7=Gr,E7=kn,A7=e=>e.map(t=>{const{address:r,amountSats:n}=t;return{address:r,amountSats:n.toString()}}),S7=async e=>{var t,r;const n=await(0,E7.getProviderOrThrow)(e.getProvider),{recipients:i,senderAddress:o,network:s,message:a}=e.payload;if(!i||i.length===0)throw new Error("At least one recipient is required");if(i.some(u=>typeof u.address!="string"||typeof u.amountSats!="bigint"))throw new Error("Incorrect recipient format");if(!o)throw new Error("The sender address is required");try{const u=A7(i),f={network:s,senderAddress:o,message:a,recipients:u},h=(0,v7.createUnsecuredToken)(f),d=await n.sendBtcTransaction(h);(t=e.onFinish)==null||t.call(e,d)}catch(u){console.error("[Connect] Error during send BTC transaction request",u),(r=e.onCancel)==null||r.call(e)}};ll.sendBtcTransaction=S7;var hl={};Object.defineProperty(hl,"__esModule",{value:!0}),hl.signTransaction=void 0;const T7=Gr,_7=kn,k7=async e=>{var t,r;const n=await(0,_7.getProviderOrThrow)(e.getProvider),{psbtBase64:i,inputsToSign:o}=e.payload;if(!i)throw new Error("A value for psbtBase64 representing the tx hash is required");if(!o)throw new Error("An array specifying the inputs to be signed by the wallet is required");try{const s=(0,T7.createUnsecuredToken)(e.payload),a=await n.signTransaction(s);(t=e.onFinish)==null||t.call(e,a)}catch(s){console.error("[Connect] Error during sign transaction request",s),(r=e.onCancel)==null||r.call(e)}};hl.signTransaction=k7;var fl={};Object.defineProperty(fl,"__esModule",{value:!0}),fl.signMultipleTransactions=void 0;const P7=Gr,O7=kn,I7=async e=>{var t,r;const n=await(0,O7.getProviderOrThrow)(e.getProvider),{psbts:i}=e.payload;if(!i||!i.length)throw new Error("psbts array is required");if(i.length>100)throw new Error("psbts array must contain less than 100 psbts");try{const o=(0,P7.createUnsecuredToken)(e.payload),s=await n.signMultipleTransactions(o);(t=e.onFinish)==null||t.call(e,s)}catch(o){console.error("[Connect] Error during sign Multiple transactions request",o),(r=e.onCancel)==null||r.call(e)}};fl.signMultipleTransactions=I7;var Kb={};Object.defineProperty(Kb,"__esModule",{value:!0}),function(e){var t=Te&&Te.__createBinding||(Object.create?function(n,i,o,s){s===void 0&&(s=o);var a=Object.getOwnPropertyDescriptor(i,o);(!a||("get"in a?!i.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return i[o]}}),Object.defineProperty(n,s,a)}:function(n,i,o,s){s===void 0&&(s=o),n[s]=i[o]}),r=Te&&Te.__exportStar||function(n,i){for(var o in n)o!=="default"&&!Object.prototype.hasOwnProperty.call(i,o)&&t(i,n,o)};Object.defineProperty(e,"__esModule",{value:!0}),r(ll,e),r(hl,e),r(fl,e),r(Kb,e)}(Lb);var jb={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.RpcErrorCode=e.BitcoinNetworkType=void 0,function(t){t.Mainnet="Mainnet",t.Testnet="Testnet"}(e.BitcoinNetworkType||(e.BitcoinNetworkType={})),function(t){t[t.PARSE_ERROR=-32700]="PARSE_ERROR",t[t.INVALID_REQUEST=-32600]="INVALID_REQUEST",t[t.METHOD_NOT_FOUND=-32601]="METHOD_NOT_FOUND",t[t.INVALID_PARAMS=-32602]="INVALID_PARAMS",t[t.INTERNAL_ERROR=-32603]="INTERNAL_ERROR",t[t.USER_REJECTION=-32e3]="USER_REJECTION",t[t.METHOD_NOT_SUPPORTED=-32001]="METHOD_NOT_SUPPORTED"}(e.RpcErrorCode||(e.RpcErrorCode={}))})(jb),function(e){var t=Te&&Te.__createBinding||(Object.create?function(n,i,o,s){s===void 0&&(s=o);var a=Object.getOwnPropertyDescriptor(i,o);(!a||("get"in a?!i.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return i[o]}}),Object.defineProperty(n,s,a)}:function(n,i,o,s){s===void 0&&(s=o),n[s]=i[o]}),r=Te&&Te.__exportStar||function(n,i){for(var o in n)o!=="default"&&!Object.prototype.hasOwnProperty.call(i,o)&&t(i,n,o)};Object.defineProperty(e,"__esModule",{value:!0}),r(_b,e),r(Ob,e),r(Cb,e),r(Bb,e),r(Rb,e),r(kn,e),r(Lb,e),r(jb,e)}($d);const x7=IT($d),Db=["address","paymentAddress","publicKey","paymentPublicKey","balance"],{signMessage:$7,sendBtcTransaction:C7,signTransaction:N7}=x7,B7="ORANGE_CONNECTED_WALLET_STATE";class U7 extends Dn{constructor(){super(...arguments),ge(this,"observer"),ge(this,"$valueStore",To(B7,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),ge(this,"removeSubscriber")}get library(){var t;return(t=window==null?void 0:window.OrangeWalletProviders)==null?void 0:t.OrangeBitcoinProvider}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Db)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===Mi&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Db.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){var t;typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var r,n;(r=window==null?void 0:window.OrangeWalletProviders)!=null&&r.OrangeBitcoinProvider&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Mi]:!0}),(n=this.observer)==null||n.disconnect())}),(t=this.observer)==null||t.observe(document,{childList:!0,subtree:!0})),gn(this.$store,["provider"],r=>{r.provider!==Mi?this.removeSubscriber&&(this.$valueStore.set({address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){const{address:r,paymentAddress:n}=this.$valueStore.get();try{if(r){this.restorePersistedValues(),Xt(n,this.network).then(s=>{this.$store.setKey("balance",s)});return}let i=Cu(this.network||vt);const o={payload:{purposes:["ordinals","payment"],message:"Address for receiving Ordinals and payments",network:{type:i}},onFinish:s=>{const a=md(s.addresses),u=vd(s.addresses);a&&u&&(this.$store.setKey("publicKey",String(s.addresses[0].publicKey)),this.$store.setKey("paymentPublicKey",String(s.addresses[1].publicKey)),this.$store.setKey("provider",Mi),this.$store.setKey("address",a.address),this.$store.setKey("paymentAddress",u.address)),Xt(u.address,this.network).then(f=>{this.$store.setKey("balance",f)})},onCancel:()=>{throw new Error(`User canceled lasereyes to ${Mi} wallet`)}};await $d.getAddress(o),this.$store.setKey("connected",!0)}catch(i){throw i}}async requestAccounts(){return[this.$store.get().address,this.$store.get().paymentAddress]}async getNetwork(){const{address:t}=this.$store.get();return t.slice(0,1)==="t"&&[Rt,xr,Ir,$r].includes(this.network)?this.network:vt}getPublicKey(){throw An}async getBalance(){const{paymentAddress:t}=this.$store.get();return await Xt(t,this.network)}getInscriptions(){throw An}async sendBTC(t,r){let n="";const i={payload:{network:{type:Cu(this.network)},recipients:[{address:t,amountSats:BigInt(r)}],senderAddress:this.$store.get().paymentAddress},onFinish:o=>{console.log(o),n=o},onCancel:()=>{throw new Error("User canceled the request")}};return await C7(i),n}async signMessage(t,r){let n="";const i=r||this.$store.get().paymentAddress,o={payload:{network:{type:Cu(this.network)},address:i,message:t},onFinish:s=>{n=s},onCancel:()=>alert("Signature request canceled")};return await $7(o),n}async signPsbt(t,r,n,i,o){const s=dt.fromBase64(String(n),{network:nr(this.network)}),a=this.$store.get().address,u=this.$store.get().paymentAddress,f=s.data.inputs,h=[],d={address:a,signingIndexes:[]},g={address:u,signingIndexes:[]};let v=0;for await(let I of f){if(I.witnessUtxo===void 0)g.signingIndexes.push(Number(v));else{const{script:k}=I.witnessUtxo,R=ga(k,nr(this.network));R===u?g.signingIndexes.push(Number(v)):R===a&&d.signingIndexes.push(Number(v))}v++}d.signingIndexes.length>0&&h.push(d),g.signingIndexes.length>0&&h.push(g);let E,T,x;const N={payload:{network:{type:Cu(this.network)},psbtBase64:s.toBase64(),broadcast:o,inputsToSign:h},onFinish:I=>{if(console.log(I),I.txId)E=I.txId;else if(I.psbtBase64){const k=dt.fromBase64(String(I.psbtBase64),{network:nr(this.network)});T=k.toHex(),x=k.toBase64()}},onCancel:()=>console.log("Canceled")};return await N7(N),{signedPsbtHex:T,signedPsbtBase64:x,txId:E}}async pushPsbt(t){let r=t;if(!r.startsWith("02")){const n=dt.fromHex(r);n.finalizeAllInputs(),r=n.extractTransaction().toHex()}return await Xe.post(`${pi(this.network)}/api/tx`,r).then(n=>n.data)}}const Mb=["address","paymentAddress","publicKey","paymentPublicKey","balance"],R7="OKX_CONNECTED_WALLET_STATE";class H7 extends Dn{constructor(){super(...arguments),ge(this,"observer"),ge(this,"$valueStore",To(R7,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),ge(this,"removeSubscriber")}get library(){var t,r;let n;return this.network===Rt||this.network===xr||this.network===Ir||this.network===$r?n=(t=window==null?void 0:window.okxwallet)==null?void 0:t.bitcoinTestnet:(this.network===vt||this.network===fo)&&(n=(r=window==null?void 0:window.okxwallet)==null?void 0:r.bitcoin),n}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Mb)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===Es&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Mb.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){var t;typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var r;this.library&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Es]:!0}),(r=this.observer)==null||r.disconnect())}),(t=this.observer)==null||t.observe(document,{childList:!0,subtree:!0})),gn(this.$store,["provider"],r=>{r.provider!==Es?this.removeSubscriber&&(this.$valueStore.set({address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){var r;try{const n=await this.library.connect();if(!n)throw new Error("No accounts found");this.$store.setKey("address",n.address),this.$store.setKey("paymentAddress",n.address),this.$store.setKey("publicKey",n.publicKey),this.$store.setKey("paymentPublicKey",n.publicKey),this.$store.setKey("accounts",[n]);const i=await((r=this.library)==null?void 0:r.getBalance());this.$store.setKey("balance",i.total),this.$store.setKey("provider",Es),this.$store.setKey("connected",!0)}catch(n){throw n}}async requestAccounts(){const t=this.library,r=this.network;return r===Rt||r===xr||r===$r?await t.connect():await t.requestAccounts()}async getNetwork(){const{address:t}=this.$store.get(),r=this.network;if(t.slice(0,1)==="t")return r===Rt?Rt:r===xr?xr:r===Ir?Ir:r===$r?$r:Rt;const n=await this.library.getNetwork();return MP(n)}async getPublicKey(){const t=this.library;return await(t==null?void 0:t.getPublicKey())}async getBalance(){const{paymentAddress:t}=this.$store.get();return await Xt(t,this.network)}async getInscriptions(){return await this.library.getInscriptions(0,10)}async sendBTC(t,r){const n=await this.library.sendBitcoin(t,r);if(!n)throw new Error("Transaction failed");return n}async signMessage(t,r){const n=this.library;return await(n==null?void 0:n.signMessage(t))}async signPsbt(t,r,n,i,o){const s=await this.library.signPsbt(r,{autoFinalized:i}),a=dt.fromHex(s);if(i&&o){const u=await this.pushPsbt(s);return{signedPsbtHex:a.toHex(),signedPsbtBase64:a.toBase64(),txId:u}}return{signedPsbtHex:a.toHex(),signedPsbtBase64:a.toBase64(),txId:void 0}}async pushPsbt(t){return await Xe.post(`${pi(this.network)}/api/tx`,t).then(r=>r.data)}}const Fb=["address","paymentAddress","publicKey","paymentPublicKey","balance"],L7="MAGIC_EDEN_CONNECTED_WALLET_STATE";class K7 extends Dn{constructor(){super(...arguments),ge(this,"observer"),ge(this,"$valueStore",To(L7,{address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""})),ge(this,"removeSubscriber")}get library(){var t;return(t=window==null?void 0:window.magicEden)==null?void 0:t.bitcoin}get network(){return this.$network.get()}restorePersistedValues(){const t=this.$valueStore.get();for(const r of Fb)this.$store.setKey(r,t[r])}watchStateChange(t,r,n){var i,o;n&&t.provider===si&&(n==="balance"?this.$valueStore.setKey("balance",((i=t.balance)==null?void 0:i.toString())??""):Fb.includes(n)&&this.$valueStore.setKey(n,((o=t[n])==null?void 0:o.toString())??""))}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t,r;(t=window==null?void 0:window.magicEden)!=null&&t.bitcoin&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[si]:!0}),(r=this.observer)==null||r.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),gn(this.$store,["provider"],t=>{t.provider!==si?this.removeSubscriber&&(this.$valueStore.set({address:"",paymentAddress:"",paymentPublicKey:"",publicKey:"",balance:""}),this.removeSubscriber(),this.removeSubscriber=void 0):this.removeSubscriber=this.$store.subscribe(this.watchStateChange.bind(this))})}dispose(){var t;(t=this.observer)==null||t.disconnect()}async connect(t){const{address:r,paymentAddress:n}=this.$valueStore.get();try{if(r){this.restorePersistedValues(),Xt(n,this.network).then(o=>{this.$store.setKey("balance",o)});return}let i=va(this.network||vt);await mb({getProvider:async()=>this.library,payload:{purposes:["ordinals","payment"],message:"Address for receiving Ordinals and payments",network:{type:i}},onFinish:o=>{const s=md(o.addresses),a=vd(o.addresses);s&&a&&(this.$store.setKey("provider",si),this.$store.setKey("address",s.address),this.$store.setKey("paymentAddress",a.address)),this.$store.setKey("publicKey",String(o.addresses[0].publicKey)),this.$store.setKey("paymentPublicKey",String(o.addresses[1].publicKey)),Xt(a.address,this.network).then(u=>{this.$store.setKey("balance",u)})},onCancel:()=>{throw new Error(`User canceled lasereyes to ${si} wallet`)},onError:o=>{throw new Error(`Can't lasereyes to ${si} wallet`)}}),this.$store.setKey("connected",!0)}catch(i){throw i}}async requestAccounts(){return[this.$store.get().address,this.$store.get().paymentAddress]}async getNetwork(){const{address:t}=this.$store.get();return t.slice(0,1)==="t"&&[Rt,xr,Ir,$r].includes(this.network)?this.network:vt}getPublicKey(){throw An}async getBalance(){const{paymentAddress:t}=this.$store.get();return await Xt(t,this.network)}getInscriptions(){throw An}async sendBTC(t,r){let n;if(await e7({getProvider:async()=>this.library,payload:{network:{type:va(this.network)},recipients:[{address:t,amountSats:BigInt(r)}],senderAddress:this.$store.get().paymentAddress},onFinish:i=>{n=i},onCancel:()=>alert("Canceled")}),!n)throw new Error("Error sending BTC");return n.txid}async signMessage(t,r){try{const n=r||this.$store.get().paymentAddress;let i="";return await Z$({getProvider:async()=>this.library,payload:{network:{type:yb.Mainnet},address:n,message:t,protocol:al.BIP322},onFinish:o=>{i=o},onCancel:()=>{alert("Request canceled")}}),i}catch(n){throw n}}async signPsbt(t,r,n,i,o){const{address:s,paymentAddress:a}=this.$store.get(),u=dt.fromBase64(String(n),{network:nr(this.network)}),f=u.data.inputs,h=[],d={address:s,signingIndexes:[]},g={address:a,signingIndexes:[]};let v=0;for await(let k of f){const{script:R}=k.witnessUtxo,W=ga(R,nr(this.network));W===a?g.signingIndexes.push(Number(v)):W===s&&d.signingIndexes.push(Number(v)),v++}d.signingIndexes.length>0&&h.push(d),g.signingIndexes.length>0&&h.push(g);let E,T,x;const N=va(this.network),I={getProvider:async()=>this.library,payload:{network:{type:N},message:"Sign Transaction",psbtBase64:u.toBase64(),broadcast:o,inputsToSign:h},onFinish:k=>{if(k.psbtBase64){const R=dt.fromBase64(String(k.psbtBase64),{network:nr(this.network)});T=R.toHex(),x=R.toBase64()}},onCancel:()=>{throw console.log("Canceled"),new Error("User canceled the request")},onError:k=>{throw console.log("error",k),k}};if(await signTransaction(I),o){const k=dt.fromBase64(String(x)).finalizeAllInputs().extractTransaction(),R=await this.pushPsbt(k.toHex());return{signedPsbtHex:k.toHex(),signedPsbtBase64:"test",txId:R}}else return{signedPsbtHex:T,signedPsbtBase64:x,txId:E}}async pushPsbt(t){return await Xe.post(`${pi(this.network)}/api/tx`,t).then(r=>r.data)}}class j7 extends Dn{constructor(){super(...arguments),ge(this,"observer")}get library(){var t;return(t=window==null?void 0:window.phantom)==null?void 0:t.bitcoin}get network(){return this.$network.get()}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;this.library&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Di]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),gn(this.$store,["provider"],t=>{if(t.provider!==Di){this.removeListeners();return}this.library.requestAccounts().then(r=>{this.handleAccountsChanged(r)}),this.addListeners()})}addListeners(){this.library.on("accountsChanged",this.handleAccountsChanged.bind(this)),this.library.on("networkChanged",this.handleNetworkChanged.bind(this))}removeListeners(){this.library.removeListener("accountsChanged",this.handleAccountsChanged.bind(this)),this.library.removeListener("networkChanged",this.handleNetworkChanged.bind(this))}dispose(){var t;(t=this.observer)==null||t.disconnect(),this.removeListeners()}handleAccountsChanged(t){if(!t.length){this.parent.disconnect();return}this.$store.get().accounts[0]!==t[0]&&(this.$store.setKey("accounts",t),t.length>0?this.parent.connect(Di):this.parent.disconnect())}handleNetworkChanged(t){const r=Ea(t);this.network!==r&&this.switchNetwork(r),this.parent.connect(Di)}async connect(t){if(!this.library)throw new Error("Unisat isn't installed");const r=await this.library.requestAccounts();if(console.log("phantomAccounts",r),!r)throw new Error("No accounts found");this.$store.setKey("accounts",r);const n=r.find(o=>o.purpose==="ordinals"),i=r.find(o=>o.purpose==="payment");this.$store.setKey("address",n.address),this.$store.setKey("paymentAddress",i.address),this.$store.setKey("publicKey",n.publicKey),this.$store.setKey("paymentPublicKey",i.publicKey),this.$store.setKey("provider",Di),Xt(r[0],this.network).then(o=>{this.$store.setKey("balance",o)}),this.$store.setKey("connected",!0)}async getNetwork(){return this.$store.get().address.slice(0,1)==="t"?Rt:vt}async sendBTC(t,r){const{psbtHex:n}=await M2(this.$store.get().address,this.$store.get().paymentAddress,t,r,this.$store.get().paymentPublicKey,this.network,7),i=await this.signPsbt("",n,"",!0,!0);if(!i)throw new Error("Error sending BTC");return i.txId}async signMessage(t,r){var n;const i=new TextEncoder().encode(t),o=new Uint8Array(i),s=r||this.$store.get().paymentAddress,a=await((n=this.library)==null?void 0:n.signMessage(s,o)),u=String.fromCharCode(...a.signature);return btoa(u)}async signPsbt(t,r,n,i,o){const{address:s,paymentAddress:a}=this.$store.get(),u=dt.fromHex(String(r),{network:nr(this.network)}).data.inputs,f=[],h={address:s,signingIndexes:[]},d={address:a,signingIndexes:[]};let g=0;for await(let T of u){const{script:x}=T.witnessUtxo,N=ga(x,nr(this.network));N===a?d.signingIndexes.push(Number(g)):N===s&&h.signingIndexes.push(Number(g)),g++}h.signingIndexes.length>0&&f.push(h),d.signingIndexes.length>0&&f.push(d);const v=await this.library.signPsbt(r,{inputsToSign:f}),E=dt.fromHex(v);if(i&&o){const T=await this.pushPsbt(v);return{signedPsbtHex:E.toHex(),signedPsbtBase64:E.toBase64(),txId:T}}return{signedPsbtHex:E.toHex(),signedPsbtBase64:E.toBase64(),txId:void 0}}async pushPsbt(t){return await Xe.post(`${pi(this.network)}/api/tx`,t).then(r=>r.data)}async getPublicKey(){return this.$store.get().publicKey}async getBalance(){return(await this.library.getBalance()).total}async getInscriptions(){return await this.library.getInscriptions(0,10)}async requestAccounts(){return await this.library.requestAccounts()}async switchNetwork(t){var r;const n=Df(t);await((r=this.library)==null?void 0:r.switchChain(n)),this.$network.set(t),await this.getBalance()}}class D7 extends Dn{constructor(){super(...arguments),ge(this,"observer")}get library(){return window.opnet}get network(){return this.$network.get()}initialize(){typeof window<"u"&&typeof document<"u"&&(this.observer=new window.MutationObserver(()=>{var t;this.library&&(this.$store.setKey("hasProvider",{...this.$store.get().hasProvider,[Fi]:!0}),(t=this.observer)==null||t.disconnect())}),this.observer.observe(document,{childList:!0,subtree:!0})),gn(this.$store,["provider"],t=>{if(t.provider!==Fi){this.removeListeners();return}this.library.getAccounts().then(r=>{this.handleAccountsChanged(r)}),this.addListeners()})}addListeners(){this.library.on("accountsChanged",this.handleAccountsChanged.bind(this)),this.library.on("networkChanged",this.handleNetworkChanged.bind(this))}removeListeners(){this.library.removeListener("accountsChanged",this.handleAccountsChanged.bind(this)),this.library.removeListener("networkChanged",this.handleNetworkChanged.bind(this))}dispose(){var t;(t=this.observer)==null||t.disconnect(),this.removeListeners()}handleAccountsChanged(t){if(!t.length){this.parent.disconnect();return}this.$store.get().accounts[0]!==t[0]&&(this.$store.setKey("accounts",t),t.length>0?this.parent.connect(Fi):this.parent.disconnect())}handleNetworkChanged(t){const r=Ea(t);this.network!==r&&this.switchNetwork(r),this.parent.connect(Fi)}async connect(t){if(!this.library)throw new Error("OP_NET isn't installed");const r=await this.library.requestAccounts();if(!r)throw new Error("No accounts found");const n=await this.library.getPublicKey();if(!n)throw new Error("No public key found");this.$store.setKey("accounts",r),this.$store.setKey("address",r[0]),this.$store.setKey("paymentAddress",r[0]),this.$store.setKey("publicKey",n),this.$store.setKey("paymentPublicKey",n),this.$store.setKey("provider",Fi),await this.getNetwork().then(i=>{var o;((o=this.config)==null?void 0:o.network)!==i&&this.switchNetwork(i)}),Xt(r[0],this.network).then(i=>{this.$store.setKey("balance",i)}),this.$store.setKey("connected",!0)}async getNetwork(){var t;const r=await((t=this.library)==null?void 0:t.getChain());return r?Ea(r.enum):this.network}async sendBTC(t,r){var n;const i=await((n=this.library)==null?void 0:n.sendBitcoin(t,r));if(!i)throw new Error("Transaction failed");return i}async signMessage(t,r){var n;return await((n=this.library)==null?void 0:n.signMessage(t))}async signPsbt(t,r,n,i,o){var s;const a=await((s=this.library)==null?void 0:s.signPsbt(r,{autoFinalized:i})),u=dt.fromHex(a);if(i&&o){const f=await this.pushPsbt(a);return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:f}}return{signedPsbtHex:u.toHex(),signedPsbtBase64:u.toBase64(),txId:void 0}}async pushPsbt(t){return await Xe.post(`${pi(this.network)}/api/tx`,t).then(r=>r.data)}async getPublicKey(){var t;return await((t=this.library)==null?void 0:t.getPublicKey())}async getBalance(){return(await this.library.getBalance()).total}async getInscriptions(){return await this.library.getInscriptions(0,10)}async requestAccounts(){return await this.library.requestAccounts()}async switchNetwork(t){var r;const n=Df(t);await((r=this.library)==null?void 0:r.switchChain(n)),this.$network.set(t),await this.getBalance()}}class M7{constructor(t,r){ge(this,"$store"),ge(this,"$network"),ge(this,"$providerMap"),this.config=r,this.$store=t.$store,this.$network=t.$network,this.$providerMap={[vs]:new c7(t,this,r),[si]:new K7(t,this,r),[Es]:new H7(t,this,r),[Fi]:new D7(t,this,r),[Mi]:new U7(t,this,r),[ms]:new o7(t,this,r),[Di]:new j7(t,this,r),[ji]:new zx(t,this,r),[ii]:new n7(t,this,r),[As]:new i7(t,this,r)},this.$network.subscribe(this.watchNetworkChange.bind(this)),Hg(this.$store,["isInitializing"],n=>this.handleIsInitializingChanged(n.isInitializing)),r&&r.network&&(this.$network.set(r.network),this.getNetwork().then(n=>{try{r.network!==n&&this.switchNetwork(r.network)}catch{this.disconnect()}})),Hg(this.$store,["hasProvider"],this.checkInitializationComplete.bind(this)),Wx()}dispose(){Object.values(this.$providerMap).forEach(t=>t==null?void 0:t.dispose())}handleIsInitializingChanged(t){if(typeof window<"u"&&typeof localStorage<"u"&&!t){const r=localStorage==null?void 0:localStorage.getItem(rf);r&&(this.$store.setKey("provider",r),this.connect(r))}}async connect(t){this.$store.setKey("isConnecting",!0);try{if(localStorage==null||localStorage.setItem(rf,t),!this.$providerMap[t])throw new Error("Unsupported wallet provider");const r=this.$providerMap[t];await(r==null?void 0:r.connect(t)),this.$store.setKey("connected",!0)}catch(r){throw console.error(r),this.$store.setKey("isConnecting",!1),this.disconnect(),r}finally{this.$store.setKey("isConnecting",!1)}}async requestAccounts(){var t;if(!this.$store.get().provider)throw new Error("No wallet provider connected");if(!this.$providerMap[this.$store.get().provider])throw new Error("The connected wallet doesn't support this method");try{return await((t=this.$providerMap[this.$store.get().provider])==null?void 0:t.requestAccounts())}catch(r){throw r instanceof Error&&r.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support this method"):r}}disconnect(){this.$store.setKey("connected",!1),this.$store.setKey("provider",void 0),this.$store.setKey("address",""),this.$store.setKey("paymentAddress",""),this.$store.setKey("publicKey",""),this.$store.setKey("paymentPublicKey",""),this.$store.setKey("balance",void 0),this.$store.setKey("accounts",[]),localStorage==null||localStorage.removeItem(rf)}switchNetwork(t){var r;try{this.$store.get().provider&&((r=this.$providerMap[this.$store.get().provider])==null||r.switchNetwork(t))}catch(n){throw n instanceof Error&&n.message.toLowerCase().includes("not implemented")?(this.disconnect(),new Error("The connected wallet doesn't support programmatic network changes..")):n}}checkInitializationComplete(){Object.values(this.$store.get().hasProvider).every(t=>t!==void 0)&&this.$store.setKey("isInitializing",!1)}watchNetworkChange(){this.$store.setKey("balance",void 0)}async getNetwork(){var t;return this.$store.get().provider&&this.$providerMap[this.$store.get().provider]?await((t=this.$providerMap[this.$store.get().provider])==null?void 0:t.getNetwork()):this.$network.get()}async sendBTC(t,r){var n;if(r<=0)throw new Error("Amount must be greater than 0");if(!Number.isInteger(r))throw new Error("Amount must be an integer");if(!this.$store.get().provider)throw new Error("No wallet connected");if(this.$providerMap[this.$store.get().provider])try{return await((n=this.$providerMap[this.$store.get().provider])==null?void 0:n.sendBTC(t,r))}catch(i){throw i instanceof Error&&i.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support sending BTC..."):i}}async signMessage(t,r){var n;if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((n=this.$providerMap[this.$store.get().provider])==null?void 0:n.signMessage(t,r))}catch(i){throw i instanceof Error&&i.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support message signing..."):i}}async signPsbt(t,r=!1,n=!1){var i;let o,s;if(!t)throw new Error("No PSBT provided");if(Mx(t))s=dt.fromHex(t).toBase64(),o=t;else if(Dx(t))s=t,o=dt.fromBase64(t).toHex();else throw new Error("Invalid PSBT format");if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((i=this.$providerMap[this.$store.get().provider])==null?void 0:i.signPsbt(t,o,s,r,n))}catch(a){throw a instanceof Error&&a.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support PSBT signing..."):a}else throw new Error("No wallet provider connected")}async pushPsbt(t){var r;if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((r=this.$providerMap[this.$store.get().provider])==null?void 0:r.pushPsbt(t))}catch(n){throw n instanceof Error&&n.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support PSBT signing..."):n}}async getPublicKey(){var t;if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((t=this.$providerMap[this.$store.get().provider])==null?void 0:t.getPublicKey())}catch(r){throw r instanceof Error&&r.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support this method"):r}}async getBalance(){if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{const t=await this.$providerMap[this.$store.get().provider].getBalance();return this.$store.setKey("balance",BigInt(t)),t}catch(t){throw t instanceof Error&&t.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support this method"):t}}async getInscriptions(){var t;if(this.$store.get().provider&&this.$providerMap[this.$store.get().provider])try{return await((t=this.$providerMap[this.$store.get().provider])==null?void 0:t.getInscriptions())}catch(r){throw r instanceof Error&&r.message.toLowerCase().includes("not implemented")?new Error("The connected wallet doesn't support this method"):r}}}const F7={hasUnisat:!1,hasXverse:!1,hasOyl:!1,hasMagicEden:!1,hasOkx:!1,hasOrange:!1,hasOpNet:!1,hasLeather:!1,hasPhantom:!1,hasWizz:!1,isInitializing:!0,connected:!1,isConnecting:!1,publicKey:"",address:"",paymentAddress:"",paymentPublicKey:"",balance:void 0,network:vt,library:null,provider:null,accounts:[],connect:async e=>{},disconnect:()=>{},requestAccounts:async()=>[],getNetwork:async()=>vt,switchNetwork:async e=>{},getPublicKey:async()=>"",getBalance:async()=>"",getInscriptions:async()=>[],sendBTC:async(e,t)=>"",signMessage:async e=>"",signPsbt:async e=>({signedPsbtHex:"",signedPsbtBase64:"",txId:""}),pushPsbt:async e=>"",inscribe:async e=>"",isCreatingCommit:!1,isInscribing:!1},Vb=tn.createContext(F7),V7=()=>tn.useContext(Vb);var Cd={exports:{}},Ba={};/**
|
|
58
58
|
* @license React
|
|
59
59
|
* react-jsx-runtime.production.min.js
|
|
60
60
|
*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnisat/lasereyes",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.90",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.umd.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"vite-plugin-dts": "^4.2.1"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@omnisat/lasereyes-core": "0.0.
|
|
26
|
-
"@omnisat/lasereyes-react": "0.0.
|
|
25
|
+
"@omnisat/lasereyes-core": "0.0.21",
|
|
26
|
+
"@omnisat/lasereyes-react": "0.0.17-rc.0"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|