@babylonlabs-io/wallet-connector 0.5.1 → 0.5.2
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.cjs.js
CHANGED
|
@@ -76,5 +76,5 @@ ${E.length}`);return(0,e.keccak256)((0,r.concatBytes)(I,E))};return signature$1.
|
|
|
76
76
|
Given value: ${r.toString()}`);this[t]=new Bytes(t,r,this.ordinalWidth),this[r.toString()]=this[t]}from(t){return t instanceof Bytes?t:this[t]}fromParser(t){return this.from(t.readUIntN(this.ordinalWidth).toString())}}bytes$2.BytesLookup=BytesLookup;var field={},serializedType={},binarySerializer={},__createBinding$2=commonjsGlobal&&commonjsGlobal.__createBinding||(Object.create?function(e,t,r,s){s===void 0&&(s=r);var o=Object.getOwnPropertyDescriptor(t,r);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,o)}:function(e,t,r,s){s===void 0&&(s=r),e[s]=t[r]}),__setModuleDefault$2=commonjsGlobal&&commonjsGlobal.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar$2=commonjsGlobal&&commonjsGlobal.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)r!=="default"&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding$2(t,e,r);return __setModuleDefault$2(t,e),t};Object.defineProperty(binarySerializer,"__esModule",{value:!0});binarySerializer.BinarySerializer=binarySerializer.BytesList=void 0;const assert$3=__importStar$2(requireAssert()),buffer_1$n=dist$t;class BytesList{constructor(){this.bytesArray=[]}getLength(){return buffer_1$n.Buffer.concat(this.bytesArray).byteLength}put(t){const r=buffer_1$n.Buffer.from(t);return this.bytesArray.push(r),this}toBytesSink(t){t.put(this.toBytes())}toBytes(){return buffer_1$n.Buffer.concat(this.bytesArray)}toHex(){return this.toBytes().toString("hex").toUpperCase()}}binarySerializer.BytesList=BytesList;class BinarySerializer{constructor(t){this.sink=new BytesList,this.sink=t}write(t){t.toBytesSink(this.sink)}put(t){this.sink.put(t)}writeType(t,r){this.write(t.from(r))}writeBytesList(t){t.toBytesSink(this.sink)}encodeVariableLength(t){const r=buffer_1$n.Buffer.alloc(3);if(t<=192)return r[0]=t,r.slice(0,1);if(t<=12480)return t-=193,r[0]=193+(t>>>8),r[1]=t&255,r.slice(0,2);if(t<=918744)return t-=12481,r[0]=241+(t>>>16),r[1]=t>>8&255,r[2]=t&255,r.slice(0,3);throw new Error("Overflow error")}writeFieldAndValue(t,r,s=!1){const o=t.associatedType.from(r);assert$3.ok(o.toBytesSink!==void 0),assert$3.ok(t.name!==void 0),this.sink.put(t.header),t.isVariableLengthEncoded?this.writeLengthEncoded(o,s):o.toBytesSink(this.sink)}writeLengthEncoded(t,r=!1){const s=new BytesList;r||t.toBytesSink(s),this.put(this.encodeVariableLength(s.getLength())),this.writeBytesList(s)}}binarySerializer.BinarySerializer=BinarySerializer;Object.defineProperty(serializedType,"__esModule",{value:!0});serializedType.Comparable=serializedType.SerializedType=void 0;const binary_serializer_1$2=binarySerializer,buffer_1$m=dist$t;class SerializedType{constructor(t){this.bytes=buffer_1$m.Buffer.alloc(0),this.bytes=t??buffer_1$m.Buffer.alloc(0)}static fromParser(t,r){throw new Error("fromParser not implemented")}static from(t){throw new Error("from not implemented")}toBytesSink(t){t.put(this.bytes)}toHex(){return this.toBytes().toString("hex").toUpperCase()}toBytes(){if(this.bytes)return this.bytes;const t=new binary_serializer_1$2.BytesList;return this.toBytesSink(t),t.toBytes()}toJSON(t){return this.toHex()}toString(){return this.toHex()}}serializedType.SerializedType=SerializedType;class Comparable extends SerializedType{lt(t){return this.compareTo(t)<0}eq(t){return this.compareTo(t)===0}gt(t){return this.compareTo(t)>0}gte(t){return this.compareTo(t)>-1}lte(t){return this.compareTo(t)<1}compareTo(t){throw new Error(`cannot compare ${this.toString()} and ${t.toString()}`)}}serializedType.Comparable=Comparable;var constants={};Object.defineProperty(constants,"__esModule",{value:!0});constants.TRANSACTION_RESULT_WIDTH=constants.TRANSACTION_TYPE_WIDTH=constants.LEDGER_ENTRY_WIDTH=constants.TYPE_WIDTH=void 0;constants.TYPE_WIDTH=2;constants.LEDGER_ENTRY_WIDTH=2;constants.TRANSACTION_TYPE_WIDTH=2;constants.TRANSACTION_RESULT_WIDTH=1;Object.defineProperty(field,"__esModule",{value:!0});field.FieldLookup=void 0;const bytes_1=bytes$2,serialized_type_1$8=serializedType,constants_1=constants,buffer_1$l=dist$t;function fieldHeader(e,t){const r=[];return e<16?t<16?r.push(e<<4|t):r.push(e<<4,t):t<16?r.push(t,e):r.push(0,e,t),buffer_1$l.Buffer.from(r)}function buildField([e,t],r){const s=fieldHeader(r,t.nth);return{name:e,nth:t.nth,isVariableLengthEncoded:t.isVLEncoded,isSerialized:t.isSerialized,isSigningField:t.isSigningField,ordinal:r<<16|t.nth,type:new bytes_1.Bytes(t.type,r,constants_1.TYPE_WIDTH),header:s,associatedType:serialized_type_1$8.SerializedType}}class FieldLookup{constructor(t,r){t.forEach(([s,o])=>{const n=r[o.type];this[s]=buildField([s,o],n),this[this[s].ordinal.toString()]=this[s]})}fromString(t){return this[t]}}field.FieldLookup=FieldLookup;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.BytesLookup=e.Bytes=e.FieldLookup=e.XrplDefinitionsBase=void 0;const t=bytes$2;Object.defineProperty(e,"Bytes",{enumerable:!0,get:function(){return t.Bytes}}),Object.defineProperty(e,"BytesLookup",{enumerable:!0,get:function(){return t.BytesLookup}});const r=field;Object.defineProperty(e,"FieldLookup",{enumerable:!0,get:function(){return r.FieldLookup}});const s=constants;class o{constructor(a,l){this.type=new t.BytesLookup(a.TYPES,s.TYPE_WIDTH),this.ledgerEntryType=new t.BytesLookup(a.LEDGER_ENTRY_TYPES,s.LEDGER_ENTRY_WIDTH),this.transactionType=new t.BytesLookup(a.TRANSACTION_TYPES,s.TRANSACTION_TYPE_WIDTH),this.transactionResult=new t.BytesLookup(a.TRANSACTION_RESULTS,s.TRANSACTION_RESULT_WIDTH),this.field=new r.FieldLookup(a.FIELDS,a.TYPES),this.transactionNames=Object.entries(a.TRANSACTION_TYPES).filter(([p,u])=>u>=0).map(([p,u])=>p),this.dataTypes={},this.associateTypes(l)}associateTypes(a){this.dataTypes=Object.assign({},this.dataTypes,a),Object.values(this.field).forEach(l=>{l.associatedType=this.dataTypes[l.type.name]}),this.field.TransactionType.associatedType=this.transactionType,this.field.TransactionResult.associatedType=this.transactionResult,this.field.LedgerEntryType.associatedType=this.ledgerEntryType}getAssociatedTypes(){return this.dataTypes}}e.XrplDefinitionsBase=o})(xrplDefinitionsBase);(function(e){var t=commonjsGlobal&&commonjsGlobal.__createBinding||(Object.create?function(b,E,I,x){x===void 0&&(x=I);var B=Object.getOwnPropertyDescriptor(E,I);(!B||("get"in B?!E.__esModule:B.writable||B.configurable))&&(B={enumerable:!0,get:function(){return E[I]}}),Object.defineProperty(b,x,B)}:function(b,E,I,x){x===void 0&&(x=I),b[x]=E[I]}),r=commonjsGlobal&&commonjsGlobal.__setModuleDefault||(Object.create?function(b,E){Object.defineProperty(b,"default",{enumerable:!0,value:E})}:function(b,E){b.default=E}),s=commonjsGlobal&&commonjsGlobal.__importStar||function(b){if(b&&b.__esModule)return b;var E={};if(b!=null)for(var I in b)I!=="default"&&Object.prototype.hasOwnProperty.call(b,I)&&t(E,b,I);return r(E,b),E};Object.defineProperty(e,"__esModule",{value:!0}),e.TRANSACTION_TYPES=e.TransactionType=e.TransactionResult=e.LedgerEntryType=e.Type=e.Field=e.DEFAULT_DEFINITIONS=e.XrplDefinitionsBase=e.Bytes=void 0;const o=s(require$$0),n=xrplDefinitionsBase;Object.defineProperty(e,"XrplDefinitionsBase",{enumerable:!0,get:function(){return n.XrplDefinitionsBase}}),Object.defineProperty(e,"Bytes",{enumerable:!0,get:function(){return n.Bytes}});const a=new n.XrplDefinitionsBase(o,{});e.DEFAULT_DEFINITIONS=a;const l=a.type;e.Type=l;const p=a.ledgerEntryType;e.LedgerEntryType=p;const u=a.transactionType;e.TransactionType=u;const c=a.transactionResult;e.TransactionResult=c;const v=a.field;e.Field=v;const w=a.transactionNames;e.TRANSACTION_TYPES=w})(enums);var types$5={},accountId={},dist$1={},xrpCodec={},_Buffer=safeBufferExports.Buffer;function base(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var s=0;s<e.length;s++){var o=e.charAt(s),n=o.charCodeAt(0);if(t[n]!==255)throw new TypeError(o+" is ambiguous");t[n]=s}var a=e.length,l=e.charAt(0),p=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function c(b){if((Array.isArray(b)||b instanceof Uint8Array)&&(b=_Buffer.from(b)),!_Buffer.isBuffer(b))throw new TypeError("Expected Buffer");if(b.length===0)return"";for(var E=0,I=0,x=0,B=b.length;x!==B&&b[x]===0;)x++,E++;for(var M=(B-x)*u+1>>>0,q=new Uint8Array(M);x!==B;){for(var U=b[x],F=0,j=M-1;(U!==0||F<I)&&j!==-1;j--,F++)U+=256*q[j]>>>0,q[j]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");I=F,x++}for(var y=M-I;y!==M&&q[y]===0;)y++;for(var T=l.repeat(E);y<M;++y)T+=e.charAt(q[y]);return T}function v(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return _Buffer.alloc(0);for(var E=0,I=0,x=0;b[E]===l;)I++,E++;for(var B=(b.length-E)*p+1>>>0,M=new Uint8Array(B);E<b.length;){var q=t[b.charCodeAt(E)];if(q===255)return;for(var U=0,F=B-1;(q!==0||U<x)&&F!==-1;F--,U++)q+=a*M[F]>>>0,M[F]=q%256>>>0,q=q/256>>>0;if(q!==0)throw new Error("Non-zero carry");x=U,E++}for(var j=B-x;j!==B&&M[j]===0;)j++;var y=_Buffer.allocUnsafe(I+(B-j));y.fill(0,0,I);for(var T=I;j!==B;)y[T++]=M[j++];return y}function w(b){var E=v(b);if(E)return E;throw new Error("Non-base"+a+" character")}return{encode:c,decodeUnsafe:v,decode:w}}var src=base,utils={};Object.defineProperty(utils,"__esModule",{value:!0});utils.concatArgs=utils.seqEqual=void 0;function seqEqual(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}utils.seqEqual=seqEqual;function isSequence(e){return typeof e!="number"}function concatArgs(...e){const t=[];return e.forEach(r=>{if(isSequence(r))for(const s of r)t.push(s);else t.push(r)}),t}utils.concatArgs=concatArgs;Object.defineProperty(xrpCodec,"__esModule",{value:!0});xrpCodec.isValidClassicAddress=xrpCodec.decodeAccountPublic=xrpCodec.encodeAccountPublic=xrpCodec.encodeNodePublic=xrpCodec.decodeNodePublic=xrpCodec.decodeAddress=xrpCodec.decodeAccountID=xrpCodec.encodeAddress=xrpCodec.encodeAccountID=xrpCodec.decodeSeed=xrpCodec.encodeSeed=xrpCodec.codec=void 0;const baseCodec=src,createHash$1=browser$a,utils_1=utils;class Codec{constructor(t){this._sha256=t.sha256,this._alphabet=t.alphabet,this._codec=baseCodec(this._alphabet)}encode(t,r){const s=r.versions;return this._encodeVersioned(t,s,r.expectedLength)}decode(t,r){var s;const o=r.versions,n=r.versionTypes,a=this.decodeChecked(t);if(o.length>1&&!r.expectedLength)throw new Error("expectedLength is required because there are >= 2 possible versions");const l=typeof o[0]=="number"?1:o[0].length,p=(s=r.expectedLength)!==null&&s!==void 0?s:a.length-l,u=a.slice(0,-p),c=a.slice(-p);for(let v=0;v<o.length;v++){const w=Array.isArray(o[v])?o[v]:[o[v]];if((0,utils_1.seqEqual)(u,w))return{version:w,bytes:c,type:n?n[v]:null}}throw new Error("version_invalid: version bytes do not match any of the provided version(s)")}encodeChecked(t){const r=this._sha256(this._sha256(t)).slice(0,4);return this._encodeRaw(Buffer$e.from((0,utils_1.concatArgs)(t,r)))}decodeChecked(t){const r=this._decodeRaw(t);if(r.length<5)throw new Error("invalid_input_size: decoded data must have length >= 5");if(!this._verifyCheckSum(r))throw new Error("checksum_invalid");return r.slice(0,-4)}_encodeVersioned(t,r,s){if(s&&t.length!==s)throw new Error("unexpected_payload_length: bytes.length does not match expectedLength. Ensure that the bytes are a Buffer.");return this.encodeChecked(Buffer$e.from((0,utils_1.concatArgs)(r,t)))}_encodeRaw(t){return this._codec.encode(t)}_decodeRaw(t){return this._codec.decode(t)}_verifyCheckSum(t){const r=this._sha256(this._sha256(t.slice(0,-4))).slice(0,4),s=t.slice(-4);return(0,utils_1.seqEqual)(r,s)}}const ACCOUNT_ID=0,ACCOUNT_PUBLIC_KEY=35,FAMILY_SEED=33,NODE_PUBLIC=28,ED25519_SEED=[1,225,75],codecOptions={sha256(e){return createHash$1("sha256").update(Buffer$e.from(e)).digest()},alphabet:"rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"},codecWithXrpAlphabet=new Codec(codecOptions);xrpCodec.codec=codecWithXrpAlphabet;function encodeSeed(e,t){if(e.length!==16)throw new Error("entropy must have length 16");const r={expectedLength:16,versions:t==="ed25519"?ED25519_SEED:[FAMILY_SEED]};return codecWithXrpAlphabet.encode(e,r)}xrpCodec.encodeSeed=encodeSeed;function decodeSeed(e,t={versionTypes:["ed25519","secp256k1"],versions:[ED25519_SEED,FAMILY_SEED],expectedLength:16}){return codecWithXrpAlphabet.decode(e,t)}xrpCodec.decodeSeed=decodeSeed;function encodeAccountID(e){const t={versions:[ACCOUNT_ID],expectedLength:20};return codecWithXrpAlphabet.encode(e,t)}xrpCodec.encodeAccountID=encodeAccountID;xrpCodec.encodeAddress=encodeAccountID;function decodeAccountID(e){const t={versions:[ACCOUNT_ID],expectedLength:20};return codecWithXrpAlphabet.decode(e,t).bytes}xrpCodec.decodeAccountID=decodeAccountID;xrpCodec.decodeAddress=decodeAccountID;function decodeNodePublic(e){const t={versions:[NODE_PUBLIC],expectedLength:33};return codecWithXrpAlphabet.decode(e,t).bytes}xrpCodec.decodeNodePublic=decodeNodePublic;function encodeNodePublic(e){const t={versions:[NODE_PUBLIC],expectedLength:33};return codecWithXrpAlphabet.encode(e,t)}xrpCodec.encodeNodePublic=encodeNodePublic;function encodeAccountPublic(e){const t={versions:[ACCOUNT_PUBLIC_KEY],expectedLength:33};return codecWithXrpAlphabet.encode(e,t)}xrpCodec.encodeAccountPublic=encodeAccountPublic;function decodeAccountPublic(e){const t={versions:[ACCOUNT_PUBLIC_KEY],expectedLength:33};return codecWithXrpAlphabet.decode(e,t).bytes}xrpCodec.decodeAccountPublic=decodeAccountPublic;function isValidClassicAddress(e){try{decodeAccountID(e)}catch{return!1}return!0}xrpCodec.isValidClassicAddress=isValidClassicAddress;(function(e){var t=commonjsGlobal&&commonjsGlobal.__createBinding||(Object.create?function(I,x,B,M){M===void 0&&(M=B);var q=Object.getOwnPropertyDescriptor(x,B);(!q||("get"in q?!x.__esModule:q.writable||q.configurable))&&(q={enumerable:!0,get:function(){return x[B]}}),Object.defineProperty(I,M,q)}:function(I,x,B,M){M===void 0&&(M=B),I[M]=x[B]}),r=commonjsGlobal&&commonjsGlobal.__setModuleDefault||(Object.create?function(I,x){Object.defineProperty(I,"default",{enumerable:!0,value:x})}:function(I,x){I.default=x}),s=commonjsGlobal&&commonjsGlobal.__importStar||function(I){if(I&&I.__esModule)return I;var x={};if(I!=null)for(var B in I)B!=="default"&&Object.prototype.hasOwnProperty.call(I,B)&&t(x,I,B);return r(x,I),x};Object.defineProperty(e,"__esModule",{value:!0}),e.isValidXAddress=e.decodeXAddress=e.xAddressToClassicAddress=e.encodeXAddress=e.classicAddressToXAddress=e.isValidClassicAddress=e.decodeAccountPublic=e.encodeAccountPublic=e.decodeNodePublic=e.encodeNodePublic=e.decodeAccountID=e.encodeAccountID=e.decodeSeed=e.encodeSeed=e.codec=void 0;const o=s(requireAssert()),n=xrpCodec;Object.defineProperty(e,"codec",{enumerable:!0,get:function(){return n.codec}}),Object.defineProperty(e,"encodeSeed",{enumerable:!0,get:function(){return n.encodeSeed}}),Object.defineProperty(e,"decodeSeed",{enumerable:!0,get:function(){return n.decodeSeed}}),Object.defineProperty(e,"encodeAccountID",{enumerable:!0,get:function(){return n.encodeAccountID}}),Object.defineProperty(e,"decodeAccountID",{enumerable:!0,get:function(){return n.decodeAccountID}}),Object.defineProperty(e,"encodeNodePublic",{enumerable:!0,get:function(){return n.encodeNodePublic}}),Object.defineProperty(e,"decodeNodePublic",{enumerable:!0,get:function(){return n.decodeNodePublic}}),Object.defineProperty(e,"encodeAccountPublic",{enumerable:!0,get:function(){return n.encodeAccountPublic}}),Object.defineProperty(e,"decodeAccountPublic",{enumerable:!0,get:function(){return n.decodeAccountPublic}}),Object.defineProperty(e,"isValidClassicAddress",{enumerable:!0,get:function(){return n.isValidClassicAddress}});const a={main:Buffer$e.from([5,68]),test:Buffer$e.from([4,147])},l=4294967295;function p(I,x,B){const M=(0,n.decodeAccountID)(I);return u(M,x,B)}e.classicAddressToXAddress=p;function u(I,x,B){if(I.length!==20)throw new Error("Account ID must be 20 bytes");if(x>l)throw new Error("Invalid tag");const M=x||0,q=x===!1||x==null?0:1,U=Buffer$e.concat([B?a.test:a.main,I,Buffer$e.from([q,M&255,M>>8&255,M>>16&255,M>>24&255,0,0,0,0])]);return n.codec.encodeChecked(U)}e.encodeXAddress=u;function c(I){const{accountId:x,tag:B,test:M}=v(I);return{classicAddress:(0,n.encodeAccountID)(x),tag:B,test:M}}e.xAddressToClassicAddress=c;function v(I){const x=n.codec.decodeChecked(I),B=w(x),M=x.slice(2,22),q=b(x);return{accountId:M,tag:q,test:B}}e.decodeXAddress=v;function w(I){const x=I.slice(0,2);if(a.main.equals(x))return!1;if(a.test.equals(x))return!0;throw new Error("Invalid X-address: bad prefix")}function b(I){const x=I[22];if(x>=2)throw new Error("Unsupported X-address");return x===1?I[23]+I[24]*256+I[25]*65536+I[26]*16777216:(o.strictEqual(x,0,"flag must be zero to indicate no tag"),o.ok(Buffer$e.from("0000000000000000","hex").equals(I.slice(23,31)),"remaining bytes must be zero"),!1)}function E(I){try{v(I)}catch{return!1}return!0}e.isValidXAddress=E})(dist$1);var hash160$1={},hash$1={};Object.defineProperty(hash$1,"__esModule",{value:!0});hash$1.Hash=void 0;const serialized_type_1$7=serializedType,buffer_1$k=dist$t;let Hash$1=class extends serialized_type_1$7.Comparable{constructor(t){if(super(t),this.bytes.byteLength!==this.constructor.width)throw new Error(`Invalid Hash length ${this.bytes.byteLength}`)}static from(t){if(t instanceof this)return t;if(typeof t=="string")return new this(buffer_1$k.Buffer.from(t,"hex"));throw new Error("Cannot construct Hash from given value")}static fromParser(t,r){return new this(t.read(r??this.width))}compareTo(t){return this.bytes.compare(this.constructor.from(t).bytes)}toString(){return this.toHex()}nibblet(t){const r=t>0?t/2|0:0;let s=this.bytes[r];return t%2===0?s=(s&240)>>>4:s=s&15,s}};hash$1.Hash=Hash$1;Object.defineProperty(hash160$1,"__esModule",{value:!0});hash160$1.Hash160=void 0;const hash_1$2=hash$1,buffer_1$j=dist$t;class Hash160 extends hash_1$2.Hash{constructor(t){t&&t.byteLength===0&&(t=Hash160.ZERO_160.bytes),super(t??Hash160.ZERO_160.bytes)}}hash160$1.Hash160=Hash160;Hash160.width=20;Hash160.ZERO_160=new Hash160(buffer_1$j.Buffer.alloc(Hash160.width));Object.defineProperty(accountId,"__esModule",{value:!0});accountId.AccountID=void 0;const ripple_address_codec_1=dist$1,hash_160_1$1=hash160$1,buffer_1$i=dist$t,HEX_REGEX$2=/^[A-F0-9]{40}$/;class AccountID extends hash_160_1$1.Hash160{constructor(t){super(t??AccountID.defaultAccountID.bytes)}static from(t){if(t instanceof AccountID)return t;if(typeof t=="string")return t===""?new AccountID:HEX_REGEX$2.test(t)?new AccountID(buffer_1$i.Buffer.from(t,"hex")):this.fromBase58(t);throw new Error("Cannot construct AccountID from value given")}static fromBase58(t){if((0,ripple_address_codec_1.isValidXAddress)(t)){const r=(0,ripple_address_codec_1.xAddressToClassicAddress)(t);if(r.tag!==!1)throw new Error("Only allowed to have tag on Account or Destination");t=r.classicAddress}return new AccountID(buffer_1$i.Buffer.from((0,ripple_address_codec_1.decodeAccountID)(t)))}toJSON(){return this.toBase58()}toBase58(){return(0,ripple_address_codec_1.encodeAccountID)(this.bytes)}}accountId.AccountID=AccountID;AccountID.defaultAccountID=new AccountID(buffer_1$i.Buffer.alloc(20));var amount={},decimal={exports:{}};(function(e){(function(t){var r=9e15,s=1e9,o="0123456789abcdef",n="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",a="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",l={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-r,maxE:r,crypto:!1},p,u,c,v,w=!0,b="[DecimalError] ",E=b+"Invalid argument: ",I=b+"Precision limit exceeded",x=b+"crypto unavailable",B="[object Decimal]",M=Math.floor,q=Math.pow,U=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,F=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,j=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,y=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,T=1e7,D=7,L=9007199254740991,C=n.length-1,d=a.length-1,_={toStringTag:B};_.absoluteValue=_.abs=function(){var ie=new this.constructor(this);return ie.s<0&&(ie.s=1),m(ie)},_.ceil=function(){return m(new this.constructor(this),this.e+1,2)},_.clampedTo=_.clamp=function(ie,de){var ve,_e=this,Ee=_e.constructor;if(ie=new Ee(ie),de=new Ee(de),!ie.s||!de.s)return new Ee(NaN);if(ie.gt(de))throw Error(E+de);return ve=_e.cmp(ie),ve<0?ie:_e.cmp(de)>0?de:new Ee(_e)},_.comparedTo=_.cmp=function(ie){var de,ve,_e,Ee,Se=this,Pe=Se.d,Le=(ie=new Se.constructor(ie)).d,Ke=Se.s,Fe=ie.s;if(!Pe||!Le)return!Ke||!Fe?NaN:Ke!==Fe?Ke:Pe===Le?0:!Pe^Ke<0?1:-1;if(!Pe[0]||!Le[0])return Pe[0]?Ke:Le[0]?-Fe:0;if(Ke!==Fe)return Ke;if(Se.e!==ie.e)return Se.e>ie.e^Ke<0?1:-1;for(_e=Pe.length,Ee=Le.length,de=0,ve=_e<Ee?_e:Ee;de<ve;++de)if(Pe[de]!==Le[de])return Pe[de]>Le[de]^Ke<0?1:-1;return _e===Ee?0:_e>Ee^Ke<0?1:-1},_.cosine=_.cos=function(){var ie,de,ve=this,_e=ve.constructor;return ve.d?ve.d[0]?(ie=_e.precision,de=_e.rounding,_e.precision=ie+Math.max(ve.e,ve.sd())+D,_e.rounding=1,ve=k(_e,Ce(_e,ve)),_e.precision=ie,_e.rounding=de,m(v==2||v==3?ve.neg():ve,ie,de,!0)):new _e(1):new _e(NaN)},_.cubeRoot=_.cbrt=function(){var ie,de,ve,_e,Ee,Se,Pe,Le,Ke,Fe,ze=this,et=ze.constructor;if(!ze.isFinite()||ze.isZero())return new et(ze);for(w=!1,Se=ze.s*q(ze.s*ze,1/3),!Se||Math.abs(Se)==1/0?(ve=$(ze.d),ie=ze.e,(Se=(ie-ve.length+1)%3)&&(ve+=Se==1||Se==-2?"0":"00"),Se=q(ve,1/3),ie=M((ie+1)/3)-(ie%3==(ie<0?-1:2)),Se==1/0?ve="5e"+ie:(ve=Se.toExponential(),ve=ve.slice(0,ve.indexOf("e")+1)+ie),_e=new et(ve),_e.s=ze.s):_e=new et(Se.toString()),Pe=(ie=et.precision)+3;;)if(Le=_e,Ke=Le.times(Le).times(Le),Fe=Ke.plus(ze),_e=A(Fe.plus(ze).times(Le),Fe.plus(Ke),Pe+2,1),$(Le.d).slice(0,Pe)===(ve=$(_e.d)).slice(0,Pe))if(ve=ve.slice(Pe-3,Pe+1),ve=="9999"||!Ee&&ve=="4999"){if(!Ee&&(m(Le,ie+1,0),Le.times(Le).times(Le).eq(ze))){_e=Le;break}Pe+=4,Ee=1}else{(!+ve||!+ve.slice(1)&&ve.charAt(0)=="5")&&(m(_e,ie+1,1),de=!_e.times(_e).times(_e).eq(ze));break}return w=!0,m(_e,ie,et.rounding,de)},_.decimalPlaces=_.dp=function(){var ie,de=this.d,ve=NaN;if(de){if(ie=de.length-1,ve=(ie-M(this.e/D))*D,ie=de[ie],ie)for(;ie%10==0;ie/=10)ve--;ve<0&&(ve=0)}return ve},_.dividedBy=_.div=function(ie){return A(this,new this.constructor(ie))},_.dividedToIntegerBy=_.divToInt=function(ie){var de=this,ve=de.constructor;return m(A(de,new ve(ie),0,1,1),ve.precision,ve.rounding)},_.equals=_.eq=function(ie){return this.cmp(ie)===0},_.floor=function(){return m(new this.constructor(this),this.e+1,3)},_.greaterThan=_.gt=function(ie){return this.cmp(ie)>0},_.greaterThanOrEqualTo=_.gte=function(ie){var de=this.cmp(ie);return de==1||de===0},_.hyperbolicCosine=_.cosh=function(){var ie,de,ve,_e,Ee,Se=this,Pe=Se.constructor,Le=new Pe(1);if(!Se.isFinite())return new Pe(Se.s?1/0:NaN);if(Se.isZero())return Le;ve=Pe.precision,_e=Pe.rounding,Pe.precision=ve+Math.max(Se.e,Se.sd())+4,Pe.rounding=1,Ee=Se.d.length,Ee<32?(ie=Math.ceil(Ee/3),de=(1/Be(4,ie)).toString()):(ie=16,de="2.3283064365386962890625e-10"),Se=Re(Pe,1,Se.times(de),new Pe(1),!0);for(var Ke,Fe=ie,ze=new Pe(8);Fe--;)Ke=Se.times(Se),Se=Le.minus(Ke.times(ze.minus(Ke.times(ze))));return m(Se,Pe.precision=ve,Pe.rounding=_e,!0)},_.hyperbolicSine=_.sinh=function(){var ie,de,ve,_e,Ee=this,Se=Ee.constructor;if(!Ee.isFinite()||Ee.isZero())return new Se(Ee);if(de=Se.precision,ve=Se.rounding,Se.precision=de+Math.max(Ee.e,Ee.sd())+4,Se.rounding=1,_e=Ee.d.length,_e<3)Ee=Re(Se,2,Ee,Ee,!0);else{ie=1.4*Math.sqrt(_e),ie=ie>16?16:ie|0,Ee=Ee.times(1/Be(5,ie)),Ee=Re(Se,2,Ee,Ee,!0);for(var Pe,Le=new Se(5),Ke=new Se(16),Fe=new Se(20);ie--;)Pe=Ee.times(Ee),Ee=Ee.times(Le.plus(Pe.times(Ke.times(Pe).plus(Fe))))}return Se.precision=de,Se.rounding=ve,m(Ee,de,ve,!0)},_.hyperbolicTangent=_.tanh=function(){var ie,de,ve=this,_e=ve.constructor;return ve.isFinite()?ve.isZero()?new _e(ve):(ie=_e.precision,de=_e.rounding,_e.precision=ie+7,_e.rounding=1,A(ve.sinh(),ve.cosh(),_e.precision=ie,_e.rounding=de)):new _e(ve.s)},_.inverseCosine=_.acos=function(){var ie,de=this,ve=de.constructor,_e=de.abs().cmp(1),Ee=ve.precision,Se=ve.rounding;return _e!==-1?_e===0?de.isNeg()?X(ve,Ee,Se):new ve(0):new ve(NaN):de.isZero()?X(ve,Ee+4,Se).times(.5):(ve.precision=Ee+6,ve.rounding=1,de=de.asin(),ie=X(ve,Ee+4,Se).times(.5),ve.precision=Ee,ve.rounding=Se,ie.minus(de))},_.inverseHyperbolicCosine=_.acosh=function(){var ie,de,ve=this,_e=ve.constructor;return ve.lte(1)?new _e(ve.eq(1)?0:NaN):ve.isFinite()?(ie=_e.precision,de=_e.rounding,_e.precision=ie+Math.max(Math.abs(ve.e),ve.sd())+4,_e.rounding=1,w=!1,ve=ve.times(ve).minus(1).sqrt().plus(ve),w=!0,_e.precision=ie,_e.rounding=de,ve.ln()):new _e(ve)},_.inverseHyperbolicSine=_.asinh=function(){var ie,de,ve=this,_e=ve.constructor;return!ve.isFinite()||ve.isZero()?new _e(ve):(ie=_e.precision,de=_e.rounding,_e.precision=ie+2*Math.max(Math.abs(ve.e),ve.sd())+6,_e.rounding=1,w=!1,ve=ve.times(ve).plus(1).sqrt().plus(ve),w=!0,_e.precision=ie,_e.rounding=de,ve.ln())},_.inverseHyperbolicTangent=_.atanh=function(){var ie,de,ve,_e,Ee=this,Se=Ee.constructor;return Ee.isFinite()?Ee.e>=0?new Se(Ee.abs().eq(1)?Ee.s/0:Ee.isZero()?Ee:NaN):(ie=Se.precision,de=Se.rounding,_e=Ee.sd(),Math.max(_e,ie)<2*-Ee.e-1?m(new Se(Ee),ie,de,!0):(Se.precision=ve=_e-Ee.e,Ee=A(Ee.plus(1),new Se(1).minus(Ee),ve+ie,1),Se.precision=ie+4,Se.rounding=1,Ee=Ee.ln(),Se.precision=ie,Se.rounding=de,Ee.times(.5))):new Se(NaN)},_.inverseSine=_.asin=function(){var ie,de,ve,_e,Ee=this,Se=Ee.constructor;return Ee.isZero()?new Se(Ee):(de=Ee.abs().cmp(1),ve=Se.precision,_e=Se.rounding,de!==-1?de===0?(ie=X(Se,ve+4,_e).times(.5),ie.s=Ee.s,ie):new Se(NaN):(Se.precision=ve+6,Se.rounding=1,Ee=Ee.div(new Se(1).minus(Ee.times(Ee)).sqrt().plus(1)).atan(),Se.precision=ve,Se.rounding=_e,Ee.times(2)))},_.inverseTangent=_.atan=function(){var ie,de,ve,_e,Ee,Se,Pe,Le,Ke,Fe=this,ze=Fe.constructor,et=ze.precision,nt=ze.rounding;if(Fe.isFinite()){if(Fe.isZero())return new ze(Fe);if(Fe.abs().eq(1)&&et+4<=d)return Pe=X(ze,et+4,nt).times(.25),Pe.s=Fe.s,Pe}else{if(!Fe.s)return new ze(NaN);if(et+4<=d)return Pe=X(ze,et+4,nt).times(.5),Pe.s=Fe.s,Pe}for(ze.precision=Le=et+10,ze.rounding=1,ve=Math.min(28,Le/D+2|0),ie=ve;ie;--ie)Fe=Fe.div(Fe.times(Fe).plus(1).sqrt().plus(1));for(w=!1,de=Math.ceil(Le/D),_e=1,Ke=Fe.times(Fe),Pe=new ze(Fe),Ee=Fe;ie!==-1;)if(Ee=Ee.times(Ke),Se=Pe.minus(Ee.div(_e+=2)),Ee=Ee.times(Ke),Pe=Se.plus(Ee.div(_e+=2)),Pe.d[de]!==void 0)for(ie=de;Pe.d[ie]===Se.d[ie]&&ie--;);return ve&&(Pe=Pe.times(2<<ve-1)),w=!0,m(Pe,ze.precision=et,ze.rounding=nt,!0)},_.isFinite=function(){return!!this.d},_.isInteger=_.isInt=function(){return!!this.d&&M(this.e/D)>this.d.length-2},_.isNaN=function(){return!this.s},_.isNegative=_.isNeg=function(){return this.s<0},_.isPositive=_.isPos=function(){return this.s>0},_.isZero=function(){return!!this.d&&this.d[0]===0},_.lessThan=_.lt=function(ie){return this.cmp(ie)<0},_.lessThanOrEqualTo=_.lte=function(ie){return this.cmp(ie)<1},_.logarithm=_.log=function(ie){var de,ve,_e,Ee,Se,Pe,Le,Ke,Fe=this,ze=Fe.constructor,et=ze.precision,nt=ze.rounding,ct=5;if(ie==null)ie=new ze(10),de=!0;else{if(ie=new ze(ie),ve=ie.d,ie.s<0||!ve||!ve[0]||ie.eq(1))return new ze(NaN);de=ie.eq(10)}if(ve=Fe.d,Fe.s<0||!ve||!ve[0]||Fe.eq(1))return new ze(ve&&!ve[0]?-1/0:Fe.s!=1?NaN:ve?0:1/0);if(de)if(ve.length>1)Se=!0;else{for(Ee=ve[0];Ee%10===0;)Ee/=10;Se=Ee!==1}if(w=!1,Le=et+ct,Pe=G(Fe,Le),_e=de?J(ze,Le+10):G(ie,Le),Ke=A(Pe,_e,Le,1),O(Ke.d,Ee=et,nt))do if(Le+=10,Pe=G(Fe,Le),_e=de?J(ze,Le+10):G(ie,Le),Ke=A(Pe,_e,Le,1),!Se){+$(Ke.d).slice(Ee+1,Ee+15)+1==1e14&&(Ke=m(Ke,et+1,0));break}while(O(Ke.d,Ee+=10,nt));return w=!0,m(Ke,et,nt)},_.minus=_.sub=function(ie){var de,ve,_e,Ee,Se,Pe,Le,Ke,Fe,ze,et,nt,ct=this,yt=ct.constructor;if(ie=new yt(ie),!ct.d||!ie.d)return!ct.s||!ie.s?ie=new yt(NaN):ct.d?ie.s=-ie.s:ie=new yt(ie.d||ct.s!==ie.s?ct:NaN),ie;if(ct.s!=ie.s)return ie.s=-ie.s,ct.plus(ie);if(Fe=ct.d,nt=ie.d,Le=yt.precision,Ke=yt.rounding,!Fe[0]||!nt[0]){if(nt[0])ie.s=-ie.s;else if(Fe[0])ie=new yt(ct);else return new yt(Ke===3?-0:0);return w?m(ie,Le,Ke):ie}if(ve=M(ie.e/D),ze=M(ct.e/D),Fe=Fe.slice(),Se=ze-ve,Se){for(et=Se<0,et?(de=Fe,Se=-Se,Pe=nt.length):(de=nt,ve=ze,Pe=Fe.length),_e=Math.max(Math.ceil(Le/D),Pe)+2,Se>_e&&(Se=_e,de.length=1),de.reverse(),_e=Se;_e--;)de.push(0);de.reverse()}else{for(_e=Fe.length,Pe=nt.length,et=_e<Pe,et&&(Pe=_e),_e=0;_e<Pe;_e++)if(Fe[_e]!=nt[_e]){et=Fe[_e]<nt[_e];break}Se=0}for(et&&(de=Fe,Fe=nt,nt=de,ie.s=-ie.s),Pe=Fe.length,_e=nt.length-Pe;_e>0;--_e)Fe[Pe++]=0;for(_e=nt.length;_e>Se;){if(Fe[--_e]<nt[_e]){for(Ee=_e;Ee&&Fe[--Ee]===0;)Fe[Ee]=T-1;--Fe[Ee],Fe[_e]+=T}Fe[_e]-=nt[_e]}for(;Fe[--Pe]===0;)Fe.pop();for(;Fe[0]===0;Fe.shift())--ve;return Fe[0]?(ie.d=Fe,ie.e=H(Fe,ve),w?m(ie,Le,Ke):ie):new yt(Ke===3?-0:0)},_.modulo=_.mod=function(ie){var de,ve=this,_e=ve.constructor;return ie=new _e(ie),!ve.d||!ie.s||ie.d&&!ie.d[0]?new _e(NaN):!ie.d||ve.d&&!ve.d[0]?m(new _e(ve),_e.precision,_e.rounding):(w=!1,_e.modulo==9?(de=A(ve,ie.abs(),0,3,1),de.s*=ie.s):de=A(ve,ie,0,_e.modulo,1),de=de.times(ie),w=!0,ve.minus(de))},_.naturalExponential=_.exp=function(){return Y(this)},_.naturalLogarithm=_.ln=function(){return G(this)},_.negated=_.neg=function(){var ie=new this.constructor(this);return ie.s=-ie.s,m(ie)},_.plus=_.add=function(ie){var de,ve,_e,Ee,Se,Pe,Le,Ke,Fe,ze,et=this,nt=et.constructor;if(ie=new nt(ie),!et.d||!ie.d)return!et.s||!ie.s?ie=new nt(NaN):et.d||(ie=new nt(ie.d||et.s===ie.s?et:NaN)),ie;if(et.s!=ie.s)return ie.s=-ie.s,et.minus(ie);if(Fe=et.d,ze=ie.d,Le=nt.precision,Ke=nt.rounding,!Fe[0]||!ze[0])return ze[0]||(ie=new nt(et)),w?m(ie,Le,Ke):ie;if(Se=M(et.e/D),_e=M(ie.e/D),Fe=Fe.slice(),Ee=Se-_e,Ee){for(Ee<0?(ve=Fe,Ee=-Ee,Pe=ze.length):(ve=ze,_e=Se,Pe=Fe.length),Se=Math.ceil(Le/D),Pe=Se>Pe?Se+1:Pe+1,Ee>Pe&&(Ee=Pe,ve.length=1),ve.reverse();Ee--;)ve.push(0);ve.reverse()}for(Pe=Fe.length,Ee=ze.length,Pe-Ee<0&&(Ee=Pe,ve=ze,ze=Fe,Fe=ve),de=0;Ee;)de=(Fe[--Ee]=Fe[Ee]+ze[Ee]+de)/T|0,Fe[Ee]%=T;for(de&&(Fe.unshift(de),++_e),Pe=Fe.length;Fe[--Pe]==0;)Fe.pop();return ie.d=Fe,ie.e=H(Fe,_e),w?m(ie,Le,Ke):ie},_.precision=_.sd=function(ie){var de,ve=this;if(ie!==void 0&&ie!==!!ie&&ie!==1&&ie!==0)throw Error(E+ie);return ve.d?(de=se(ve.d),ie&&ve.e+1>de&&(de=ve.e+1)):de=NaN,de},_.round=function(){var ie=this,de=ie.constructor;return m(new de(ie),ie.e+1,de.rounding)},_.sine=_.sin=function(){var ie,de,ve=this,_e=ve.constructor;return ve.isFinite()?ve.isZero()?new _e(ve):(ie=_e.precision,de=_e.rounding,_e.precision=ie+Math.max(ve.e,ve.sd())+D,_e.rounding=1,ve=me(_e,Ce(_e,ve)),_e.precision=ie,_e.rounding=de,m(v>2?ve.neg():ve,ie,de,!0)):new _e(NaN)},_.squareRoot=_.sqrt=function(){var ie,de,ve,_e,Ee,Se,Pe=this,Le=Pe.d,Ke=Pe.e,Fe=Pe.s,ze=Pe.constructor;if(Fe!==1||!Le||!Le[0])return new ze(!Fe||Fe<0&&(!Le||Le[0])?NaN:Le?Pe:1/0);for(w=!1,Fe=Math.sqrt(+Pe),Fe==0||Fe==1/0?(de=$(Le),(de.length+Ke)%2==0&&(de+="0"),Fe=Math.sqrt(de),Ke=M((Ke+1)/2)-(Ke<0||Ke%2),Fe==1/0?de="5e"+Ke:(de=Fe.toExponential(),de=de.slice(0,de.indexOf("e")+1)+Ke),_e=new ze(de)):_e=new ze(Fe.toString()),ve=(Ke=ze.precision)+3;;)if(Se=_e,_e=Se.plus(A(Pe,Se,ve+2,1)).times(.5),$(Se.d).slice(0,ve)===(de=$(_e.d)).slice(0,ve))if(de=de.slice(ve-3,ve+1),de=="9999"||!Ee&&de=="4999"){if(!Ee&&(m(Se,Ke+1,0),Se.times(Se).eq(Pe))){_e=Se;break}ve+=4,Ee=1}else{(!+de||!+de.slice(1)&&de.charAt(0)=="5")&&(m(_e,Ke+1,1),ie=!_e.times(_e).eq(Pe));break}return w=!0,m(_e,Ke,ze.rounding,ie)},_.tangent=_.tan=function(){var ie,de,ve=this,_e=ve.constructor;return ve.isFinite()?ve.isZero()?new _e(ve):(ie=_e.precision,de=_e.rounding,_e.precision=ie+10,_e.rounding=1,ve=ve.sin(),ve.s=1,ve=A(ve,new _e(1).minus(ve.times(ve)).sqrt(),ie+10,0),_e.precision=ie,_e.rounding=de,m(v==2||v==4?ve.neg():ve,ie,de,!0)):new _e(NaN)},_.times=_.mul=function(ie){var de,ve,_e,Ee,Se,Pe,Le,Ke,Fe,ze=this,et=ze.constructor,nt=ze.d,ct=(ie=new et(ie)).d;if(ie.s*=ze.s,!nt||!nt[0]||!ct||!ct[0])return new et(!ie.s||nt&&!nt[0]&&!ct||ct&&!ct[0]&&!nt?NaN:!nt||!ct?ie.s/0:ie.s*0);for(ve=M(ze.e/D)+M(ie.e/D),Ke=nt.length,Fe=ct.length,Ke<Fe&&(Se=nt,nt=ct,ct=Se,Pe=Ke,Ke=Fe,Fe=Pe),Se=[],Pe=Ke+Fe,_e=Pe;_e--;)Se.push(0);for(_e=Fe;--_e>=0;){for(de=0,Ee=Ke+_e;Ee>_e;)Le=Se[Ee]+ct[_e]*nt[Ee-_e-1]+de,Se[Ee--]=Le%T|0,de=Le/T|0;Se[Ee]=(Se[Ee]+de)%T|0}for(;!Se[--Pe];)Se.pop();return de?++ve:Se.shift(),ie.d=Se,ie.e=H(Se,ve),w?m(ie,et.precision,et.rounding):ie},_.toBinary=function(ie,de){return $e(this,2,ie,de)},_.toDecimalPlaces=_.toDP=function(ie,de){var ve=this,_e=ve.constructor;return ve=new _e(ve),ie===void 0?ve:(S(ie,0,s),de===void 0?de=_e.rounding:S(de,0,8),m(ve,ie+ve.e+1,de))},_.toExponential=function(ie,de){var ve,_e=this,Ee=_e.constructor;return ie===void 0?ve=P(_e,!0):(S(ie,0,s),de===void 0?de=Ee.rounding:S(de,0,8),_e=m(new Ee(_e),ie+1,de),ve=P(_e,!0,ie+1)),_e.isNeg()&&!_e.isZero()?"-"+ve:ve},_.toFixed=function(ie,de){var ve,_e,Ee=this,Se=Ee.constructor;return ie===void 0?ve=P(Ee):(S(ie,0,s),de===void 0?de=Se.rounding:S(de,0,8),_e=m(new Se(Ee),ie+Ee.e+1,de),ve=P(_e,!1,ie+_e.e+1)),Ee.isNeg()&&!Ee.isZero()?"-"+ve:ve},_.toFraction=function(ie){var de,ve,_e,Ee,Se,Pe,Le,Ke,Fe,ze,et,nt,ct=this,yt=ct.d,dt=ct.constructor;if(!yt)return new dt(ct);if(Fe=ve=new dt(1),_e=Ke=new dt(0),de=new dt(_e),Se=de.e=se(yt)-ct.e-1,Pe=Se%D,de.d[0]=q(10,Pe<0?D+Pe:Pe),ie==null)ie=Se>0?de:Fe;else{if(Le=new dt(ie),!Le.isInt()||Le.lt(Fe))throw Error(E+Le);ie=Le.gt(de)?Se>0?de:Fe:Le}for(w=!1,Le=new dt($(yt)),ze=dt.precision,dt.precision=Se=yt.length*D*2;et=A(Le,de,0,1,1),Ee=ve.plus(et.times(_e)),Ee.cmp(ie)!=1;)ve=_e,_e=Ee,Ee=Fe,Fe=Ke.plus(et.times(Ee)),Ke=Ee,Ee=de,de=Le.minus(et.times(Ee)),Le=Ee;return Ee=A(ie.minus(ve),_e,0,1,1),Ke=Ke.plus(Ee.times(Fe)),ve=ve.plus(Ee.times(_e)),Ke.s=Fe.s=ct.s,nt=A(Fe,_e,Se,1).minus(ct).abs().cmp(A(Ke,ve,Se,1).minus(ct).abs())<1?[Fe,_e]:[Ke,ve],dt.precision=ze,w=!0,nt},_.toHexadecimal=_.toHex=function(ie,de){return $e(this,16,ie,de)},_.toNearest=function(ie,de){var ve=this,_e=ve.constructor;if(ve=new _e(ve),ie==null){if(!ve.d)return ve;ie=new _e(1),de=_e.rounding}else{if(ie=new _e(ie),de===void 0?de=_e.rounding:S(de,0,8),!ve.d)return ie.s?ve:ie;if(!ie.d)return ie.s&&(ie.s=ve.s),ie}return ie.d[0]?(w=!1,ve=A(ve,ie,0,de,1).times(ie),w=!0,m(ve)):(ie.s=ve.s,ve=ie),ve},_.toNumber=function(){return+this},_.toOctal=function(ie,de){return $e(this,8,ie,de)},_.toPower=_.pow=function(ie){var de,ve,_e,Ee,Se,Pe,Le=this,Ke=Le.constructor,Fe=+(ie=new Ke(ie));if(!Le.d||!ie.d||!Le.d[0]||!ie.d[0])return new Ke(q(+Le,Fe));if(Le=new Ke(Le),Le.eq(1))return Le;if(_e=Ke.precision,Se=Ke.rounding,ie.eq(1))return m(Le,_e,Se);if(de=M(ie.e/D),de>=ie.d.length-1&&(ve=Fe<0?-Fe:Fe)<=L)return Ee=Z(Ke,Le,ve,_e),ie.s<0?new Ke(1).div(Ee):m(Ee,_e,Se);if(Pe=Le.s,Pe<0){if(de<ie.d.length-1)return new Ke(NaN);if(ie.d[de]&1||(Pe=1),Le.e==0&&Le.d[0]==1&&Le.d.length==1)return Le.s=Pe,Le}return ve=q(+Le,Fe),de=ve==0||!isFinite(ve)?M(Fe*(Math.log("0."+$(Le.d))/Math.LN10+Le.e+1)):new Ke(ve+"").e,de>Ke.maxE+1||de<Ke.minE-1?new Ke(de>0?Pe/0:0):(w=!1,Ke.rounding=Le.s=1,ve=Math.min(12,(de+"").length),Ee=Y(ie.times(G(Le,_e+ve)),_e),Ee.d&&(Ee=m(Ee,_e+5,1),O(Ee.d,_e,Se)&&(de=_e+10,Ee=m(Y(ie.times(G(Le,de+ve)),de),de+5,1),+$(Ee.d).slice(_e+1,_e+15)+1==1e14&&(Ee=m(Ee,_e+1,0)))),Ee.s=Pe,w=!0,Ke.rounding=Se,m(Ee,_e,Se))},_.toPrecision=function(ie,de){var ve,_e=this,Ee=_e.constructor;return ie===void 0?ve=P(_e,_e.e<=Ee.toExpNeg||_e.e>=Ee.toExpPos):(S(ie,1,s),de===void 0?de=Ee.rounding:S(de,0,8),_e=m(new Ee(_e),ie,de),ve=P(_e,ie<=_e.e||_e.e<=Ee.toExpNeg,ie)),_e.isNeg()&&!_e.isZero()?"-"+ve:ve},_.toSignificantDigits=_.toSD=function(ie,de){var ve=this,_e=ve.constructor;return ie===void 0?(ie=_e.precision,de=_e.rounding):(S(ie,1,s),de===void 0?de=_e.rounding:S(de,0,8)),m(new _e(ve),ie,de)},_.toString=function(){var ie=this,de=ie.constructor,ve=P(ie,ie.e<=de.toExpNeg||ie.e>=de.toExpPos);return ie.isNeg()&&!ie.isZero()?"-"+ve:ve},_.truncated=_.trunc=function(){return m(new this.constructor(this),this.e+1,1)},_.valueOf=_.toJSON=function(){var ie=this,de=ie.constructor,ve=P(ie,ie.e<=de.toExpNeg||ie.e>=de.toExpPos);return ie.isNeg()?"-"+ve:ve};function $(ie){var de,ve,_e,Ee=ie.length-1,Se="",Pe=ie[0];if(Ee>0){for(Se+=Pe,de=1;de<Ee;de++)_e=ie[de]+"",ve=D-_e.length,ve&&(Se+=ne(ve)),Se+=_e;Pe=ie[de],_e=Pe+"",ve=D-_e.length,ve&&(Se+=ne(ve))}else if(Pe===0)return"0";for(;Pe%10===0;)Pe/=10;return Se+Pe}function S(ie,de,ve){if(ie!==~~ie||ie<de||ie>ve)throw Error(E+ie)}function O(ie,de,ve,_e){var Ee,Se,Pe,Le;for(Se=ie[0];Se>=10;Se/=10)--de;return--de<0?(de+=D,Ee=0):(Ee=Math.ceil((de+1)/D),de%=D),Se=q(10,D-de),Le=ie[Ee]%Se|0,_e==null?de<3?(de==0?Le=Le/100|0:de==1&&(Le=Le/10|0),Pe=ve<4&&Le==99999||ve>3&&Le==49999||Le==5e4||Le==0):Pe=(ve<4&&Le+1==Se||ve>3&&Le+1==Se/2)&&(ie[Ee+1]/Se/100|0)==q(10,de-2)-1||(Le==Se/2||Le==0)&&(ie[Ee+1]/Se/100|0)==0:de<4?(de==0?Le=Le/1e3|0:de==1?Le=Le/100|0:de==2&&(Le=Le/10|0),Pe=(_e||ve<4)&&Le==9999||!_e&&ve>3&&Le==4999):Pe=((_e||ve<4)&&Le+1==Se||!_e&&ve>3&&Le+1==Se/2)&&(ie[Ee+1]/Se/1e3|0)==q(10,de-3)-1,Pe}function N(ie,de,ve){for(var _e,Ee=[0],Se,Pe=0,Le=ie.length;Pe<Le;){for(Se=Ee.length;Se--;)Ee[Se]*=de;for(Ee[0]+=o.indexOf(ie.charAt(Pe++)),_e=0;_e<Ee.length;_e++)Ee[_e]>ve-1&&(Ee[_e+1]===void 0&&(Ee[_e+1]=0),Ee[_e+1]+=Ee[_e]/ve|0,Ee[_e]%=ve)}return Ee.reverse()}function k(ie,de){var ve,_e,Ee;if(de.isZero())return de;_e=de.d.length,_e<32?(ve=Math.ceil(_e/3),Ee=(1/Be(4,ve)).toString()):(ve=16,Ee="2.3283064365386962890625e-10"),ie.precision+=ve,de=Re(ie,1,de.times(Ee),new ie(1));for(var Se=ve;Se--;){var Pe=de.times(de);de=Pe.times(Pe).minus(Pe).times(8).plus(1)}return ie.precision-=ve,de}var A=function(){function ie(_e,Ee,Se){var Pe,Le=0,Ke=_e.length;for(_e=_e.slice();Ke--;)Pe=_e[Ke]*Ee+Le,_e[Ke]=Pe%Se|0,Le=Pe/Se|0;return Le&&_e.unshift(Le),_e}function de(_e,Ee,Se,Pe){var Le,Ke;if(Se!=Pe)Ke=Se>Pe?1:-1;else for(Le=Ke=0;Le<Se;Le++)if(_e[Le]!=Ee[Le]){Ke=_e[Le]>Ee[Le]?1:-1;break}return Ke}function ve(_e,Ee,Se,Pe){for(var Le=0;Se--;)_e[Se]-=Le,Le=_e[Se]<Ee[Se]?1:0,_e[Se]=Le*Pe+_e[Se]-Ee[Se];for(;!_e[0]&&_e.length>1;)_e.shift()}return function(_e,Ee,Se,Pe,Le,Ke){var Fe,ze,et,nt,ct,yt,dt,vt,gt,bt,wt,It,Ct,Et,Ot,xt,St,Mt,Rt,Bt,Dt=_e.constructor,At=_e.s==Ee.s?1:-1,Tt=_e.d,$t=Ee.d;if(!Tt||!Tt[0]||!$t||!$t[0])return new Dt(!_e.s||!Ee.s||(Tt?$t&&Tt[0]==$t[0]:!$t)?NaN:Tt&&Tt[0]==0||!$t?At*0:At/0);for(Ke?(ct=1,ze=_e.e-Ee.e):(Ke=T,ct=D,ze=M(_e.e/ct)-M(Ee.e/ct)),Rt=$t.length,St=Tt.length,gt=new Dt(At),bt=gt.d=[],et=0;$t[et]==(Tt[et]||0);et++);if($t[et]>(Tt[et]||0)&&ze--,Se==null?(Et=Se=Dt.precision,Pe=Dt.rounding):Le?Et=Se+(_e.e-Ee.e)+1:Et=Se,Et<0)bt.push(1),yt=!0;else{if(Et=Et/ct+2|0,et=0,Rt==1){for(nt=0,$t=$t[0],Et++;(et<St||nt)&&Et--;et++)Ot=nt*Ke+(Tt[et]||0),bt[et]=Ot/$t|0,nt=Ot%$t|0;yt=nt||et<St}else{for(nt=Ke/($t[0]+1)|0,nt>1&&($t=ie($t,nt,Ke),Tt=ie(Tt,nt,Ke),Rt=$t.length,St=Tt.length),xt=Rt,wt=Tt.slice(0,Rt),It=wt.length;It<Rt;)wt[It++]=0;Bt=$t.slice(),Bt.unshift(0),Mt=$t[0],$t[1]>=Ke/2&&++Mt;do nt=0,Fe=de($t,wt,Rt,It),Fe<0?(Ct=wt[0],Rt!=It&&(Ct=Ct*Ke+(wt[1]||0)),nt=Ct/Mt|0,nt>1?(nt>=Ke&&(nt=Ke-1),dt=ie($t,nt,Ke),vt=dt.length,It=wt.length,Fe=de(dt,wt,vt,It),Fe==1&&(nt--,ve(dt,Rt<vt?Bt:$t,vt,Ke))):(nt==0&&(Fe=nt=1),dt=$t.slice()),vt=dt.length,vt<It&&dt.unshift(0),ve(wt,dt,It,Ke),Fe==-1&&(It=wt.length,Fe=de($t,wt,Rt,It),Fe<1&&(nt++,ve(wt,Rt<It?Bt:$t,It,Ke))),It=wt.length):Fe===0&&(nt++,wt=[0]),bt[et++]=nt,Fe&&wt[0]?wt[It++]=Tt[xt]||0:(wt=[Tt[xt]],It=1);while((xt++<St||wt[0]!==void 0)&&Et--);yt=wt[0]!==void 0}bt[0]||bt.shift()}if(ct==1)gt.e=ze,u=yt;else{for(et=1,nt=bt[0];nt>=10;nt/=10)et++;gt.e=et+ze*ct-1,m(gt,Le?Se+gt.e+1:Se,Pe,yt)}return gt}}();function m(ie,de,ve,_e){var Ee,Se,Pe,Le,Ke,Fe,ze,et,nt,ct=ie.constructor;e:if(de!=null){if(et=ie.d,!et)return ie;for(Ee=1,Le=et[0];Le>=10;Le/=10)Ee++;if(Se=de-Ee,Se<0)Se+=D,Pe=de,ze=et[nt=0],Ke=ze/q(10,Ee-Pe-1)%10|0;else if(nt=Math.ceil((Se+1)/D),Le=et.length,nt>=Le)if(_e){for(;Le++<=nt;)et.push(0);ze=Ke=0,Ee=1,Se%=D,Pe=Se-D+1}else break e;else{for(ze=Le=et[nt],Ee=1;Le>=10;Le/=10)Ee++;Se%=D,Pe=Se-D+Ee,Ke=Pe<0?0:ze/q(10,Ee-Pe-1)%10|0}if(_e=_e||de<0||et[nt+1]!==void 0||(Pe<0?ze:ze%q(10,Ee-Pe-1)),Fe=ve<4?(Ke||_e)&&(ve==0||ve==(ie.s<0?3:2)):Ke>5||Ke==5&&(ve==4||_e||ve==6&&(Se>0?Pe>0?ze/q(10,Ee-Pe):0:et[nt-1])%10&1||ve==(ie.s<0?8:7)),de<1||!et[0])return et.length=0,Fe?(de-=ie.e+1,et[0]=q(10,(D-de%D)%D),ie.e=-de||0):et[0]=ie.e=0,ie;if(Se==0?(et.length=nt,Le=1,nt--):(et.length=nt+1,Le=q(10,D-Se),et[nt]=Pe>0?(ze/q(10,Ee-Pe)%q(10,Pe)|0)*Le:0),Fe)for(;;)if(nt==0){for(Se=1,Pe=et[0];Pe>=10;Pe/=10)Se++;for(Pe=et[0]+=Le,Le=1;Pe>=10;Pe/=10)Le++;Se!=Le&&(ie.e++,et[0]==T&&(et[0]=1));break}else{if(et[nt]+=Le,et[nt]!=T)break;et[nt--]=0,Le=1}for(Se=et.length;et[--Se]===0;)et.pop()}return w&&(ie.e>ct.maxE?(ie.d=null,ie.e=NaN):ie.e<ct.minE&&(ie.e=0,ie.d=[0])),ie}function P(ie,de,ve){if(!ie.isFinite())return V(ie);var _e,Ee=ie.e,Se=$(ie.d),Pe=Se.length;return de?(ve&&(_e=ve-Pe)>0?Se=Se.charAt(0)+"."+Se.slice(1)+ne(_e):Pe>1&&(Se=Se.charAt(0)+"."+Se.slice(1)),Se=Se+(ie.e<0?"e":"e+")+ie.e):Ee<0?(Se="0."+ne(-Ee-1)+Se,ve&&(_e=ve-Pe)>0&&(Se+=ne(_e))):Ee>=Pe?(Se+=ne(Ee+1-Pe),ve&&(_e=ve-Ee-1)>0&&(Se=Se+"."+ne(_e))):((_e=Ee+1)<Pe&&(Se=Se.slice(0,_e)+"."+Se.slice(_e)),ve&&(_e=ve-Pe)>0&&(Ee+1===Pe&&(Se+="."),Se+=ne(_e))),Se}function H(ie,de){var ve=ie[0];for(de*=D;ve>=10;ve/=10)de++;return de}function J(ie,de,ve){if(de>C)throw w=!0,ve&&(ie.precision=ve),Error(I);return m(new ie(n),de,1,!0)}function X(ie,de,ve){if(de>d)throw Error(I);return m(new ie(a),de,ve,!0)}function se(ie){var de=ie.length-1,ve=de*D+1;if(de=ie[de],de){for(;de%10==0;de/=10)ve--;for(de=ie[0];de>=10;de/=10)ve++}return ve}function ne(ie){for(var de="";ie--;)de+="0";return de}function Z(ie,de,ve,_e){var Ee,Se=new ie(1),Pe=Math.ceil(_e/D+4);for(w=!1;;){if(ve%2&&(Se=Se.times(de),Ue(Se.d,Pe)&&(Ee=!0)),ve=M(ve/2),ve===0){ve=Se.d.length-1,Ee&&Se.d[ve]===0&&++Se.d[ve];break}de=de.times(de),Ue(de.d,Pe)}return w=!0,Se}function oe(ie){return ie.d[ie.d.length-1]&1}function ye(ie,de,ve){for(var _e,Ee=new ie(de[0]),Se=0;++Se<de.length;)if(_e=new ie(de[Se]),_e.s)Ee[ve](_e)&&(Ee=_e);else{Ee=_e;break}return Ee}function Y(ie,de){var ve,_e,Ee,Se,Pe,Le,Ke,Fe=0,ze=0,et=0,nt=ie.constructor,ct=nt.rounding,yt=nt.precision;if(!ie.d||!ie.d[0]||ie.e>17)return new nt(ie.d?ie.d[0]?ie.s<0?0:1/0:1:ie.s?ie.s<0?0:ie:NaN);for(de==null?(w=!1,Ke=yt):Ke=de,Le=new nt(.03125);ie.e>-2;)ie=ie.times(Le),et+=5;for(_e=Math.log(q(2,et))/Math.LN10*2+5|0,Ke+=_e,ve=Se=Pe=new nt(1),nt.precision=Ke;;){if(Se=m(Se.times(ie),Ke,1),ve=ve.times(++ze),Le=Pe.plus(A(Se,ve,Ke,1)),$(Le.d).slice(0,Ke)===$(Pe.d).slice(0,Ke)){for(Ee=et;Ee--;)Pe=m(Pe.times(Pe),Ke,1);if(de==null)if(Fe<3&&O(Pe.d,Ke-_e,ct,Fe))nt.precision=Ke+=10,ve=Se=Le=new nt(1),ze=0,Fe++;else return m(Pe,nt.precision=yt,ct,w=!0);else return nt.precision=yt,Pe}Pe=Le}}function G(ie,de){var ve,_e,Ee,Se,Pe,Le,Ke,Fe,ze,et,nt,ct=1,yt=10,dt=ie,vt=dt.d,gt=dt.constructor,bt=gt.rounding,wt=gt.precision;if(dt.s<0||!vt||!vt[0]||!dt.e&&vt[0]==1&&vt.length==1)return new gt(vt&&!vt[0]?-1/0:dt.s!=1?NaN:vt?0:dt);if(de==null?(w=!1,ze=wt):ze=de,gt.precision=ze+=yt,ve=$(vt),_e=ve.charAt(0),Math.abs(Se=dt.e)<15e14){for(;_e<7&&_e!=1||_e==1&&ve.charAt(1)>3;)dt=dt.times(ie),ve=$(dt.d),_e=ve.charAt(0),ct++;Se=dt.e,_e>1?(dt=new gt("0."+ve),Se++):dt=new gt(_e+"."+ve.slice(1))}else return Fe=J(gt,ze+2,wt).times(Se+""),dt=G(new gt(_e+"."+ve.slice(1)),ze-yt).plus(Fe),gt.precision=wt,de==null?m(dt,wt,bt,w=!0):dt;for(et=dt,Ke=Pe=dt=A(dt.minus(1),dt.plus(1),ze,1),nt=m(dt.times(dt),ze,1),Ee=3;;){if(Pe=m(Pe.times(nt),ze,1),Fe=Ke.plus(A(Pe,new gt(Ee),ze,1)),$(Fe.d).slice(0,ze)===$(Ke.d).slice(0,ze))if(Ke=Ke.times(2),Se!==0&&(Ke=Ke.plus(J(gt,ze+2,wt).times(Se+""))),Ke=A(Ke,new gt(ct),ze,1),de==null)if(O(Ke.d,ze-yt,bt,Le))gt.precision=ze+=yt,Fe=Pe=dt=A(et.minus(1),et.plus(1),ze,1),nt=m(dt.times(dt),ze,1),Ee=Le=1;else return m(Ke,gt.precision=wt,bt,w=!0);else return gt.precision=wt,Ke;Ke=Fe,Ee+=2}}function V(ie){return String(ie.s*ie.s/0)}function te(ie,de){var ve,_e,Ee;for((ve=de.indexOf("."))>-1&&(de=de.replace(".","")),(_e=de.search(/e/i))>0?(ve<0&&(ve=_e),ve+=+de.slice(_e+1),de=de.substring(0,_e)):ve<0&&(ve=de.length),_e=0;de.charCodeAt(_e)===48;_e++);for(Ee=de.length;de.charCodeAt(Ee-1)===48;--Ee);if(de=de.slice(_e,Ee),de){if(Ee-=_e,ie.e=ve=ve-_e-1,ie.d=[],_e=(ve+1)%D,ve<0&&(_e+=D),_e<Ee){for(_e&&ie.d.push(+de.slice(0,_e)),Ee-=D;_e<Ee;)ie.d.push(+de.slice(_e,_e+=D));de=de.slice(_e),_e=D-de.length}else _e-=Ee;for(;_e--;)de+="0";ie.d.push(+de),w&&(ie.e>ie.constructor.maxE?(ie.d=null,ie.e=NaN):ie.e<ie.constructor.minE&&(ie.e=0,ie.d=[0]))}else ie.e=0,ie.d=[0];return ie}function le(ie,de){var ve,_e,Ee,Se,Pe,Le,Ke,Fe,ze;if(de.indexOf("_")>-1){if(de=de.replace(/(\d)_(?=\d)/g,"$1"),y.test(de))return te(ie,de)}else if(de==="Infinity"||de==="NaN")return+de||(ie.s=NaN),ie.e=NaN,ie.d=null,ie;if(F.test(de))ve=16,de=de.toLowerCase();else if(U.test(de))ve=2;else if(j.test(de))ve=8;else throw Error(E+de);for(Se=de.search(/p/i),Se>0?(Ke=+de.slice(Se+1),de=de.substring(2,Se)):de=de.slice(2),Se=de.indexOf("."),Pe=Se>=0,_e=ie.constructor,Pe&&(de=de.replace(".",""),Le=de.length,Se=Le-Se,Ee=Z(_e,new _e(ve),Se,Se*2)),Fe=N(de,ve,T),ze=Fe.length-1,Se=ze;Fe[Se]===0;--Se)Fe.pop();return Se<0?new _e(ie.s*0):(ie.e=H(Fe,ze),ie.d=Fe,w=!1,Pe&&(ie=A(ie,Ee,Le*4)),Ke&&(ie=ie.times(Math.abs(Ke)<54?q(2,Ke):p.pow(2,Ke))),w=!0,ie)}function me(ie,de){var ve,_e=de.d.length;if(_e<3)return de.isZero()?de:Re(ie,2,de,de);ve=1.4*Math.sqrt(_e),ve=ve>16?16:ve|0,de=de.times(1/Be(5,ve)),de=Re(ie,2,de,de);for(var Ee,Se=new ie(5),Pe=new ie(16),Le=new ie(20);ve--;)Ee=de.times(de),de=de.times(Se.plus(Ee.times(Pe.times(Ee).minus(Le))));return de}function Re(ie,de,ve,_e,Ee){var Se,Pe,Le,Ke,Fe=ie.precision,ze=Math.ceil(Fe/D);for(w=!1,Ke=ve.times(ve),Le=new ie(_e);;){if(Pe=A(Le.times(Ke),new ie(de++*de++),Fe,1),Le=Ee?_e.plus(Pe):_e.minus(Pe),_e=A(Pe.times(Ke),new ie(de++*de++),Fe,1),Pe=Le.plus(_e),Pe.d[ze]!==void 0){for(Se=ze;Pe.d[Se]===Le.d[Se]&&Se--;);if(Se==-1)break}Se=Le,Le=_e,_e=Pe,Pe=Se}return w=!0,Pe.d.length=ze+1,Pe}function Be(ie,de){for(var ve=ie;--de;)ve*=ie;return ve}function Ce(ie,de){var ve,_e=de.s<0,Ee=X(ie,ie.precision,1),Se=Ee.times(.5);if(de=de.abs(),de.lte(Se))return v=_e?4:1,de;if(ve=de.divToInt(Ee),ve.isZero())v=_e?3:2;else{if(de=de.minus(ve.times(Ee)),de.lte(Se))return v=oe(ve)?_e?2:3:_e?4:1,de;v=oe(ve)?_e?1:4:_e?3:2}return de.minus(Ee).abs()}function $e(ie,de,ve,_e){var Ee,Se,Pe,Le,Ke,Fe,ze,et,nt,ct=ie.constructor,yt=ve!==void 0;if(yt?(S(ve,1,s),_e===void 0?_e=ct.rounding:S(_e,0,8)):(ve=ct.precision,_e=ct.rounding),!ie.isFinite())ze=V(ie);else{for(ze=P(ie),Pe=ze.indexOf("."),yt?(Ee=2,de==16?ve=ve*4-3:de==8&&(ve=ve*3-2)):Ee=de,Pe>=0&&(ze=ze.replace(".",""),nt=new ct(1),nt.e=ze.length-Pe,nt.d=N(P(nt),10,Ee),nt.e=nt.d.length),et=N(ze,10,Ee),Se=Ke=et.length;et[--Ke]==0;)et.pop();if(!et[0])ze=yt?"0p+0":"0";else{if(Pe<0?Se--:(ie=new ct(ie),ie.d=et,ie.e=Se,ie=A(ie,nt,ve,_e,0,Ee),et=ie.d,Se=ie.e,Fe=u),Pe=et[ve],Le=Ee/2,Fe=Fe||et[ve+1]!==void 0,Fe=_e<4?(Pe!==void 0||Fe)&&(_e===0||_e===(ie.s<0?3:2)):Pe>Le||Pe===Le&&(_e===4||Fe||_e===6&&et[ve-1]&1||_e===(ie.s<0?8:7)),et.length=ve,Fe)for(;++et[--ve]>Ee-1;)et[ve]=0,ve||(++Se,et.unshift(1));for(Ke=et.length;!et[Ke-1];--Ke);for(Pe=0,ze="";Pe<Ke;Pe++)ze+=o.charAt(et[Pe]);if(yt){if(Ke>1)if(de==16||de==8){for(Pe=de==16?4:3,--Ke;Ke%Pe;Ke++)ze+="0";for(et=N(ze,Ee,de),Ke=et.length;!et[Ke-1];--Ke);for(Pe=1,ze="1.";Pe<Ke;Pe++)ze+=o.charAt(et[Pe])}else ze=ze.charAt(0)+"."+ze.slice(1);ze=ze+(Se<0?"p":"p+")+Se}else if(Se<0){for(;++Se;)ze="0"+ze;ze="0."+ze}else if(++Se>Ke)for(Se-=Ke;Se--;)ze+="0";else Se<Ke&&(ze=ze.slice(0,Se)+"."+ze.slice(Se))}ze=(de==16?"0x":de==2?"0b":de==8?"0o":"")+ze}return ie.s<0?"-"+ze:ze}function Ue(ie,de){if(ie.length>de)return ie.length=de,!0}function Me(ie){return new this(ie).abs()}function ke(ie){return new this(ie).acos()}function tt(ie){return new this(ie).acosh()}function Ie(ie,de){return new this(ie).plus(de)}function xe(ie){return new this(ie).asin()}function he(ie){return new this(ie).asinh()}function ae(ie){return new this(ie).atan()}function be(ie){return new this(ie).atanh()}function Ae(ie,de){ie=new this(ie),de=new this(de);var ve,_e=this.precision,Ee=this.rounding,Se=_e+4;return!ie.s||!de.s?ve=new this(NaN):!ie.d&&!de.d?(ve=X(this,Se,1).times(de.s>0?.25:.75),ve.s=ie.s):!de.d||ie.isZero()?(ve=de.s<0?X(this,_e,Ee):new this(0),ve.s=ie.s):!ie.d||de.isZero()?(ve=X(this,Se,1).times(.5),ve.s=ie.s):de.s<0?(this.precision=Se,this.rounding=1,ve=this.atan(A(ie,de,Se,1)),de=X(this,Se,1),this.precision=_e,this.rounding=Ee,ve=ie.s<0?ve.minus(de):ve.plus(de)):ve=this.atan(A(ie,de,Se,1)),ve}function re(ie){return new this(ie).cbrt()}function z(ie){return m(ie=new this(ie),ie.e+1,2)}function Q(ie,de,ve){return new this(ie).clamp(de,ve)}function ue(ie){if(!ie||typeof ie!="object")throw Error(b+"Object expected");var de,ve,_e,Ee=ie.defaults===!0,Se=["precision",1,s,"rounding",0,8,"toExpNeg",-r,0,"toExpPos",0,r,"maxE",0,r,"minE",-r,0,"modulo",0,9];for(de=0;de<Se.length;de+=3)if(ve=Se[de],Ee&&(this[ve]=l[ve]),(_e=ie[ve])!==void 0)if(M(_e)===_e&&_e>=Se[de+1]&&_e<=Se[de+2])this[ve]=_e;else throw Error(E+ve+": "+_e);if(ve="crypto",Ee&&(this[ve]=l[ve]),(_e=ie[ve])!==void 0)if(_e===!0||_e===!1||_e===0||_e===1)if(_e)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[ve]=!0;else throw Error(x);else this[ve]=!1;else throw Error(E+ve+": "+_e);return this}function we(ie){return new this(ie).cos()}function Ne(ie){return new this(ie).cosh()}function De(ie){var de,ve,_e;function Ee(Se){var Pe,Le,Ke,Fe=this;if(!(Fe instanceof Ee))return new Ee(Se);if(Fe.constructor=Ee,ht(Se)){Fe.s=Se.s,w?!Se.d||Se.e>Ee.maxE?(Fe.e=NaN,Fe.d=null):Se.e<Ee.minE?(Fe.e=0,Fe.d=[0]):(Fe.e=Se.e,Fe.d=Se.d.slice()):(Fe.e=Se.e,Fe.d=Se.d?Se.d.slice():Se.d);return}if(Ke=typeof Se,Ke==="number"){if(Se===0){Fe.s=1/Se<0?-1:1,Fe.e=0,Fe.d=[0];return}if(Se<0?(Se=-Se,Fe.s=-1):Fe.s=1,Se===~~Se&&Se<1e7){for(Pe=0,Le=Se;Le>=10;Le/=10)Pe++;w?Pe>Ee.maxE?(Fe.e=NaN,Fe.d=null):Pe<Ee.minE?(Fe.e=0,Fe.d=[0]):(Fe.e=Pe,Fe.d=[Se]):(Fe.e=Pe,Fe.d=[Se]);return}else if(Se*0!==0){Se||(Fe.s=NaN),Fe.e=NaN,Fe.d=null;return}return te(Fe,Se.toString())}else if(Ke!=="string")throw Error(E+Se);return(Le=Se.charCodeAt(0))===45?(Se=Se.slice(1),Fe.s=-1):(Le===43&&(Se=Se.slice(1)),Fe.s=1),y.test(Se)?te(Fe,Se):le(Fe,Se)}if(Ee.prototype=_,Ee.ROUND_UP=0,Ee.ROUND_DOWN=1,Ee.ROUND_CEIL=2,Ee.ROUND_FLOOR=3,Ee.ROUND_HALF_UP=4,Ee.ROUND_HALF_DOWN=5,Ee.ROUND_HALF_EVEN=6,Ee.ROUND_HALF_CEIL=7,Ee.ROUND_HALF_FLOOR=8,Ee.EUCLID=9,Ee.config=Ee.set=ue,Ee.clone=De,Ee.isDecimal=ht,Ee.abs=Me,Ee.acos=ke,Ee.acosh=tt,Ee.add=Ie,Ee.asin=xe,Ee.asinh=he,Ee.atan=ae,Ee.atanh=be,Ee.atan2=Ae,Ee.cbrt=re,Ee.ceil=z,Ee.clamp=Q,Ee.cos=we,Ee.cosh=Ne,Ee.div=je,Ee.exp=ot,Ee.floor=He,Ee.hypot=We,Ee.ln=Je,Ee.log=rt,Ee.log10=Ze,Ee.log2=mt,Ee.max=it,Ee.min=_t,Ee.mod=pe,Ee.mul=ee,Ee.pow=ce,Ee.random=Te,Ee.round=Oe,Ee.sign=Ve,Ee.sin=qe,Ee.sinh=Ye,Ee.sqrt=pt,Ee.sub=Ge,Ee.sum=Xe,Ee.tan=lt,Ee.tanh=Qe,Ee.trunc=st,ie===void 0&&(ie={}),ie&&ie.defaults!==!0)for(_e=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],de=0;de<_e.length;)ie.hasOwnProperty(ve=_e[de++])||(ie[ve]=this[ve]);return Ee.config(ie),Ee}function je(ie,de){return new this(ie).div(de)}function ot(ie){return new this(ie).exp()}function He(ie){return m(ie=new this(ie),ie.e+1,3)}function We(){var ie,de,ve=new this(0);for(w=!1,ie=0;ie<arguments.length;)if(de=new this(arguments[ie++]),de.d)ve.d&&(ve=ve.plus(de.times(de)));else{if(de.s)return w=!0,new this(1/0);ve=de}return w=!0,ve.sqrt()}function ht(ie){return ie instanceof p||ie&&ie.toStringTag===B||!1}function Je(ie){return new this(ie).ln()}function rt(ie,de){return new this(ie).log(de)}function mt(ie){return new this(ie).log(2)}function Ze(ie){return new this(ie).log(10)}function it(){return ye(this,arguments,"lt")}function _t(){return ye(this,arguments,"gt")}function pe(ie,de){return new this(ie).mod(de)}function ee(ie,de){return new this(ie).mul(de)}function ce(ie,de){return new this(ie).pow(de)}function Te(ie){var de,ve,_e,Ee,Se=0,Pe=new this(1),Le=[];if(ie===void 0?ie=this.precision:S(ie,1,s),_e=Math.ceil(ie/D),this.crypto)if(crypto.getRandomValues)for(de=crypto.getRandomValues(new Uint32Array(_e));Se<_e;)Ee=de[Se],Ee>=429e7?de[Se]=crypto.getRandomValues(new Uint32Array(1))[0]:Le[Se++]=Ee%1e7;else if(crypto.randomBytes){for(de=crypto.randomBytes(_e*=4);Se<_e;)Ee=de[Se]+(de[Se+1]<<8)+(de[Se+2]<<16)+((de[Se+3]&127)<<24),Ee>=214e7?crypto.randomBytes(4).copy(de,Se):(Le.push(Ee%1e7),Se+=4);Se=_e/4}else throw Error(x);else for(;Se<_e;)Le[Se++]=Math.random()*1e7|0;for(_e=Le[--Se],ie%=D,_e&&ie&&(Ee=q(10,D-ie),Le[Se]=(_e/Ee|0)*Ee);Le[Se]===0;Se--)Le.pop();if(Se<0)ve=0,Le=[0];else{for(ve=-1;Le[0]===0;ve-=D)Le.shift();for(_e=1,Ee=Le[0];Ee>=10;Ee/=10)_e++;_e<D&&(ve-=D-_e)}return Pe.e=ve,Pe.d=Le,Pe}function Oe(ie){return m(ie=new this(ie),ie.e+1,this.rounding)}function Ve(ie){return ie=new this(ie),ie.d?ie.d[0]?ie.s:0*ie.s:ie.s||NaN}function qe(ie){return new this(ie).sin()}function Ye(ie){return new this(ie).sinh()}function pt(ie){return new this(ie).sqrt()}function Ge(ie,de){return new this(ie).sub(de)}function Xe(){var ie=0,de=arguments,ve=new this(de[ie]);for(w=!1;ve.s&&++ie<de.length;)ve=ve.plus(de[ie]);return w=!0,m(ve,this.precision,this.rounding)}function lt(ie){return new this(ie).tan()}function Qe(ie){return new this(ie).tanh()}function st(ie){return m(ie=new this(ie),ie.e+1,1)}p=De(l),p.prototype.constructor=p,p.default=p.Decimal=p,n=new p(n),a=new p(a),e.exports?(typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"&&(_[Symbol.for("nodejs.util.inspect.custom")]=_.toString,_[Symbol.toStringTag]="Decimal"),e.exports=p):(t||(t=typeof self<"u"&&self&&self.self==self?self:window),c=t.Decimal,p.noConflict=function(){return t.Decimal=c,p},t.Decimal=p)})(commonjsGlobal)})(decimal);var decimalExports=decimal.exports,binaryParser={},__createBinding$1=commonjsGlobal&&commonjsGlobal.__createBinding||(Object.create?function(e,t,r,s){s===void 0&&(s=r);var o=Object.getOwnPropertyDescriptor(t,r);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,o)}:function(e,t,r,s){s===void 0&&(s=r),e[s]=t[r]}),__setModuleDefault$1=commonjsGlobal&&commonjsGlobal.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar$1=commonjsGlobal&&commonjsGlobal.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)r!=="default"&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding$1(t,e,r);return __setModuleDefault$1(t,e),t};Object.defineProperty(binaryParser,"__esModule",{value:!0});binaryParser.BinaryParser=void 0;const assert$2=__importStar$1(requireAssert()),enums_1=enums,buffer_1$h=dist$t;class BinaryParser{constructor(t,r=enums_1.DEFAULT_DEFINITIONS){this.bytes=buffer_1$h.Buffer.from(t,"hex"),this.definitions=r}peek(){return assert$2.ok(this.bytes.byteLength!==0),this.bytes[0]}skip(t){assert$2.ok(t<=this.bytes.byteLength),this.bytes=this.bytes.slice(t)}read(t){assert$2.ok(t<=this.bytes.byteLength);const r=this.bytes.slice(0,t);return this.skip(t),r}readUIntN(t){return assert$2.ok(0<t&&t<=4,"invalid n"),this.read(t).reduce((r,s)=>r<<8|s)>>>0}readUInt8(){return this.readUIntN(1)}readUInt16(){return this.readUIntN(2)}readUInt32(){return this.readUIntN(4)}size(){return this.bytes.byteLength}end(t){const r=this.bytes.byteLength;return r===0||t!==void 0&&r<=t}readVariableLength(){return this.read(this.readVariableLengthLength())}readVariableLengthLength(){const t=this.readUInt8();if(t<=192)return t;if(t<=240){const r=this.readUInt8();return 193+(t-193)*256+r}else if(t<=254){const r=this.readUInt8(),s=this.readUInt8();return 12481+(t-241)*65536+r*256+s}throw new Error("Invalid variable length indicator")}readFieldOrdinal(){let t=this.readUInt8(),r=t&15;if(t>>=4,t===0&&(t=this.readUInt8(),t===0||t<16))throw new Error("Cannot read FieldOrdinal, type_code out of range");if(r===0&&(r=this.readUInt8(),r===0||r<16))throw new Error("Cannot read FieldOrdinal, field_code out of range");return t<<16|r}readField(){return this.definitions.field.fromString(this.readFieldOrdinal().toString())}readType(t){return t.fromParser(this)}typeForField(t){return t.associatedType}readFieldValue(t){const r=this.typeForField(t);if(!r)throw new Error(`unsupported: (${t.name}, ${t.type.name})`);const s=t.isVariableLengthEncoded?this.readVariableLengthLength():void 0,o=r.fromParser(this,s);if(o===void 0)throw new Error(`fromParser for (${t.name}, ${t.type.name}) -> undefined `);return o}readFieldAndValue(){const t=this.readField();return[t,this.readFieldValue(t)]}}binaryParser.BinaryParser=BinaryParser;var currency={};Object.defineProperty(currency,"__esModule",{value:!0});currency.Currency=void 0;const hash_160_1=hash160$1,buffer_1$g=dist$t,XRP_HEX_REGEX=/^0{40}$/,ISO_REGEX=/^[A-Z0-9a-z?!@#$%^&*(){}[\]|]{3}$/,HEX_REGEX$1=/^[A-F0-9]{40}$/,STANDARD_FORMAT_HEX_REGEX=/^0{24}[\x00-\x7F]{6}0{10}$/;function isoToBytes(e){const t=buffer_1$g.Buffer.alloc(20);if(e!=="XRP"){const r=e.split("").map(s=>s.charCodeAt(0));t.set(r,12)}return t}function isIsoCode(e){return ISO_REGEX.test(e)}function isoCodeFromHex(e){const t=e.toString();return t==="XRP"?null:isIsoCode(t)?t:null}function isHex(e){return HEX_REGEX$1.test(e)}function isStringRepresentation(e){return e.length===3||isHex(e)}function isBytesArray(e){return e.byteLength===20}function isValidRepresentation(e){return e instanceof buffer_1$g.Buffer?isBytesArray(e):isStringRepresentation(e)}function bytesFromRepresentation(e){if(!isValidRepresentation(e))throw new Error(`Unsupported Currency representation: ${e}`);return e.length===3?isoToBytes(e):buffer_1$g.Buffer.from(e,"hex")}class Currency extends hash_160_1.Hash160{constructor(t){super(t??Currency.XRP.bytes);const r=this.bytes.toString("hex");XRP_HEX_REGEX.test(r)?this._iso="XRP":STANDARD_FORMAT_HEX_REGEX.test(r)?this._iso=isoCodeFromHex(this.bytes.slice(12,15)):this._iso=null}iso(){return this._iso}static from(t){if(t instanceof Currency)return t;if(typeof t=="string")return new Currency(bytesFromRepresentation(t));throw new Error("Cannot construct Currency from value given")}toJSON(){const t=this.iso();return t!==null?t:this.bytes.toString("hex").toUpperCase()}}currency.Currency=Currency;Currency.XRP=new Currency(buffer_1$g.Buffer.alloc(20));var BigInteger={exports:{}};(function(e){var t=function(r){var s=1e7,o=7,n=9007199254740992,a=E(n),l="0123456789abcdefghijklmnopqrstuvwxyz",p=typeof BigInt=="function";function u(he,ae,be,Ae){return typeof he>"u"?u[0]:typeof ae<"u"?+ae==10&&!be?Ie(he):Be(he,ae,be,Ae):Ie(he)}function c(he,ae){this.value=he,this.sign=ae,this.isSmall=!1}c.prototype=Object.create(u.prototype);function v(he){this.value=he,this.sign=he<0,this.isSmall=!0}v.prototype=Object.create(u.prototype);function w(he){this.value=he}w.prototype=Object.create(u.prototype);function b(he){return-n<he&&he<n}function E(he){return he<1e7?[he]:he<1e14?[he%1e7,Math.floor(he/1e7)]:[he%1e7,Math.floor(he/1e7)%1e7,Math.floor(he/1e14)]}function I(he){x(he);var ae=he.length;if(ae<4&&m(he,a)<0)switch(ae){case 0:return 0;case 1:return he[0];case 2:return he[0]+he[1]*s;default:return he[0]+(he[1]+he[2]*s)*s}return he}function x(he){for(var ae=he.length;he[--ae]===0;);he.length=ae+1}function B(he){for(var ae=new Array(he),be=-1;++be<he;)ae[be]=0;return ae}function M(he){return he>0?Math.floor(he):Math.ceil(he)}function q(he,ae){var be=he.length,Ae=ae.length,re=new Array(be),z=0,Q=s,ue,we;for(we=0;we<Ae;we++)ue=he[we]+ae[we]+z,z=ue>=Q?1:0,re[we]=ue-z*Q;for(;we<be;)ue=he[we]+z,z=ue===Q?1:0,re[we++]=ue-z*Q;return z>0&&re.push(z),re}function U(he,ae){return he.length>=ae.length?q(he,ae):q(ae,he)}function F(he,ae){var be=he.length,Ae=new Array(be),re=s,z,Q;for(Q=0;Q<be;Q++)z=he[Q]-re+ae,ae=Math.floor(z/re),Ae[Q]=z-ae*re,ae+=1;for(;ae>0;)Ae[Q++]=ae%re,ae=Math.floor(ae/re);return Ae}c.prototype.add=function(he){var ae=Ie(he);if(this.sign!==ae.sign)return this.subtract(ae.negate());var be=this.value,Ae=ae.value;return ae.isSmall?new c(F(be,Math.abs(Ae)),this.sign):new c(U(be,Ae),this.sign)},c.prototype.plus=c.prototype.add,v.prototype.add=function(he){var ae=Ie(he),be=this.value;if(be<0!==ae.sign)return this.subtract(ae.negate());var Ae=ae.value;if(ae.isSmall){if(b(be+Ae))return new v(be+Ae);Ae=E(Math.abs(Ae))}return new c(F(Ae,Math.abs(be)),be<0)},v.prototype.plus=v.prototype.add,w.prototype.add=function(he){return new w(this.value+Ie(he).value)},w.prototype.plus=w.prototype.add;function j(he,ae){var be=he.length,Ae=ae.length,re=new Array(be),z=0,Q=s,ue,we;for(ue=0;ue<Ae;ue++)we=he[ue]-z-ae[ue],we<0?(we+=Q,z=1):z=0,re[ue]=we;for(ue=Ae;ue<be;ue++){if(we=he[ue]-z,we<0)we+=Q;else{re[ue++]=we;break}re[ue]=we}for(;ue<be;ue++)re[ue]=he[ue];return x(re),re}function y(he,ae,be){var Ae;return m(he,ae)>=0?Ae=j(he,ae):(Ae=j(ae,he),be=!be),Ae=I(Ae),typeof Ae=="number"?(be&&(Ae=-Ae),new v(Ae)):new c(Ae,be)}function T(he,ae,be){var Ae=he.length,re=new Array(Ae),z=-ae,Q=s,ue,we;for(ue=0;ue<Ae;ue++)we=he[ue]+z,z=Math.floor(we/Q),we%=Q,re[ue]=we<0?we+Q:we;return re=I(re),typeof re=="number"?(be&&(re=-re),new v(re)):new c(re,be)}c.prototype.subtract=function(he){var ae=Ie(he);if(this.sign!==ae.sign)return this.add(ae.negate());var be=this.value,Ae=ae.value;return ae.isSmall?T(be,Math.abs(Ae),this.sign):y(be,Ae,this.sign)},c.prototype.minus=c.prototype.subtract,v.prototype.subtract=function(he){var ae=Ie(he),be=this.value;if(be<0!==ae.sign)return this.add(ae.negate());var Ae=ae.value;return ae.isSmall?new v(be-Ae):T(Ae,Math.abs(be),be>=0)},v.prototype.minus=v.prototype.subtract,w.prototype.subtract=function(he){return new w(this.value-Ie(he).value)},w.prototype.minus=w.prototype.subtract,c.prototype.negate=function(){return new c(this.value,!this.sign)},v.prototype.negate=function(){var he=this.sign,ae=new v(-this.value);return ae.sign=!he,ae},w.prototype.negate=function(){return new w(-this.value)},c.prototype.abs=function(){return new c(this.value,!1)},v.prototype.abs=function(){return new v(Math.abs(this.value))},w.prototype.abs=function(){return new w(this.value>=0?this.value:-this.value)};function D(he,ae){var be=he.length,Ae=ae.length,re=be+Ae,z=B(re),Q=s,ue,we,Ne,De,je;for(Ne=0;Ne<be;++Ne){De=he[Ne];for(var ot=0;ot<Ae;++ot)je=ae[ot],ue=De*je+z[Ne+ot],we=Math.floor(ue/Q),z[Ne+ot]=ue-we*Q,z[Ne+ot+1]+=we}return x(z),z}function L(he,ae){var be=he.length,Ae=new Array(be),re=s,z=0,Q,ue;for(ue=0;ue<be;ue++)Q=he[ue]*ae+z,z=Math.floor(Q/re),Ae[ue]=Q-z*re;for(;z>0;)Ae[ue++]=z%re,z=Math.floor(z/re);return Ae}function C(he,ae){for(var be=[];ae-- >0;)be.push(0);return be.concat(he)}function d(he,ae){var be=Math.max(he.length,ae.length);if(be<=30)return D(he,ae);be=Math.ceil(be/2);var Ae=he.slice(be),re=he.slice(0,be),z=ae.slice(be),Q=ae.slice(0,be),ue=d(re,Q),we=d(Ae,z),Ne=d(U(re,Ae),U(Q,z)),De=U(U(ue,C(j(j(Ne,ue),we),be)),C(we,2*be));return x(De),De}function _(he,ae){return-.012*he-.012*ae+15e-6*he*ae>0}c.prototype.multiply=function(he){var ae=Ie(he),be=this.value,Ae=ae.value,re=this.sign!==ae.sign,z;if(ae.isSmall){if(Ae===0)return u[0];if(Ae===1)return this;if(Ae===-1)return this.negate();if(z=Math.abs(Ae),z<s)return new c(L(be,z),re);Ae=E(z)}return _(be.length,Ae.length)?new c(d(be,Ae),re):new c(D(be,Ae),re)},c.prototype.times=c.prototype.multiply;function $(he,ae,be){return he<s?new c(L(ae,he),be):new c(D(ae,E(he)),be)}v.prototype._multiplyBySmall=function(he){return b(he.value*this.value)?new v(he.value*this.value):$(Math.abs(he.value),E(Math.abs(this.value)),this.sign!==he.sign)},c.prototype._multiplyBySmall=function(he){return he.value===0?u[0]:he.value===1?this:he.value===-1?this.negate():$(Math.abs(he.value),this.value,this.sign!==he.sign)},v.prototype.multiply=function(he){return Ie(he)._multiplyBySmall(this)},v.prototype.times=v.prototype.multiply,w.prototype.multiply=function(he){return new w(this.value*Ie(he).value)},w.prototype.times=w.prototype.multiply;function S(he){var ae=he.length,be=B(ae+ae),Ae=s,re,z,Q,ue,we;for(Q=0;Q<ae;Q++){ue=he[Q],z=0-ue*ue;for(var Ne=Q;Ne<ae;Ne++)we=he[Ne],re=2*(ue*we)+be[Q+Ne]+z,z=Math.floor(re/Ae),be[Q+Ne]=re-z*Ae;be[Q+ae]=z}return x(be),be}c.prototype.square=function(){return new c(S(this.value),!1)},v.prototype.square=function(){var he=this.value*this.value;return b(he)?new v(he):new c(S(E(Math.abs(this.value))),!1)},w.prototype.square=function(he){return new w(this.value*this.value)};function O(he,ae){var be=he.length,Ae=ae.length,re=s,z=B(ae.length),Q=ae[Ae-1],ue=Math.ceil(re/(2*Q)),we=L(he,ue),Ne=L(ae,ue),De,je,ot,He,We,ht,Je;for(we.length<=be&&we.push(0),Ne.push(0),Q=Ne[Ae-1],je=be-Ae;je>=0;je--){for(De=re-1,we[je+Ae]!==Q&&(De=Math.floor((we[je+Ae]*re+we[je+Ae-1])/Q)),ot=0,He=0,ht=Ne.length,We=0;We<ht;We++)ot+=De*Ne[We],Je=Math.floor(ot/re),He+=we[je+We]-(ot-Je*re),ot=Je,He<0?(we[je+We]=He+re,He=-1):(we[je+We]=He,He=0);for(;He!==0;){for(De-=1,ot=0,We=0;We<ht;We++)ot+=we[je+We]-re+Ne[We],ot<0?(we[je+We]=ot+re,ot=0):(we[je+We]=ot,ot=1);He+=ot}z[je]=De}return we=k(we,ue)[0],[I(z),I(we)]}function N(he,ae){for(var be=he.length,Ae=ae.length,re=[],z=[],Q=s,ue,we,Ne,De,je;be;){if(z.unshift(he[--be]),x(z),m(z,ae)<0){re.push(0);continue}we=z.length,Ne=z[we-1]*Q+z[we-2],De=ae[Ae-1]*Q+ae[Ae-2],we>Ae&&(Ne=(Ne+1)*Q),ue=Math.ceil(Ne/De);do{if(je=L(ae,ue),m(je,z)<=0)break;ue--}while(ue);re.push(ue),z=j(z,je)}return re.reverse(),[I(re),I(z)]}function k(he,ae){var be=he.length,Ae=B(be),re=s,z,Q,ue,we;for(ue=0,z=be-1;z>=0;--z)we=ue*re+he[z],Q=M(we/ae),ue=we-Q*ae,Ae[z]=Q|0;return[Ae,ue|0]}function A(he,ae){var be,Ae=Ie(ae);if(p)return[new w(he.value/Ae.value),new w(he.value%Ae.value)];var re=he.value,z=Ae.value,Q;if(z===0)throw new Error("Cannot divide by zero");if(he.isSmall)return Ae.isSmall?[new v(M(re/z)),new v(re%z)]:[u[0],he];if(Ae.isSmall){if(z===1)return[he,u[0]];if(z==-1)return[he.negate(),u[0]];var ue=Math.abs(z);if(ue<s){be=k(re,ue),Q=I(be[0]);var we=be[1];return he.sign&&(we=-we),typeof Q=="number"?(he.sign!==Ae.sign&&(Q=-Q),[new v(Q),new v(we)]):[new c(Q,he.sign!==Ae.sign),new v(we)]}z=E(ue)}var Ne=m(re,z);if(Ne===-1)return[u[0],he];if(Ne===0)return[u[he.sign===Ae.sign?1:-1],u[0]];re.length+z.length<=200?be=O(re,z):be=N(re,z),Q=be[0];var De=he.sign!==Ae.sign,je=be[1],ot=he.sign;return typeof Q=="number"?(De&&(Q=-Q),Q=new v(Q)):Q=new c(Q,De),typeof je=="number"?(ot&&(je=-je),je=new v(je)):je=new c(je,ot),[Q,je]}c.prototype.divmod=function(he){var ae=A(this,he);return{quotient:ae[0],remainder:ae[1]}},w.prototype.divmod=v.prototype.divmod=c.prototype.divmod,c.prototype.divide=function(he){return A(this,he)[0]},w.prototype.over=w.prototype.divide=function(he){return new w(this.value/Ie(he).value)},v.prototype.over=v.prototype.divide=c.prototype.over=c.prototype.divide,c.prototype.mod=function(he){return A(this,he)[1]},w.prototype.mod=w.prototype.remainder=function(he){return new w(this.value%Ie(he).value)},v.prototype.remainder=v.prototype.mod=c.prototype.remainder=c.prototype.mod,c.prototype.pow=function(he){var ae=Ie(he),be=this.value,Ae=ae.value,re,z,Q;if(Ae===0)return u[1];if(be===0)return u[0];if(be===1)return u[1];if(be===-1)return ae.isEven()?u[1]:u[-1];if(ae.sign)return u[0];if(!ae.isSmall)throw new Error("The exponent "+ae.toString()+" is too large.");if(this.isSmall&&b(re=Math.pow(be,Ae)))return new v(M(re));for(z=this,Q=u[1];Ae&!0&&(Q=Q.times(z),--Ae),Ae!==0;)Ae/=2,z=z.square();return Q},v.prototype.pow=c.prototype.pow,w.prototype.pow=function(he){var ae=Ie(he),be=this.value,Ae=ae.value,re=BigInt(0),z=BigInt(1),Q=BigInt(2);if(Ae===re)return u[1];if(be===re)return u[0];if(be===z)return u[1];if(be===BigInt(-1))return ae.isEven()?u[1]:u[-1];if(ae.isNegative())return new w(re);for(var ue=this,we=u[1];(Ae&z)===z&&(we=we.times(ue),--Ae),Ae!==re;)Ae/=Q,ue=ue.square();return we},c.prototype.modPow=function(he,ae){if(he=Ie(he),ae=Ie(ae),ae.isZero())throw new Error("Cannot take modPow with modulus 0");var be=u[1],Ae=this.mod(ae);for(he.isNegative()&&(he=he.multiply(u[-1]),Ae=Ae.modInv(ae));he.isPositive();){if(Ae.isZero())return u[0];he.isOdd()&&(be=be.multiply(Ae).mod(ae)),he=he.divide(2),Ae=Ae.square().mod(ae)}return be},w.prototype.modPow=v.prototype.modPow=c.prototype.modPow;function m(he,ae){if(he.length!==ae.length)return he.length>ae.length?1:-1;for(var be=he.length-1;be>=0;be--)if(he[be]!==ae[be])return he[be]>ae[be]?1:-1;return 0}c.prototype.compareAbs=function(he){var ae=Ie(he),be=this.value,Ae=ae.value;return ae.isSmall?1:m(be,Ae)},v.prototype.compareAbs=function(he){var ae=Ie(he),be=Math.abs(this.value),Ae=ae.value;return ae.isSmall?(Ae=Math.abs(Ae),be===Ae?0:be>Ae?1:-1):-1},w.prototype.compareAbs=function(he){var ae=this.value,be=Ie(he).value;return ae=ae>=0?ae:-ae,be=be>=0?be:-be,ae===be?0:ae>be?1:-1},c.prototype.compare=function(he){if(he===1/0)return-1;if(he===-1/0)return 1;var ae=Ie(he),be=this.value,Ae=ae.value;return this.sign!==ae.sign?ae.sign?1:-1:ae.isSmall?this.sign?-1:1:m(be,Ae)*(this.sign?-1:1)},c.prototype.compareTo=c.prototype.compare,v.prototype.compare=function(he){if(he===1/0)return-1;if(he===-1/0)return 1;var ae=Ie(he),be=this.value,Ae=ae.value;return ae.isSmall?be==Ae?0:be>Ae?1:-1:be<0!==ae.sign?be<0?-1:1:be<0?1:-1},v.prototype.compareTo=v.prototype.compare,w.prototype.compare=function(he){if(he===1/0)return-1;if(he===-1/0)return 1;var ae=this.value,be=Ie(he).value;return ae===be?0:ae>be?1:-1},w.prototype.compareTo=w.prototype.compare,c.prototype.equals=function(he){return this.compare(he)===0},w.prototype.eq=w.prototype.equals=v.prototype.eq=v.prototype.equals=c.prototype.eq=c.prototype.equals,c.prototype.notEquals=function(he){return this.compare(he)!==0},w.prototype.neq=w.prototype.notEquals=v.prototype.neq=v.prototype.notEquals=c.prototype.neq=c.prototype.notEquals,c.prototype.greater=function(he){return this.compare(he)>0},w.prototype.gt=w.prototype.greater=v.prototype.gt=v.prototype.greater=c.prototype.gt=c.prototype.greater,c.prototype.lesser=function(he){return this.compare(he)<0},w.prototype.lt=w.prototype.lesser=v.prototype.lt=v.prototype.lesser=c.prototype.lt=c.prototype.lesser,c.prototype.greaterOrEquals=function(he){return this.compare(he)>=0},w.prototype.geq=w.prototype.greaterOrEquals=v.prototype.geq=v.prototype.greaterOrEquals=c.prototype.geq=c.prototype.greaterOrEquals,c.prototype.lesserOrEquals=function(he){return this.compare(he)<=0},w.prototype.leq=w.prototype.lesserOrEquals=v.prototype.leq=v.prototype.lesserOrEquals=c.prototype.leq=c.prototype.lesserOrEquals,c.prototype.isEven=function(){return(this.value[0]&1)===0},v.prototype.isEven=function(){return(this.value&1)===0},w.prototype.isEven=function(){return(this.value&BigInt(1))===BigInt(0)},c.prototype.isOdd=function(){return(this.value[0]&1)===1},v.prototype.isOdd=function(){return(this.value&1)===1},w.prototype.isOdd=function(){return(this.value&BigInt(1))===BigInt(1)},c.prototype.isPositive=function(){return!this.sign},v.prototype.isPositive=function(){return this.value>0},w.prototype.isPositive=v.prototype.isPositive,c.prototype.isNegative=function(){return this.sign},v.prototype.isNegative=function(){return this.value<0},w.prototype.isNegative=v.prototype.isNegative,c.prototype.isUnit=function(){return!1},v.prototype.isUnit=function(){return Math.abs(this.value)===1},w.prototype.isUnit=function(){return this.abs().value===BigInt(1)},c.prototype.isZero=function(){return!1},v.prototype.isZero=function(){return this.value===0},w.prototype.isZero=function(){return this.value===BigInt(0)},c.prototype.isDivisibleBy=function(he){var ae=Ie(he);return ae.isZero()?!1:ae.isUnit()?!0:ae.compareAbs(2)===0?this.isEven():this.mod(ae).isZero()},w.prototype.isDivisibleBy=v.prototype.isDivisibleBy=c.prototype.isDivisibleBy;function P(he){var ae=he.abs();if(ae.isUnit())return!1;if(ae.equals(2)||ae.equals(3)||ae.equals(5))return!0;if(ae.isEven()||ae.isDivisibleBy(3)||ae.isDivisibleBy(5))return!1;if(ae.lesser(49))return!0}function H(he,ae){for(var be=he.prev(),Ae=be,re=0,z,Q,ue;Ae.isEven();)Ae=Ae.divide(2),re++;e:for(Q=0;Q<ae.length;Q++)if(!he.lesser(ae[Q])&&(ue=t(ae[Q]).modPow(Ae,he),!(ue.isUnit()||ue.equals(be)))){for(z=re-1;z!=0;z--){if(ue=ue.square().mod(he),ue.isUnit())return!1;if(ue.equals(be))continue e}return!1}return!0}c.prototype.isPrime=function(he){var ae=P(this);if(ae!==r)return ae;var be=this.abs(),Ae=be.bitLength();if(Ae<=64)return H(be,[2,3,5,7,11,13,17,19,23,29,31,37]);for(var re=Math.log(2)*Ae.toJSNumber(),z=Math.ceil(he===!0?2*Math.pow(re,2):re),Q=[],ue=0;ue<z;ue++)Q.push(t(ue+2));return H(be,Q)},w.prototype.isPrime=v.prototype.isPrime=c.prototype.isPrime,c.prototype.isProbablePrime=function(he,ae){var be=P(this);if(be!==r)return be;for(var Ae=this.abs(),re=he===r?5:he,z=[],Q=0;Q<re;Q++)z.push(t.randBetween(2,Ae.minus(2),ae));return H(Ae,z)},w.prototype.isProbablePrime=v.prototype.isProbablePrime=c.prototype.isProbablePrime,c.prototype.modInv=function(he){for(var ae=t.zero,be=t.one,Ae=Ie(he),re=this.abs(),z,Q,ue;!re.isZero();)z=Ae.divide(re),Q=ae,ue=Ae,ae=be,Ae=re,be=Q.subtract(z.multiply(be)),re=ue.subtract(z.multiply(re));if(!Ae.isUnit())throw new Error(this.toString()+" and "+he.toString()+" are not co-prime");return ae.compare(0)===-1&&(ae=ae.add(he)),this.isNegative()?ae.negate():ae},w.prototype.modInv=v.prototype.modInv=c.prototype.modInv,c.prototype.next=function(){var he=this.value;return this.sign?T(he,1,this.sign):new c(F(he,1),this.sign)},v.prototype.next=function(){var he=this.value;return he+1<n?new v(he+1):new c(a,!1)},w.prototype.next=function(){return new w(this.value+BigInt(1))},c.prototype.prev=function(){var he=this.value;return this.sign?new c(F(he,1),!0):T(he,1,this.sign)},v.prototype.prev=function(){var he=this.value;return he-1>-n?new v(he-1):new c(a,!0)},w.prototype.prev=function(){return new w(this.value-BigInt(1))};for(var J=[1];2*J[J.length-1]<=s;)J.push(2*J[J.length-1]);var X=J.length,se=J[X-1];function ne(he){return Math.abs(he)<=s}c.prototype.shiftLeft=function(he){var ae=Ie(he).toJSNumber();if(!ne(ae))throw new Error(String(ae)+" is too large for shifting.");if(ae<0)return this.shiftRight(-ae);var be=this;if(be.isZero())return be;for(;ae>=X;)be=be.multiply(se),ae-=X-1;return be.multiply(J[ae])},w.prototype.shiftLeft=v.prototype.shiftLeft=c.prototype.shiftLeft,c.prototype.shiftRight=function(he){var ae,be=Ie(he).toJSNumber();if(!ne(be))throw new Error(String(be)+" is too large for shifting.");if(be<0)return this.shiftLeft(-be);for(var Ae=this;be>=X;){if(Ae.isZero()||Ae.isNegative()&&Ae.isUnit())return Ae;ae=A(Ae,se),Ae=ae[1].isNegative()?ae[0].prev():ae[0],be-=X-1}return ae=A(Ae,J[be]),ae[1].isNegative()?ae[0].prev():ae[0]},w.prototype.shiftRight=v.prototype.shiftRight=c.prototype.shiftRight;function Z(he,ae,be){ae=Ie(ae);for(var Ae=he.isNegative(),re=ae.isNegative(),z=Ae?he.not():he,Q=re?ae.not():ae,ue=0,we=0,Ne=null,De=null,je=[];!z.isZero()||!Q.isZero();)Ne=A(z,se),ue=Ne[1].toJSNumber(),Ae&&(ue=se-1-ue),De=A(Q,se),we=De[1].toJSNumber(),re&&(we=se-1-we),z=Ne[0],Q=De[0],je.push(be(ue,we));for(var ot=be(Ae?1:0,re?1:0)!==0?t(-1):t(0),He=je.length-1;He>=0;He-=1)ot=ot.multiply(se).add(t(je[He]));return ot}c.prototype.not=function(){return this.negate().prev()},w.prototype.not=v.prototype.not=c.prototype.not,c.prototype.and=function(he){return Z(this,he,function(ae,be){return ae&be})},w.prototype.and=v.prototype.and=c.prototype.and,c.prototype.or=function(he){return Z(this,he,function(ae,be){return ae|be})},w.prototype.or=v.prototype.or=c.prototype.or,c.prototype.xor=function(he){return Z(this,he,function(ae,be){return ae^be})},w.prototype.xor=v.prototype.xor=c.prototype.xor;var oe=1<<30,ye=(s&-s)*(s&-s)|oe;function Y(he){var ae=he.value,be=typeof ae=="number"?ae|oe:typeof ae=="bigint"?ae|BigInt(oe):ae[0]+ae[1]*s|ye;return be&-be}function G(he,ae){if(ae.compareTo(he)<=0){var be=G(he,ae.square(ae)),Ae=be.p,re=be.e,z=Ae.multiply(ae);return z.compareTo(he)<=0?{p:z,e:re*2+1}:{p:Ae,e:re*2}}return{p:t(1),e:0}}c.prototype.bitLength=function(){var he=this;return he.compareTo(t(0))<0&&(he=he.negate().subtract(t(1))),he.compareTo(t(0))===0?t(0):t(G(he,t(2)).e).add(t(1))},w.prototype.bitLength=v.prototype.bitLength=c.prototype.bitLength;function V(he,ae){return he=Ie(he),ae=Ie(ae),he.greater(ae)?he:ae}function te(he,ae){return he=Ie(he),ae=Ie(ae),he.lesser(ae)?he:ae}function le(he,ae){if(he=Ie(he).abs(),ae=Ie(ae).abs(),he.equals(ae))return he;if(he.isZero())return ae;if(ae.isZero())return he;for(var be=u[1],Ae,re;he.isEven()&&ae.isEven();)Ae=te(Y(he),Y(ae)),he=he.divide(Ae),ae=ae.divide(Ae),be=be.multiply(Ae);for(;he.isEven();)he=he.divide(Y(he));do{for(;ae.isEven();)ae=ae.divide(Y(ae));he.greater(ae)&&(re=ae,ae=he,he=re),ae=ae.subtract(he)}while(!ae.isZero());return be.isUnit()?he:he.multiply(be)}function me(he,ae){return he=Ie(he).abs(),ae=Ie(ae).abs(),he.divide(le(he,ae)).multiply(ae)}function Re(he,ae,be){he=Ie(he),ae=Ie(ae);var Ae=be||Math.random,re=te(he,ae),z=V(he,ae),Q=z.subtract(re).add(1);if(Q.isSmall)return re.add(Math.floor(Ae()*Q));for(var ue=Ue(Q,s).value,we=[],Ne=!0,De=0;De<ue.length;De++){var je=Ne?ue[De]+(De+1<ue.length?ue[De+1]/s:0):s,ot=M(Ae()*je);we.push(ot),ot<ue[De]&&(Ne=!1)}return re.add(u.fromArray(we,s,!1))}var Be=function(he,ae,be,Ae){be=be||l,he=String(he),Ae||(he=he.toLowerCase(),be=be.toLowerCase());var re=he.length,z,Q=Math.abs(ae),ue={};for(z=0;z<be.length;z++)ue[be[z]]=z;for(z=0;z<re;z++){var we=he[z];if(we!=="-"&&we in ue&&ue[we]>=Q){if(we==="1"&&Q===1)continue;throw new Error(we+" is not a valid digit in base "+ae+".")}}ae=Ie(ae);var Ne=[],De=he[0]==="-";for(z=De?1:0;z<he.length;z++){var we=he[z];if(we in ue)Ne.push(Ie(ue[we]));else if(we==="<"){var je=z;do z++;while(he[z]!==">"&&z<he.length);Ne.push(Ie(he.slice(je+1,z)))}else throw new Error(we+" is not a valid character")}return Ce(Ne,ae,De)};function Ce(he,ae,be){var Ae=u[0],re=u[1],z;for(z=he.length-1;z>=0;z--)Ae=Ae.add(he[z].times(re)),re=re.times(ae);return be?Ae.negate():Ae}function $e(he,ae){return ae=ae||l,he<ae.length?ae[he]:"<"+he+">"}function Ue(he,ae){if(ae=t(ae),ae.isZero()){if(he.isZero())return{value:[0],isNegative:!1};throw new Error("Cannot convert nonzero numbers to base 0.")}if(ae.equals(-1)){if(he.isZero())return{value:[0],isNegative:!1};if(he.isNegative())return{value:[].concat.apply([],Array.apply(null,Array(-he.toJSNumber())).map(Array.prototype.valueOf,[1,0])),isNegative:!1};var be=Array.apply(null,Array(he.toJSNumber()-1)).map(Array.prototype.valueOf,[0,1]);return be.unshift([1]),{value:[].concat.apply([],be),isNegative:!1}}var Ae=!1;if(he.isNegative()&&ae.isPositive()&&(Ae=!0,he=he.abs()),ae.isUnit())return he.isZero()?{value:[0],isNegative:!1}:{value:Array.apply(null,Array(he.toJSNumber())).map(Number.prototype.valueOf,1),isNegative:Ae};for(var re=[],z=he,Q;z.isNegative()||z.compareAbs(ae)>=0;){Q=z.divmod(ae),z=Q.quotient;var ue=Q.remainder;ue.isNegative()&&(ue=ae.minus(ue).abs(),z=z.next()),re.push(ue.toJSNumber())}return re.push(z.toJSNumber()),{value:re.reverse(),isNegative:Ae}}function Me(he,ae,be){var Ae=Ue(he,ae);return(Ae.isNegative?"-":"")+Ae.value.map(function(re){return $e(re,be)}).join("")}c.prototype.toArray=function(he){return Ue(this,he)},v.prototype.toArray=function(he){return Ue(this,he)},w.prototype.toArray=function(he){return Ue(this,he)},c.prototype.toString=function(he,ae){if(he===r&&(he=10),he!==10||ae)return Me(this,he,ae);for(var be=this.value,Ae=be.length,re=String(be[--Ae]),z="0000000",Q;--Ae>=0;)Q=String(be[Ae]),re+=z.slice(Q.length)+Q;var ue=this.sign?"-":"";return ue+re},v.prototype.toString=function(he,ae){return he===r&&(he=10),he!=10||ae?Me(this,he,ae):String(this.value)},w.prototype.toString=v.prototype.toString,w.prototype.toJSON=c.prototype.toJSON=v.prototype.toJSON=function(){return this.toString()},c.prototype.valueOf=function(){return parseInt(this.toString(),10)},c.prototype.toJSNumber=c.prototype.valueOf,v.prototype.valueOf=function(){return this.value},v.prototype.toJSNumber=v.prototype.valueOf,w.prototype.valueOf=w.prototype.toJSNumber=function(){return parseInt(this.toString(),10)};function ke(he){if(b(+he)){var ae=+he;if(ae===M(ae))return p?new w(BigInt(ae)):new v(ae);throw new Error("Invalid integer: "+he)}var be=he[0]==="-";be&&(he=he.slice(1));var Ae=he.split(/e/i);if(Ae.length>2)throw new Error("Invalid integer: "+Ae.join("e"));if(Ae.length===2){var re=Ae[1];if(re[0]==="+"&&(re=re.slice(1)),re=+re,re!==M(re)||!b(re))throw new Error("Invalid integer: "+re+" is not a valid exponent.");var z=Ae[0],Q=z.indexOf(".");if(Q>=0&&(re-=z.length-Q-1,z=z.slice(0,Q)+z.slice(Q+1)),re<0)throw new Error("Cannot include negative exponent part for integers");z+=new Array(re+1).join("0"),he=z}var ue=/^([0-9][0-9]*)$/.test(he);if(!ue)throw new Error("Invalid integer: "+he);if(p)return new w(BigInt(be?"-"+he:he));for(var we=[],Ne=he.length,De=o,je=Ne-De;Ne>0;)we.push(+he.slice(je,Ne)),je-=De,je<0&&(je=0),Ne-=De;return x(we),new c(we,be)}function tt(he){if(p)return new w(BigInt(he));if(b(he)){if(he!==M(he))throw new Error(he+" is not an integer.");return new v(he)}return ke(he.toString())}function Ie(he){return typeof he=="number"?tt(he):typeof he=="string"?ke(he):typeof he=="bigint"?new w(he):he}for(var xe=0;xe<1e3;xe++)u[xe]=Ie(xe),xe>0&&(u[-xe]=Ie(-xe));return u.one=u[1],u.zero=u[0],u.minusOne=u[-1],u.max=V,u.min=te,u.gcd=le,u.lcm=me,u.isInstance=function(he){return he instanceof c||he instanceof v||he instanceof w},u.randBetween=Re,u.fromArray=function(he,ae,be){return Ce(he.map(Ie),Ie(ae||10),be)},u}();e.hasOwnProperty("exports")&&(e.exports=t)})(BigInteger);var BigIntegerExports=BigInteger.exports;Object.defineProperty(amount,"__esModule",{value:!0});amount.Amount=void 0;const decimal_js_1$1=decimalExports,binary_parser_1$4=binaryParser,account_id_1$3=accountId,currency_1$2=currency,serialized_type_1$6=serializedType,bigInt$3=BigIntegerExports,buffer_1$f=dist$t,MIN_IOU_EXPONENT=-96,MAX_IOU_EXPONENT=80,MAX_IOU_PRECISION=16,MAX_DROPS=new decimal_js_1$1.Decimal("1e17"),MIN_XRP=new decimal_js_1$1.Decimal("1e-6"),mask$1=bigInt$3(4294967295);decimal_js_1$1.Decimal.config({toExpPos:MAX_IOU_EXPONENT+MAX_IOU_PRECISION,toExpNeg:MIN_IOU_EXPONENT-MAX_IOU_PRECISION});function isAmountObject(e){const t=Object.keys(e).sort();return t.length===3&&t[0]==="currency"&&t[1]==="issuer"&&t[2]==="value"}class Amount extends serialized_type_1$6.SerializedType{constructor(t){super(t??Amount.defaultAmount.bytes)}static from(t){if(t instanceof Amount)return t;let r=buffer_1$f.Buffer.alloc(8);if(typeof t=="string"){Amount.assertXrpIsValid(t);const s=bigInt$3(t),o=[buffer_1$f.Buffer.alloc(4),buffer_1$f.Buffer.alloc(4)];return o[0].writeUInt32BE(Number(s.shiftRight(32)),0),o[1].writeUInt32BE(Number(s.and(mask$1)),0),r=buffer_1$f.Buffer.concat(o),r[0]|=64,new Amount(r)}if(isAmountObject(t)){const s=new decimal_js_1$1.Decimal(t.value);if(Amount.assertIouIsValid(s),s.isZero())r[0]|=128;else{const a=s.times(`1e${-(s.e-15)}`).abs().toString(),l=bigInt$3(a),p=[buffer_1$f.Buffer.alloc(4),buffer_1$f.Buffer.alloc(4)];p[0].writeUInt32BE(Number(l.shiftRight(32)),0),p[1].writeUInt32BE(Number(l.and(mask$1)),0),r=buffer_1$f.Buffer.concat(p),r[0]|=128,s.gt(new decimal_js_1$1.Decimal(0))&&(r[0]|=64);const c=97+(s.e-15);r[0]|=c>>>2,r[1]|=(c&3)<<6}const o=currency_1$2.Currency.from(t.currency).toBytes(),n=account_id_1$3.AccountID.from(t.issuer).toBytes();return new Amount(buffer_1$f.Buffer.concat([r,o,n]))}throw new Error("Invalid type to construct an Amount")}static fromParser(t){const s=t.peek()&128?48:8;return new Amount(t.read(s))}toJSON(){if(this.isNative()){const t=this.bytes,s=t[0]&64?"":"-";t[0]&=63;const o=bigInt$3(t.slice(0,4).readUInt32BE(0)),n=bigInt$3(t.slice(4).readUInt32BE(0)),a=o.shiftLeft(32).or(n);return`${s}${a.toString()}`}else{const t=new binary_parser_1$4.BinaryParser(this.toString()),r=t.read(8),s=currency_1$2.Currency.fromParser(t),o=account_id_1$3.AccountID.fromParser(t),n=r[0],a=r[1],p=n&64?"":"-",u=((n&63)<<2)+((a&255)>>6)-97;r[0]=0,r[1]&=63;const c=new decimal_js_1$1.Decimal(`${p}0x${r.toString("hex")}`).times(`1e${u}`);return Amount.assertIouIsValid(c),{value:c.toString(),currency:s.toJSON(),issuer:o.toJSON()}}}static assertXrpIsValid(t){if(t.indexOf(".")!==-1)throw new Error(`${t.toString()} is an illegal amount`);const r=new decimal_js_1$1.Decimal(t);if(!r.isZero()&&(r.lt(MIN_XRP)||r.gt(MAX_DROPS)))throw new Error(`${t.toString()} is an illegal amount`)}static assertIouIsValid(t){if(!t.isZero()){const r=t.precision(),s=t.e-15;if(r>MAX_IOU_PRECISION||s>MAX_IOU_EXPONENT||s<MIN_IOU_EXPONENT)throw new Error("Decimal precision out of range");this.verifyNoDecimal(t)}}static verifyNoDecimal(t){if(t.times(`1e${-(t.e-15)}`).abs().toString().indexOf(".")!==-1)throw new Error("Decimal place found in integerNumberString")}isNative(){return(this.bytes[0]&128)===0}}amount.Amount=Amount;Amount.defaultAmount=new Amount(buffer_1$f.Buffer.from("4000000000000000","hex"));var blob={};Object.defineProperty(blob,"__esModule",{value:!0});blob.Blob=void 0;const serialized_type_1$5=serializedType,buffer_1$e=dist$t;class Blob extends serialized_type_1$5.SerializedType{constructor(t){super(t)}static fromParser(t,r){return new Blob(t.read(r))}static from(t){if(t instanceof Blob)return t;if(typeof t=="string")return new Blob(buffer_1$e.Buffer.from(t,"hex"));throw new Error("Cannot construct Blob from value given")}}blob.Blob=Blob;var hash128={};Object.defineProperty(hash128,"__esModule",{value:!0});hash128.Hash128=void 0;const hash_1$1=hash$1,buffer_1$d=dist$t;class Hash128 extends hash_1$1.Hash{constructor(t){t&&t.byteLength===0&&(t=Hash128.ZERO_128.bytes),super(t??Hash128.ZERO_128.bytes)}toHex(){const t=this.toBytes().toString("hex").toUpperCase();return/^0+$/.exec(t)?"":t}}hash128.Hash128=Hash128;Hash128.width=16;Hash128.ZERO_128=new Hash128(buffer_1$d.Buffer.alloc(Hash128.width));var hash256={};Object.defineProperty(hash256,"__esModule",{value:!0});hash256.Hash256=void 0;const hash_1=hash$1,buffer_1$c=dist$t;class Hash256 extends hash_1.Hash{constructor(t){super(t??Hash256.ZERO_256.bytes)}}hash256.Hash256=Hash256;Hash256.width=32;Hash256.ZERO_256=new Hash256(buffer_1$c.Buffer.alloc(Hash256.width));var issue={};Object.defineProperty(issue,"__esModule",{value:!0});issue.Issue=void 0;const binary_parser_1$3=binaryParser,account_id_1$2=accountId,currency_1$1=currency,serialized_type_1$4=serializedType,buffer_1$b=dist$t;function isIssueObject(e){const t=Object.keys(e).sort();return t.length===1?t[0]==="currency":t.length===2&&t[0]==="currency"&&t[1]==="issuer"}class Issue extends serialized_type_1$4.SerializedType{constructor(t){super(t??Issue.ZERO_ISSUED_CURRENCY.bytes)}static from(t){if(t instanceof Issue)return t;if(isIssueObject(t)){const r=currency_1$1.Currency.from(t.currency).toBytes();if(t.issuer==null)return new Issue(r);const s=account_id_1$2.AccountID.from(t.issuer).toBytes();return new Issue(buffer_1$b.Buffer.concat([r,s]))}throw new Error("Invalid type to construct an Amount")}static fromParser(t){const r=t.read(20);if(new currency_1$1.Currency(r).toJSON()==="XRP")return new Issue(r);const s=[r,t.read(20)];return new Issue(buffer_1$b.Buffer.concat(s))}toJSON(){const t=new binary_parser_1$3.BinaryParser(this.toString()),r=currency_1$1.Currency.fromParser(t);if(r.toJSON()==="XRP")return{currency:r.toJSON()};const s=account_id_1$2.AccountID.fromParser(t);return{currency:r.toJSON(),issuer:s.toJSON()}}}issue.Issue=Issue;Issue.ZERO_ISSUED_CURRENCY=new Issue(buffer_1$b.Buffer.alloc(20));var pathSet={};Object.defineProperty(pathSet,"__esModule",{value:!0});pathSet.PathSet=void 0;const account_id_1$1=accountId,currency_1=currency,binary_parser_1$2=binaryParser,serialized_type_1$3=serializedType,buffer_1$a=dist$t,PATHSET_END_BYTE=0,PATH_SEPARATOR_BYTE=255,TYPE_ACCOUNT=1,TYPE_CURRENCY=16,TYPE_ISSUER=32;function isHopObject(e){return e.issuer!==void 0||e.account!==void 0||e.currency!==void 0}function isPathSet(e){return Array.isArray(e)&&e.length===0||Array.isArray(e)&&Array.isArray(e[0])&&e[0].length===0||Array.isArray(e)&&Array.isArray(e[0])&&isHopObject(e[0][0])}class Hop extends serialized_type_1$3.SerializedType{static from(t){if(t instanceof Hop)return t;const r=[buffer_1$a.Buffer.from([0])];return t.account&&(r.push(account_id_1$1.AccountID.from(t.account).toBytes()),r[0][0]|=TYPE_ACCOUNT),t.currency&&(r.push(currency_1.Currency.from(t.currency).toBytes()),r[0][0]|=TYPE_CURRENCY),t.issuer&&(r.push(account_id_1$1.AccountID.from(t.issuer).toBytes()),r[0][0]|=TYPE_ISSUER),new Hop(buffer_1$a.Buffer.concat(r))}static fromParser(t){const r=t.readUInt8(),s=[buffer_1$a.Buffer.from([r])];return r&TYPE_ACCOUNT&&s.push(t.read(account_id_1$1.AccountID.width)),r&TYPE_CURRENCY&&s.push(t.read(currency_1.Currency.width)),r&TYPE_ISSUER&&s.push(t.read(account_id_1$1.AccountID.width)),new Hop(buffer_1$a.Buffer.concat(s))}toJSON(){const t=new binary_parser_1$2.BinaryParser(this.bytes.toString("hex")),r=t.readUInt8();let s,o,n;r&TYPE_ACCOUNT&&(s=account_id_1$1.AccountID.fromParser(t).toJSON()),r&TYPE_CURRENCY&&(o=currency_1.Currency.fromParser(t).toJSON()),r&TYPE_ISSUER&&(n=account_id_1$1.AccountID.fromParser(t).toJSON());const a={};return s&&(a.account=s),n&&(a.issuer=n),o&&(a.currency=o),a}type(){return this.bytes[0]}}class Path extends serialized_type_1$3.SerializedType{static from(t){if(t instanceof Path)return t;const r=[];return t.forEach(s=>{r.push(Hop.from(s).toBytes())}),new Path(buffer_1$a.Buffer.concat(r))}static fromParser(t){const r=[];for(;!t.end()&&(r.push(Hop.fromParser(t).toBytes()),!(t.peek()===PATHSET_END_BYTE||t.peek()===PATH_SEPARATOR_BYTE)););return new Path(buffer_1$a.Buffer.concat(r))}toJSON(){const t=[],r=new binary_parser_1$2.BinaryParser(this.toString());for(;!r.end();)t.push(Hop.fromParser(r).toJSON());return t}}class PathSet extends serialized_type_1$3.SerializedType{static from(t){if(t instanceof PathSet)return t;if(isPathSet(t)){const r=[];return t.forEach(s=>{r.push(Path.from(s).toBytes()),r.push(buffer_1$a.Buffer.from([PATH_SEPARATOR_BYTE]))}),r[r.length-1]=buffer_1$a.Buffer.from([PATHSET_END_BYTE]),new PathSet(buffer_1$a.Buffer.concat(r))}throw new Error("Cannot construct PathSet from given value")}static fromParser(t){const r=[];for(;!t.end()&&(r.push(Path.fromParser(t).toBytes()),r.push(t.read(1)),r[r.length-1][0]!=PATHSET_END_BYTE););return new PathSet(buffer_1$a.Buffer.concat(r))}toJSON(){const t=[],r=new binary_parser_1$2.BinaryParser(this.toString());for(;!r.end();)t.push(Path.fromParser(r).toJSON()),r.skip(1);return t}}pathSet.PathSet=PathSet;var stArray={},stObject={},hasRequiredStObject;function requireStObject(){if(hasRequiredStObject)return stObject;hasRequiredStObject=1,Object.defineProperty(stObject,"__esModule",{value:!0}),stObject.STObject=void 0;const e=enums,t=serializedType,r=dist$1,s=binaryParser,o=binarySerializer,n=dist$t,a=requireStArray(),l=n.Buffer.from([225]),p="ObjectEndMarker",u="STObject",c="Destination",v="Account",w="SourceTag",b="DestinationTag";function E(B,M){const q=(0,r.xAddressToClassicAddress)(M);let U;if(B===c)U=b;else if(B===v)U=w;else if(q.tag!==!1)throw new Error(`${B} cannot have an associated tag`);return q.tag!==!1?{[B]:q.classicAddress,[U]:q.tag}:{[B]:q.classicAddress}}function I(B,M){if(!(B[w]===void 0||M[w]===void 0))throw new Error("Cannot have Account X-Address and SourceTag");if(!(B[b]===void 0||M[b]===void 0))throw new Error("Cannot have Destination X-Address and DestinationTag")}class x extends t.SerializedType{static fromParser(M){const q=new o.BytesList,U=new o.BinarySerializer(q);for(;!M.end();){const F=M.readField();if(F.name===p)break;const j=M.readFieldValue(F);U.writeFieldAndValue(F,j),F.type.name===u&&U.put(l)}return new x(q.toBytes())}static from(M,q,U=e.DEFAULT_DEFINITIONS){if(M instanceof x)return M;const F=new o.BytesList,j=new o.BinarySerializer(F);let y=!1;const T=Object.entries(M).reduce((L,[C,d])=>{let _;return d&&(0,r.isValidXAddress)(d.toString())&&(_=E(C,d.toString()),I(_,M)),Object.assign(L,_??{[C]:d})},{});let D=Object.keys(T).map(L=>U.field[L]).filter(L=>L!==void 0&&T[L.name]!==void 0&&L.isSerialized).sort((L,C)=>L.ordinal-C.ordinal);return q!==void 0&&(D=D.filter(q)),D.forEach(L=>{const C=L.type.name===u?this.from(T[L.name],void 0,U):L.type.name==="STArray"?a.STArray.from(T[L.name],U):L.associatedType.from(T[L.name]);if(C==null)throw new TypeError(`Unable to interpret "${L.name}: ${T[L.name]}".`);C.name==="UNLModify"&&(y=!0);const d=L.name=="Account"&&y;j.writeFieldAndValue(L,C,d),L.type.name===u&&j.put(l)}),new x(F.toBytes())}toJSON(M){const q=new s.BinaryParser(this.toString(),M),U={};for(;!q.end();){const F=q.readField();if(F.name===p)break;U[F.name]=q.readFieldValue(F).toJSON(M)}return U}}return stObject.STObject=x,stObject}var hasRequiredStArray;function requireStArray(){if(hasRequiredStArray)return stArray;hasRequiredStArray=1,Object.defineProperty(stArray,"__esModule",{value:!0}),stArray.STArray=void 0;const e=enums,t=serializedType,r=requireStObject(),s=binaryParser,o=dist$t,n=o.Buffer.from([241]),a="ArrayEndMarker",l=o.Buffer.from([225]);function p(c){return Array.isArray(c)&&(c.length===0||typeof c[0]=="object")}class u extends t.SerializedType{static fromParser(v){const w=[];for(;!v.end();){const b=v.readField();if(b.name===a)break;w.push(b.header,v.readFieldValue(b).toBytes(),l)}return w.push(n),new u(o.Buffer.concat(w))}static from(v,w=e.DEFAULT_DEFINITIONS){if(v instanceof u)return v;if(p(v)){const b=[];return v.forEach(E=>{b.push(r.STObject.from(E,void 0,w).toBytes())}),b.push(n),new u(o.Buffer.concat(b))}throw new Error("Cannot construct STArray from value given")}toJSON(v=e.DEFAULT_DEFINITIONS){const w=[],b=new s.BinaryParser(this.toString(),v);for(;!b.end();){const E=b.readField();if(E.name===a)break;const I={};I[E.name]=r.STObject.fromParser(b).toJSON(v),w.push(I)}return w}}return stArray.STArray=u,stArray}var uint16={},uint={};Object.defineProperty(uint,"__esModule",{value:!0});uint.UInt=void 0;const serialized_type_1$2=serializedType;function compare(e,t){return e<t?-1:e==t?0:1}class UInt extends serialized_type_1$2.Comparable{constructor(t){super(t)}compareTo(t){return compare(this.valueOf(),t.valueOf())}toJSON(){const t=this.valueOf();return typeof t=="number"?t:t.toString()}}uint.UInt=UInt;Object.defineProperty(uint16,"__esModule",{value:!0});uint16.UInt16=void 0;const uint_1$3=uint,buffer_1$9=dist$t;class UInt16 extends uint_1$3.UInt{constructor(t){super(t??UInt16.defaultUInt16.bytes)}static fromParser(t){return new UInt16(t.read(UInt16.width))}static from(t){if(t instanceof UInt16)return t;if(typeof t=="number"){const r=buffer_1$9.Buffer.alloc(UInt16.width);return r.writeUInt16BE(t,0),new UInt16(r)}throw new Error("Can not construct UInt16 with given value")}valueOf(){return this.bytes.readUInt16BE(0)}}uint16.UInt16=UInt16;UInt16.width=16/8;UInt16.defaultUInt16=new UInt16(buffer_1$9.Buffer.alloc(UInt16.width));var uint32={};Object.defineProperty(uint32,"__esModule",{value:!0});uint32.UInt32=void 0;const uint_1$2=uint,buffer_1$8=dist$t;class UInt32 extends uint_1$2.UInt{constructor(t){super(t??UInt32.defaultUInt32.bytes)}static fromParser(t){return new UInt32(t.read(UInt32.width))}static from(t){if(t instanceof UInt32)return t;const r=buffer_1$8.Buffer.alloc(UInt32.width);if(typeof t=="string"){const s=Number.parseInt(t);return r.writeUInt32BE(s,0),new UInt32(r)}if(typeof t=="number")return r.writeUInt32BE(t,0),new UInt32(r);throw new Error("Cannot construct UInt32 from given value")}valueOf(){return this.bytes.readUInt32BE(0)}}uint32.UInt32=UInt32;UInt32.width=32/8;UInt32.defaultUInt32=new UInt32(buffer_1$8.Buffer.alloc(UInt32.width));var uint64={};Object.defineProperty(uint64,"__esModule",{value:!0});uint64.UInt64=void 0;const uint_1$1=uint,bigInt$2=BigIntegerExports,big_integer_1=BigIntegerExports,buffer_1$7=dist$t,HEX_REGEX=/^[a-fA-F0-9]{1,16}$/,mask=bigInt$2(4294967295);class UInt64 extends uint_1$1.UInt{constructor(t){super(t??UInt64.defaultUInt64.bytes)}static fromParser(t){return new UInt64(t.read(UInt64.width))}static from(t){if(t instanceof UInt64)return t;let r=buffer_1$7.Buffer.alloc(UInt64.width);if(typeof t=="number"){if(t<0)throw new Error("value must be an unsigned integer");const s=bigInt$2(t),o=[buffer_1$7.Buffer.alloc(4),buffer_1$7.Buffer.alloc(4)];return o[0].writeUInt32BE(Number(s.shiftRight(32)),0),o[1].writeUInt32BE(Number(s.and(mask)),0),new UInt64(buffer_1$7.Buffer.concat(o))}if(typeof t=="string"){if(!HEX_REGEX.test(t))throw new Error(`${t} is not a valid hex-string`);const s=t.padStart(16,"0");return r=buffer_1$7.Buffer.from(s,"hex"),new UInt64(r)}if((0,big_integer_1.isInstance)(t)){const s=[buffer_1$7.Buffer.alloc(4),buffer_1$7.Buffer.alloc(4)];return s[0].writeUInt32BE(Number(t.shiftRight(bigInt$2(32))),0),s[1].writeUInt32BE(Number(t.and(mask)),0),new UInt64(buffer_1$7.Buffer.concat(s))}throw new Error("Cannot construct UInt64 from given value")}toJSON(){return this.bytes.toString("hex").toUpperCase()}valueOf(){const t=bigInt$2(this.bytes.slice(0,4).readUInt32BE(0)),r=bigInt$2(this.bytes.slice(4).readUInt32BE(0));return t.shiftLeft(bigInt$2(32)).or(r)}toBytes(){return this.bytes}}uint64.UInt64=UInt64;UInt64.width=64/8;UInt64.defaultUInt64=new UInt64(buffer_1$7.Buffer.alloc(UInt64.width));var uint8={};Object.defineProperty(uint8,"__esModule",{value:!0});uint8.UInt8=void 0;const uint_1=uint,buffer_1$6=dist$t;class UInt8 extends uint_1.UInt{constructor(t){super(t??UInt8.defaultUInt8.bytes)}static fromParser(t){return new UInt8(t.read(UInt8.width))}static from(t){if(t instanceof UInt8)return t;if(typeof t=="number"){const r=buffer_1$6.Buffer.alloc(UInt8.width);return r.writeUInt8(t,0),new UInt8(r)}throw new Error("Cannot construct UInt8 from given value")}valueOf(){return this.bytes.readUInt8(0)}}uint8.UInt8=UInt8;UInt8.width=8/8;UInt8.defaultUInt8=new UInt8(buffer_1$6.Buffer.alloc(UInt8.width));var vector256={};Object.defineProperty(vector256,"__esModule",{value:!0});vector256.Vector256=void 0;const serialized_type_1$1=serializedType,hash_256_1$2=hash256,binary_serializer_1$1=binarySerializer;function isStrings(e){return Array.isArray(e)&&(e.length===0||typeof e[0]=="string")}class Vector256 extends serialized_type_1$1.SerializedType{constructor(t){super(t)}static fromParser(t,r){const s=new binary_serializer_1$1.BytesList,n=(r??t.size())/32;for(let a=0;a<n;a++)hash_256_1$2.Hash256.fromParser(t).toBytesSink(s);return new Vector256(s.toBytes())}static from(t){if(t instanceof Vector256)return t;if(isStrings(t)){const r=new binary_serializer_1$1.BytesList;return t.forEach(s=>{hash_256_1$2.Hash256.from(s).toBytesSink(r)}),new Vector256(r.toBytes())}throw new Error("Cannot construct Vector256 from given value")}toJSON(){if(this.bytes.byteLength%32!==0)throw new Error("Invalid bytes for Vector256");const t=[];for(let r=0;r<this.bytes.byteLength;r+=32)t.push(this.bytes.slice(r,r+32).toString("hex").toUpperCase());return t}}vector256.Vector256=Vector256;var xchainBridge={};Object.defineProperty(xchainBridge,"__esModule",{value:!0});xchainBridge.XChainBridge=void 0;const binary_parser_1$1=binaryParser,account_id_1=accountId,serialized_type_1=serializedType,buffer_1$5=dist$t,issue_1=issue;function isXChainBridgeObject(e){const t=Object.keys(e).sort();return t.length===4&&t[0]==="IssuingChainDoor"&&t[1]==="IssuingChainIssue"&&t[2]==="LockingChainDoor"&&t[3]==="LockingChainIssue"}class XChainBridge extends serialized_type_1.SerializedType{constructor(t){super(t??XChainBridge.ZERO_XCHAIN_BRIDGE.bytes)}static from(t){if(t instanceof XChainBridge)return t;if(!isXChainBridgeObject(t))throw new Error("Invalid type to construct an XChainBridge");const r=[];return this.TYPE_ORDER.forEach(s=>{const{name:o,type:n}=s;n===account_id_1.AccountID&&r.push(buffer_1$5.Buffer.from([20]));const a=n.from(t[o]);r.push(a.toBytes())}),new XChainBridge(buffer_1$5.Buffer.concat(r))}static fromParser(t){const r=[];return this.TYPE_ORDER.forEach(s=>{const{type:o}=s;o===account_id_1.AccountID&&(t.skip(1),r.push(buffer_1$5.Buffer.from([20])));const n=o.fromParser(t);r.push(n.toBytes())}),new XChainBridge(buffer_1$5.Buffer.concat(r))}toJSON(){const t=new binary_parser_1$1.BinaryParser(this.toString()),r={};return XChainBridge.TYPE_ORDER.forEach(s=>{const{name:o,type:n}=s;n===account_id_1.AccountID&&t.skip(1);const a=n.fromParser(t).toJSON();r[o]=a}),r}}xchainBridge.XChainBridge=XChainBridge;XChainBridge.ZERO_XCHAIN_BRIDGE=new XChainBridge(buffer_1$5.Buffer.concat([buffer_1$5.Buffer.from([20]),buffer_1$5.Buffer.alloc(40),buffer_1$5.Buffer.from([20]),buffer_1$5.Buffer.alloc(40)]));XChainBridge.TYPE_ORDER=[{name:"LockingChainDoor",type:account_id_1.AccountID},{name:"LockingChainIssue",type:issue_1.Issue},{name:"IssuingChainDoor",type:account_id_1.AccountID},{name:"IssuingChainIssue",type:issue_1.Issue}];(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Vector256=e.UInt64=e.UInt32=e.UInt16=e.UInt8=e.STObject=e.STArray=e.PathSet=e.Hash256=e.Hash160=e.Hash128=e.Currency=e.Blob=e.Amount=e.AccountID=e.coreTypes=void 0;const t=accountId;Object.defineProperty(e,"AccountID",{enumerable:!0,get:function(){return t.AccountID}});const r=amount;Object.defineProperty(e,"Amount",{enumerable:!0,get:function(){return r.Amount}});const s=blob;Object.defineProperty(e,"Blob",{enumerable:!0,get:function(){return s.Blob}});const o=currency;Object.defineProperty(e,"Currency",{enumerable:!0,get:function(){return o.Currency}});const n=hash128;Object.defineProperty(e,"Hash128",{enumerable:!0,get:function(){return n.Hash128}});const a=hash160$1;Object.defineProperty(e,"Hash160",{enumerable:!0,get:function(){return a.Hash160}});const l=hash256;Object.defineProperty(e,"Hash256",{enumerable:!0,get:function(){return l.Hash256}});const p=issue,u=pathSet;Object.defineProperty(e,"PathSet",{enumerable:!0,get:function(){return u.PathSet}});const c=requireStArray();Object.defineProperty(e,"STArray",{enumerable:!0,get:function(){return c.STArray}});const v=requireStObject();Object.defineProperty(e,"STObject",{enumerable:!0,get:function(){return v.STObject}});const w=uint16;Object.defineProperty(e,"UInt16",{enumerable:!0,get:function(){return w.UInt16}});const b=uint32;Object.defineProperty(e,"UInt32",{enumerable:!0,get:function(){return b.UInt32}});const E=uint64;Object.defineProperty(e,"UInt64",{enumerable:!0,get:function(){return E.UInt64}});const I=uint8;Object.defineProperty(e,"UInt8",{enumerable:!0,get:function(){return I.UInt8}});const x=vector256;Object.defineProperty(e,"Vector256",{enumerable:!0,get:function(){return x.Vector256}});const B=xchainBridge,M=enums,q={AccountID:t.AccountID,Amount:r.Amount,Blob:s.Blob,Currency:o.Currency,Hash128:n.Hash128,Hash160:a.Hash160,Hash256:l.Hash256,Issue:p.Issue,PathSet:u.PathSet,STArray:c.STArray,STObject:v.STObject,UInt8:I.UInt8,UInt16:w.UInt16,UInt32:b.UInt32,UInt64:E.UInt64,Vector256:x.Vector256,XChainBridge:B.XChainBridge};e.coreTypes=q,M.DEFAULT_DEFINITIONS.associateTypes(q)})(types$5);var binary={},hashPrefixes={};Object.defineProperty(hashPrefixes,"__esModule",{value:!0});hashPrefixes.HashPrefix=void 0;const buffer_1$4=dist$t;function bytes$1(e){const t=buffer_1$4.Buffer.alloc(4);return t.writeUInt32BE(e,0),t}const HashPrefix={transactionID:bytes$1(1415073280),transaction:bytes$1(1397638144),accountStateEntry:bytes$1(1296846336),innerNode:bytes$1(1296649728),ledgerHeader:bytes$1(1280791040),transactionSig:bytes$1(1398036480),transactionMultiSig:bytes$1(1397576704),validation:bytes$1(1447119872),proposal:bytes$1(1347571712),paymentChannelClaim:bytes$1(1129073920)};hashPrefixes.HashPrefix=HashPrefix;var hashes={};Object.defineProperty(hashes,"__esModule",{value:!0});hashes.transactionID=hashes.sha512Half=hashes.Sha512Half=void 0;const hash_prefixes_1$2=hashPrefixes,createHash=browser$a,hash_256_1$1=hash256,binary_serializer_1=binarySerializer,buffer_1$3=dist$t;class Sha512Half extends binary_serializer_1.BytesList{constructor(){super(...arguments),this.hash=createHash("sha512")}static put(t){return new Sha512Half().put(t)}put(t){return this.hash.update(t),this}finish256(){return buffer_1$3.Buffer.from(this.hash.digest().slice(0,32))}finish(){return new hash_256_1$1.Hash256(this.finish256())}}hashes.Sha512Half=Sha512Half;function sha512Half(...e){const t=new Sha512Half;return e.forEach(r=>t.put(r)),t.finish256()}hashes.sha512Half=sha512Half;function transactionID(e){return new hash_256_1$1.Hash256(sha512Half(hash_prefixes_1$2.HashPrefix.transactionID,e))}hashes.transactionID=transactionID;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.transactionID=e.sha512Half=e.binaryToJSON=e.signingClaimData=e.signingData=e.multiSigningData=e.readJSON=e.serializeObject=e.makeParser=e.BytesList=e.BinarySerializer=e.BinaryParser=void 0;const t=types$5,r=binaryParser;Object.defineProperty(e,"BinaryParser",{enumerable:!0,get:function(){return r.BinaryParser}});const s=hashPrefixes,o=binarySerializer;Object.defineProperty(e,"BinarySerializer",{enumerable:!0,get:function(){return o.BinarySerializer}}),Object.defineProperty(e,"BytesList",{enumerable:!0,get:function(){return o.BytesList}});const n=hashes;Object.defineProperty(e,"sha512Half",{enumerable:!0,get:function(){return n.sha512Half}}),Object.defineProperty(e,"transactionID",{enumerable:!0,get:function(){return n.transactionID}});const a=enums,l=BigIntegerExports,p=(I,x)=>new r.BinaryParser(I,x);e.makeParser=p;const u=(I,x=a.DEFAULT_DEFINITIONS)=>I.readType(t.coreTypes.STObject).toJSON(x);e.readJSON=u;const c=(I,x)=>u(p(I,x),x);e.binaryToJSON=c;function v(I,x={}){const{prefix:B,suffix:M,signingFieldsOnly:q=!1,definitions:U}=x,F=new o.BytesList;B&&F.put(B);const j=q?y=>y.isSigningField:void 0;return t.coreTypes.STObject.from(I,j,U).toBytesSink(F),M&&F.put(M),F.toBytes()}e.serializeObject=v;function w(I,x=s.HashPrefix.transactionSig,B={}){return v(I,{prefix:x,signingFieldsOnly:!0,definitions:B.definitions})}e.signingData=w;function b(I){const x=l(String(I.amount)),B=s.HashPrefix.paymentChannelClaim,M=t.coreTypes.Hash256.from(I.channel).toBytes(),q=t.coreTypes.UInt64.from(x).toBytes(),U=new o.BytesList;return U.put(B),U.put(M),U.put(q),U.toBytes()}e.signingClaimData=b;function E(I,x,B={definitions:a.DEFAULT_DEFINITIONS}){const M=s.HashPrefix.transactionMultiSig,q=t.coreTypes.AccountID.from(x).toBytes();return v(I,{prefix:M,suffix:q,signingFieldsOnly:!0,definitions:B.definitions})}e.multiSigningData=E})(binary);var shamap={};Object.defineProperty(shamap,"__esModule",{value:!0});shamap.ShaMapLeaf=shamap.ShaMapNode=shamap.ShaMap=void 0;const assert_1=requireAssert(),types_1$b=types$5,hash_prefixes_1$1=hashPrefixes,hashes_1$1=hashes,buffer_1$2=dist$t;class ShaMapNode{}shamap.ShaMapNode=ShaMapNode;class ShaMapLeaf extends ShaMapNode{constructor(t,r){super(),this.index=t,this.item=r}isLeaf(){return!0}isInner(){return!1}hashPrefix(){return this.item===void 0?buffer_1$2.Buffer.alloc(0):this.item.hashPrefix()}hash(){const t=hashes_1$1.Sha512Half.put(this.hashPrefix());return this.toBytesSink(t),t.finish()}toBytesSink(t){this.item!==void 0&&this.item.toBytesSink(t),this.index.toBytesSink(t)}}shamap.ShaMapLeaf=ShaMapLeaf;class ShaMapInner extends ShaMapNode{constructor(t=0){super(),this.depth=t,this.slotBits=0,this.branches=Array(16)}isInner(){return!0}isLeaf(){return!1}hashPrefix(){return hash_prefixes_1$1.HashPrefix.innerNode}setBranch(t,r){this.slotBits=this.slotBits|1<<t,this.branches[t]=r}empty(){return this.slotBits===0}hash(){if(this.empty())return types_1$b.coreTypes.Hash256.ZERO_256;const t=hashes_1$1.Sha512Half.put(this.hashPrefix());return this.toBytesSink(t),t.finish()}toBytesSink(t){for(let r=0;r<this.branches.length;r++){const s=this.branches[r];(s?s.hash():types_1$b.coreTypes.Hash256.ZERO_256).toBytesSink(t)}}addItem(t,r,s){if(assert_1.strict.ok(t!==void 0),t!==void 0){const o=t.nibblet(this.depth),n=this.branches[o];if(n===void 0)this.setBranch(o,s||new ShaMapLeaf(t,r));else if(n instanceof ShaMapLeaf){const a=new ShaMapInner(this.depth+1);a.addItem(n.index,void 0,n),a.addItem(t,r,s),this.setBranch(o,a)}else if(n instanceof ShaMapInner)n.addItem(t,r,s);else throw new Error("invalid ShaMap.addItem call")}}}class ShaMap extends ShaMapInner{}shamap.ShaMap=ShaMap;var ledgerHashes={},__createBinding=commonjsGlobal&&commonjsGlobal.__createBinding||(Object.create?function(e,t,r,s){s===void 0&&(s=r);var o=Object.getOwnPropertyDescriptor(t,r);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,o)}:function(e,t,r,s){s===void 0&&(s=r),e[s]=t[r]}),__setModuleDefault=commonjsGlobal&&commonjsGlobal.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=commonjsGlobal&&commonjsGlobal.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)r!=="default"&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t};Object.defineProperty(ledgerHashes,"__esModule",{value:!0});ledgerHashes.decodeLedgerData=ledgerHashes.ledgerHash=ledgerHashes.transactionTreeHash=ledgerHashes.accountStateHash=void 0;const assert$1=__importStar(requireAssert()),shamap_1=shamap,hash_prefixes_1=hashPrefixes,hashes_1=hashes,binary_1=binary,hash_256_1=hash256,st_object_1=requireStObject(),uint_64_1=uint64,uint_32_1=uint32,uint_8_1=uint8,binary_parser_1=binaryParser,bigInt$1=BigIntegerExports;function computeHash(e,t){const r=new shamap_1.ShaMap;return t.forEach(s=>r.addItem(...e(s))),r.hash()}function transactionItemizer(e){return assert$1.ok(e.hash),[hash_256_1.Hash256.from(e.hash),{hashPrefix(){return hash_prefixes_1.HashPrefix.transaction},toBytesSink(s){const o=new binary_1.BinarySerializer(s);o.writeLengthEncoded(st_object_1.STObject.from(e)),o.writeLengthEncoded(st_object_1.STObject.from(e.metaData))}},void 0]}function entryItemizer(e){const t=hash_256_1.Hash256.from(e.index),r=(0,binary_1.serializeObject)(e);return[t,{hashPrefix(){return hash_prefixes_1.HashPrefix.accountStateEntry},toBytesSink(o){o.put(r)}},void 0]}function transactionTreeHash(e){return computeHash(transactionItemizer,e)}ledgerHashes.transactionTreeHash=transactionTreeHash;function accountStateHash(e){return computeHash(entryItemizer,e)}ledgerHashes.accountStateHash=accountStateHash;function ledgerHash(e){const t=new hashes_1.Sha512Half;return t.put(hash_prefixes_1.HashPrefix.ledgerHeader),assert$1.ok(e.parent_close_time!==void 0),assert$1.ok(e.close_flags!==void 0),uint_32_1.UInt32.from(e.ledger_index).toBytesSink(t),uint_64_1.UInt64.from(bigInt$1(String(e.total_coins))).toBytesSink(t),hash_256_1.Hash256.from(e.parent_hash).toBytesSink(t),hash_256_1.Hash256.from(e.transaction_hash).toBytesSink(t),hash_256_1.Hash256.from(e.account_hash).toBytesSink(t),uint_32_1.UInt32.from(e.parent_close_time).toBytesSink(t),uint_32_1.UInt32.from(e.close_time).toBytesSink(t),uint_8_1.UInt8.from(e.close_time_resolution).toBytesSink(t),uint_8_1.UInt8.from(e.close_flags).toBytesSink(t),t.finish()}ledgerHashes.ledgerHash=ledgerHash;function decodeLedgerData(e,t){assert$1.ok(typeof e=="string","binary must be a hex string");const r=new binary_parser_1.BinaryParser(e,t);return{ledger_index:r.readUInt32(),total_coins:r.readType(uint_64_1.UInt64).valueOf().toString(),parent_hash:r.readType(hash_256_1.Hash256).toHex(),transaction_hash:r.readType(hash_256_1.Hash256).toHex(),account_hash:r.readType(hash_256_1.Hash256).toHex(),parent_close_time:r.readUInt32(),close_time:r.readUInt32(),close_time_resolution:r.readUInt8(),close_flags:r.readUInt8()}}ledgerHashes.decodeLedgerData=decodeLedgerData;var quality$1={};Object.defineProperty(quality$1,"__esModule",{value:!0});quality$1.quality=void 0;const types_1$a=types$5,decimal_js_1=decimalExports,bigInt=BigIntegerExports,buffer_1$1=dist$t;class quality{static encode(t){const r=new decimal_js_1.Decimal(t),s=r.e-15,o=r.times(`1e${-s}`).abs().toString(),n=types_1$a.coreTypes.UInt64.from(bigInt(o)).toBytes();return n[0]=s+100,n}static decode(t){const r=buffer_1$1.Buffer.from(t,"hex").slice(-8),s=r[0]-100;return new decimal_js_1.Decimal(`0x${r.slice(1).toString("hex")}`).times(`1e${s}`)}}quality$1.quality=quality;(function(e){var t=commonjsGlobal&&commonjsGlobal.__createBinding||(Object.create?function(w,b,E,I){I===void 0&&(I=E);var x=Object.getOwnPropertyDescriptor(b,E);(!x||("get"in x?!b.__esModule:x.writable||x.configurable))&&(x={enumerable:!0,get:function(){return b[E]}}),Object.defineProperty(w,I,x)}:function(w,b,E,I){I===void 0&&(I=E),w[I]=b[E]}),r=commonjsGlobal&&commonjsGlobal.__setModuleDefault||(Object.create?function(w,b){Object.defineProperty(w,"default",{enumerable:!0,value:b})}:function(w,b){w.default=b}),s=commonjsGlobal&&commonjsGlobal.__importStar||function(w){if(w&&w.__esModule)return w;var b={};if(w!=null)for(var E in w)E!=="default"&&Object.prototype.hasOwnProperty.call(w,E)&&t(b,w,E);return r(b,w),b};Object.defineProperty(e,"__esModule",{value:!0}),e.types=e.ShaMap=e.HashPrefix=e.quality=e.TransactionResult=e.Type=e.LedgerEntryType=e.TransactionType=e.Field=e.DEFAULT_DEFINITIONS=e.ledgerHashes=e.binary=e.hashes=void 0;const o=enums;Object.defineProperty(e,"DEFAULT_DEFINITIONS",{enumerable:!0,get:function(){return o.DEFAULT_DEFINITIONS}}),Object.defineProperty(e,"Field",{enumerable:!0,get:function(){return o.Field}}),Object.defineProperty(e,"TransactionType",{enumerable:!0,get:function(){return o.TransactionType}}),Object.defineProperty(e,"LedgerEntryType",{enumerable:!0,get:function(){return o.LedgerEntryType}}),Object.defineProperty(e,"Type",{enumerable:!0,get:function(){return o.Type}}),Object.defineProperty(e,"TransactionResult",{enumerable:!0,get:function(){return o.TransactionResult}});const n=s(types$5);e.types=n;const a=s(binary);e.binary=a;const l=shamap;Object.defineProperty(e,"ShaMap",{enumerable:!0,get:function(){return l.ShaMap}});const p=s(ledgerHashes);e.ledgerHashes=p;const u=s(hashes);e.hashes=u;const c=quality$1;Object.defineProperty(e,"quality",{enumerable:!0,get:function(){return c.quality}});const v=hashPrefixes;Object.defineProperty(e,"HashPrefix",{enumerable:!0,get:function(){return v.HashPrefix}})})(coretypes);var xrplDefinitions={};Object.defineProperty(xrplDefinitions,"__esModule",{value:!0});xrplDefinitions.XrplDefinitions=void 0;const xrpl_definitions_base_1=xrplDefinitionsBase,types_1$9=types$5;class XrplDefinitions extends xrpl_definitions_base_1.XrplDefinitionsBase{constructor(t,r){const s=Object.assign({},types_1$9.coreTypes,r);super(t,s)}}xrplDefinitions.XrplDefinitions=XrplDefinitions;(function(e){var t=commonjsGlobal&&commonjsGlobal.__createBinding||(Object.create?function(j,y,T,D){D===void 0&&(D=T);var L=Object.getOwnPropertyDescriptor(y,T);(!L||("get"in L?!y.__esModule:L.writable||L.configurable))&&(L={enumerable:!0,get:function(){return y[T]}}),Object.defineProperty(j,D,L)}:function(j,y,T,D){D===void 0&&(D=T),j[D]=y[T]}),r=commonjsGlobal&&commonjsGlobal.__setModuleDefault||(Object.create?function(j,y){Object.defineProperty(j,"default",{enumerable:!0,value:y})}:function(j,y){j.default=y}),s=commonjsGlobal&&commonjsGlobal.__importStar||function(j){if(j&&j.__esModule)return j;var y={};if(j!=null)for(var T in j)T!=="default"&&Object.prototype.hasOwnProperty.call(j,T)&&t(y,j,T);return r(y,j),y};Object.defineProperty(e,"__esModule",{value:!0}),e.coreTypes=e.DEFAULT_DEFINITIONS=e.XrplDefinitionsBase=e.XrplDefinitions=e.TRANSACTION_TYPES=e.decodeLedgerData=e.decodeQuality=e.encodeQuality=e.encodeForMultisigning=e.encodeForSigningClaim=e.encodeForSigning=e.encode=e.decode=void 0;const o=s(requireAssert()),n=coretypes,a=ledgerHashes;Object.defineProperty(e,"decodeLedgerData",{enumerable:!0,get:function(){return a.decodeLedgerData}});const l=enums;Object.defineProperty(e,"XrplDefinitionsBase",{enumerable:!0,get:function(){return l.XrplDefinitionsBase}}),Object.defineProperty(e,"TRANSACTION_TYPES",{enumerable:!0,get:function(){return l.TRANSACTION_TYPES}}),Object.defineProperty(e,"DEFAULT_DEFINITIONS",{enumerable:!0,get:function(){return l.DEFAULT_DEFINITIONS}});const p=xrplDefinitions;Object.defineProperty(e,"XrplDefinitions",{enumerable:!0,get:function(){return p.XrplDefinitions}});const u=types$5;Object.defineProperty(e,"coreTypes",{enumerable:!0,get:function(){return u.coreTypes}});const{signingData:c,signingClaimData:v,multiSigningData:w,binaryToJSON:b,serializeObject:E}=n.binary;function I(j,y){return o.ok(typeof j=="string","binary must be a hex string"),b(j,y)}e.decode=I;function x(j,y){return o.ok(typeof j=="object"),E(j,{definitions:y}).toString("hex").toUpperCase()}e.encode=x;function B(j,y){return o.ok(typeof j=="object"),c(j,n.HashPrefix.transactionSig,{definitions:y}).toString("hex").toUpperCase()}e.encodeForSigning=B;function M(j){return o.ok(typeof j=="object"),v(j).toString("hex").toUpperCase()}e.encodeForSigningClaim=M;function q(j,y,T){return o.ok(typeof j=="object"),o.equal(j.SigningPubKey,""),w(j,y,T?{definitions:T}:void 0).toString("hex").toUpperCase()}e.encodeForMultisigning=q;function U(j){return o.ok(typeof j=="string"),n.quality.encode(j).toString("hex").toUpperCase()}e.encodeQuality=U;function F(j){return o.ok(typeof j=="string"),n.quality.decode(j).toString()}e.decodeQuality=F})(dist$2);Object.defineProperty(xrp,"__esModule",{value:!0});xrp.KeystoneXrpSDK=void 0;const bc_ur_1=dist$s,ripple_binary_codec_1=dist$2;class KeystoneXrpSDK{parseAccount(t){const r=t.decodeCBOR().toString();return JSON.parse(r)}parseSignature(t){if(t.type!=="bytes")throw new Error("type not match");try{const r=t.decodeCBOR().toString("hex");return(0,ripple_binary_codec_1.decode)(r).TxnSignature}catch{throw new Error("signature is invalid")}}generateSignRequest(t){const r=JSON.stringify(t);return bc_ur_1.UR.fromBuffer(Buffer$e.from(r))}}xrp.KeystoneXrpSDK=KeystoneXrpSDK;(function(e){var t=commonjsGlobal&&commonjsGlobal.__createBinding||(Object.create?function(s,o,n,a){a===void 0&&(a=n);var l=Object.getOwnPropertyDescriptor(o,n);(!l||("get"in l?!o.__esModule:l.writable||l.configurable))&&(l={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(s,a,l)}:function(s,o,n,a){a===void 0&&(a=n),s[a]=o[n]}),r=commonjsGlobal&&commonjsGlobal.__exportStar||function(s,o){for(var n in s)n!=="default"&&!Object.prototype.hasOwnProperty.call(o,n)&&t(o,s,n)};Object.defineProperty(e,"__esModule",{value:!0}),r(xrp,e)})(xrp$1);var __awaiter=commonjsGlobal&&commonjsGlobal.__awaiter||function(e,t,r,s){function o(n){return n instanceof r?n:new r(function(a){a(n)})}return new(r||(r=Promise))(function(n,a){function l(c){try{u(s.next(c))}catch(v){a(v)}}function p(c){try{u(s.throw(c))}catch(v){a(v)}}function u(c){c.done?n(c.value):o(c.value).then(l,p)}u((s=s.apply(e,t||[])).next())})};Object.defineProperty(sdk,"__esModule",{value:!0});sdk.KeystoneSDK=void 0;const chains_1=chains,wallet_1=wallet,xrp_1=xrp$1,CONFIG_URL="https://keyst.one/statics/sdk/config.json";class KeystoneSDK{constructor(t){this.parseMultiAccounts=wallet_1.parseMultiAccounts,this.parseTonAccount=wallet_1.parseTonAccount,this.parseHDKey=wallet_1.parseHDKey,this.parseAccount=wallet_1.parseAccount,this.generateKeyDerivationCall=wallet_1.generateKeyDerivationCall,this.config=t}static create(t){return __awaiter(this,void 0,void 0,function*(){try{const s=yield(yield fetch(CONFIG_URL)).json();return new KeystoneSDK(Object.assign(Object.assign({},t),s))}catch(r){return console.error("fetch config error",r),new KeystoneSDK(t)}})}get btc(){return this._btc===void 0&&(this._btc=new chains_1.KeystoneBitcoinSDK),this._btc}get eth(){return this._eth===void 0&&(this._eth=new chains_1.KeystoneEthereumSDK(this.config)),this._eth}get sol(){return this._sol===void 0&&(this._sol=new chains_1.KeystoneSolanaSDK),this._sol}get stellar(){return this._stellar===void 0&&(this._stellar=new chains_1.KeystoneStellarSDK),this._stellar}get cosmos(){return this._cosmos===void 0&&(this._cosmos=new chains_1.KeystoneCosmosSDK(this.config)),this._cosmos}get evm(){return this._evm===void 0&&(this._evm=new chains_1.KeystoneEvmSDK(this.config)),this._evm}get tron(){return this._tron===void 0&&(this._tron=new chains_1.KeystoneTronSDK),this._tron}get ltc(){return this._ltc===void 0&&(this._ltc=new chains_1.KeystoneLitecoinSDK),this._ltc}get bch(){return this._bch===void 0&&(this._bch=new chains_1.KeystoneBitcoinCashSDK),this._bch}get dash(){return this._dash===void 0&&(this._dash=new chains_1.KeystoneDashSDK),this._dash}get aptos(){return this._aptos===void 0&&(this._aptos=new chains_1.KeystoneAptosSDK),this._aptos}get near(){return this._near===void 0&&(this._near=new chains_1.KeystoneNearSDK),this._near}get arweave(){return this._arweave===void 0&&(this._arweave=new chains_1.KeystoneArweaveSDK),this._arweave}get sui(){return this._sui===void 0&&(this._sui=new chains_1.KeystoneSuiSDK(this.config)),this._sui}get cardano(){return this._cardano===void 0&&(this._cardano=new chains_1.KeystoneCardanoSDK),this._cardano}get xrp(){return this._xrp===void 0&&(this._xrp=new xrp_1.KeystoneXrpSDK),this._xrp}get ton(){return this._ton===void 0&&(this._ton=new chains_1.KeystoneTonSDK(this.config)),this._ton}}KeystoneSDK.parseMultiAccounts=wallet_1.parseMultiAccounts;KeystoneSDK.parseHDKey=wallet_1.parseHDKey;KeystoneSDK.generateKeyDerivationCall=wallet_1.generateKeyDerivationCall;sdk.KeystoneSDK=KeystoneSDK;(function(e){var t=commonjsGlobal&&commonjsGlobal.__createBinding||(Object.create?function(u,c,v,w){w===void 0&&(w=v);var b=Object.getOwnPropertyDescriptor(c,v);(!b||("get"in b?!c.__esModule:b.writable||b.configurable))&&(b={enumerable:!0,get:function(){return c[v]}}),Object.defineProperty(u,w,b)}:function(u,c,v,w){w===void 0&&(w=v),u[w]=c[v]}),r=commonjsGlobal&&commonjsGlobal.__setModuleDefault||(Object.create?function(u,c){Object.defineProperty(u,"default",{enumerable:!0,value:c})}:function(u,c){u.default=c}),s=commonjsGlobal&&commonjsGlobal.__importStar||function(u){if(u&&u.__esModule)return u;var c={};if(u!=null)for(var v in u)v!=="default"&&Object.prototype.hasOwnProperty.call(u,v)&&t(c,u,v);return r(c,u),c},o=commonjsGlobal&&commonjsGlobal.__exportStar||function(u,c){for(var v in u)v!=="default"&&!Object.prototype.hasOwnProperty.call(c,v)&&t(c,u,v)};Object.defineProperty(e,"__esModule",{value:!0}),e.utils=e.KeystoneSDK=e.QRHardwareCallVersion=e.DerivationAlgorithm=e.Curve=void 0;const n=s(utils$o);e.utils=n;const a=sdk;Object.defineProperty(e,"KeystoneSDK",{enumerable:!0,get:function(){return a.KeystoneSDK}}),o(dist$s,e),o(types$6,e),o(chains,e);var l=hardwareCall;Object.defineProperty(e,"Curve",{enumerable:!0,get:function(){return l.Curve}}),Object.defineProperty(e,"DerivationAlgorithm",{enumerable:!0,get:function(){return l.DerivationAlgorithm}});var p=requireDist$c();Object.defineProperty(e,"QRHardwareCallVersion",{enumerable:!0,get:function(){return p.QRHardwareCallVersion}}),e.default=a.KeystoneSDK})(dist$v);function number(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function isBytes$1(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function bytes(e,...t){if(!isBytes$1(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 hash(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");number(e.outputLen),number(e.blockLen)}function exists(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 output(e,t){bytes(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}const createView=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),rotr=(e,t)=>e<<32-t|e>>>t,rotl=(e,t)=>e<<t|e>>>32-t>>>0;new Uint8Array(new Uint32Array([287454020]).buffer)[0];const hexes=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function bytesToHex(e){bytes(e);let t="";for(let r=0;r<e.length;r++)t+=hexes[e[r]];return t}const asciis={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function asciiToBase16(e){if(e>=asciis._0&&e<=asciis._9)return e-asciis._0;if(e>=asciis._A&&e<=asciis._F)return e-(asciis._A-10);if(e>=asciis._a&&e<=asciis._f)return e-(asciis._a-10)}function hexToBytes(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length,r=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const s=new Uint8Array(r);for(let o=0,n=0;o<r;o++,n+=2){const a=asciiToBase16(e.charCodeAt(n)),l=asciiToBase16(e.charCodeAt(n+1));if(a===void 0||l===void 0){const p=e[n]+e[n+1];throw new Error('hex string expected, got non-hex character "'+p+'" at index '+n)}s[o]=a*16+l}return s}function utf8ToBytes(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function toBytes(e){return typeof e=="string"&&(e=utf8ToBytes(e)),bytes(e),e}function concatBytes(...e){let t=0;for(let s=0;s<e.length;s++){const o=e[s];bytes(o),t+=o.length}const r=new Uint8Array(t);for(let s=0,o=0;s<e.length;s++){const n=e[s];r.set(n,o),o+=n.length}return r}class Hash{clone(){return this._cloneInto()}}function wrapConstructor(e){const t=s=>e().update(toBytes(s)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}class HMAC extends Hash{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,hash(t);const s=toBytes(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const o=this.blockLen,n=new Uint8Array(o);n.set(s.length>o?t.create().update(s).digest():s);for(let a=0;a<n.length;a++)n[a]^=54;this.iHash.update(n),this.oHash=t.create();for(let a=0;a<n.length;a++)n[a]^=106;this.oHash.update(n),n.fill(0)}update(t){return exists(this),this.iHash.update(t),this}digestInto(t){exists(this),bytes(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:r,iHash:s,finished:o,destroyed:n,blockLen:a,outputLen:l}=this;return t=t,t.finished=o,t.destroyed=n,t.blockLen=a,t.outputLen=l,t.oHash=r._cloneInto(t.oHash),t.iHash=s._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const hmac=(e,t,r)=>new HMAC(e,t).update(r).digest();hmac.create=(e,t)=>new HMAC(e,t);function setBigUint64(e,t,r,s){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,s);const o=BigInt(32),n=BigInt(4294967295),a=Number(r>>o&n),l=Number(r&n),p=s?4:0,u=s?0:4;e.setUint32(t+p,a,s),e.setUint32(t+u,l,s)}const Chi=(e,t,r)=>e&t^~e&r,Maj=(e,t,r)=>e&t^e&r^t&r;class HashMD extends Hash{constructor(t,r,s,o){super(),this.blockLen=t,this.outputLen=r,this.padOffset=s,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=createView(this.buffer)}update(t){exists(this);const{view:r,buffer:s,blockLen:o}=this;t=toBytes(t);const n=t.length;for(let a=0;a<n;){const l=Math.min(o-this.pos,n-a);if(l===o){const p=createView(t);for(;o<=n-a;a+=o)this.process(p,a);continue}s.set(t.subarray(a,a+l),this.pos),this.pos+=l,a+=l,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){exists(this),output(t,this),this.finished=!0;const{buffer:r,view:s,blockLen:o,isLE:n}=this;let{pos:a}=this;r[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>o-a&&(this.process(s,0),a=0);for(let v=a;v<o;v++)r[v]=0;setBigUint64(s,o-8,BigInt(this.length*8),n),this.process(s,0);const l=createView(t),p=this.outputLen;if(p%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=p/4,c=this.get();if(u>c.length)throw new Error("_sha2: outputLen bigger than state");for(let v=0;v<u;v++)l.setUint32(4*v,c[v],n)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const s=t.slice(0,r);return this.destroy(),s}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:s,length:o,finished:n,destroyed:a,pos:l}=this;return t.length=o,t.pos=l,t.finished=n,t.destroyed=a,o%r&&t.buffer.set(s),t}}const Rho$1=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Id$1=new Uint8Array(new Array(16).fill(0).map((e,t)=>t)),Pi$1=Id$1.map(e=>(9*e+5)%16);let idxL$1=[Id$1],idxR$1=[Pi$1];for(let e=0;e<4;e++)for(let t of[idxL$1,idxR$1])t.push(t[e].map(r=>Rho$1[r]));const shifts$1=[[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)),shiftsL$1=idxL$1.map((e,t)=>e.map(r=>shifts$1[t][r])),shiftsR$1=idxR$1.map((e,t)=>e.map(r=>shifts$1[t][r])),Kl$1=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),Kr$1=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function f$1(e,t,r,s){return e===0?t^r^s:e===1?t&r|~t&s:e===2?(t|~r)^s:e===3?t&s|r&~s:t^(r|~s)}const R_BUF$1=new Uint32Array(16);let RIPEMD160$1=class extends HashMD{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:s,h3:o,h4:n}=this;return[t,r,s,o,n]}set(t,r,s,o,n){this.h0=t|0,this.h1=r|0,this.h2=s|0,this.h3=o|0,this.h4=n|0}process(t,r){for(let b=0;b<16;b++,r+=4)R_BUF$1[b]=t.getUint32(r,!0);let s=this.h0|0,o=s,n=this.h1|0,a=n,l=this.h2|0,p=l,u=this.h3|0,c=u,v=this.h4|0,w=v;for(let b=0;b<5;b++){const E=4-b,I=Kl$1[b],x=Kr$1[b],B=idxL$1[b],M=idxR$1[b],q=shiftsL$1[b],U=shiftsR$1[b];for(let F=0;F<16;F++){const j=rotl(s+f$1(b,n,l,u)+R_BUF$1[B[F]]+I,q[F])+v|0;s=v,v=u,u=rotl(l,10)|0,l=n,n=j}for(let F=0;F<16;F++){const j=rotl(o+f$1(E,a,p,c)+R_BUF$1[M[F]]+x,U[F])+w|0;o=w,w=c,c=rotl(p,10)|0,p=a,a=j}}this.set(this.h1+l+c|0,this.h2+u+w|0,this.h3+v+o|0,this.h4+s+a|0,this.h0+n+p|0)}roundClean(){R_BUF$1.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}};const ripemd160$1=wrapConstructor(()=>new RIPEMD160$1),SHA256_K=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]),SHA256_IV=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),SHA256_W=new Uint32Array(64);class SHA256 extends HashMD{constructor(){super(64,32,8,!1),this.A=SHA256_IV[0]|0,this.B=SHA256_IV[1]|0,this.C=SHA256_IV[2]|0,this.D=SHA256_IV[3]|0,this.E=SHA256_IV[4]|0,this.F=SHA256_IV[5]|0,this.G=SHA256_IV[6]|0,this.H=SHA256_IV[7]|0}get(){const{A:t,B:r,C:s,D:o,E:n,F:a,G:l,H:p}=this;return[t,r,s,o,n,a,l,p]}set(t,r,s,o,n,a,l,p){this.A=t|0,this.B=r|0,this.C=s|0,this.D=o|0,this.E=n|0,this.F=a|0,this.G=l|0,this.H=p|0}process(t,r){for(let v=0;v<16;v++,r+=4)SHA256_W[v]=t.getUint32(r,!1);for(let v=16;v<64;v++){const w=SHA256_W[v-15],b=SHA256_W[v-2],E=rotr(w,7)^rotr(w,18)^w>>>3,I=rotr(b,17)^rotr(b,19)^b>>>10;SHA256_W[v]=I+SHA256_W[v-7]+E+SHA256_W[v-16]|0}let{A:s,B:o,C:n,D:a,E:l,F:p,G:u,H:c}=this;for(let v=0;v<64;v++){const w=rotr(l,6)^rotr(l,11)^rotr(l,25),b=c+w+Chi(l,p,u)+SHA256_K[v]+SHA256_W[v]|0,I=(rotr(s,2)^rotr(s,13)^rotr(s,22))+Maj(s,o,n)|0;c=u,u=p,p=l,l=a+b|0,a=n,n=o,o=s,s=b+I|0}s=s+this.A|0,o=o+this.B|0,n=n+this.C|0,a=a+this.D|0,l=l+this.E|0,p=p+this.F|0,u=u+this.G|0,c=c+this.H|0,this.set(s,o,n,a,l,p,u,c)}roundClean(){SHA256_W.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const sha256=wrapConstructor(()=>new SHA256),U32_MASK64=BigInt(2**32-1),_32n=BigInt(32);function fromBig(e,t=!1){return t?{h:Number(e&U32_MASK64),l:Number(e>>_32n&U32_MASK64)}:{h:Number(e>>_32n&U32_MASK64)|0,l:Number(e&U32_MASK64)|0}}function split(e,t=!1){let r=new Uint32Array(e.length),s=new Uint32Array(e.length);for(let o=0;o<e.length;o++){const{h:n,l:a}=fromBig(e[o],t);[r[o],s[o]]=[n,a]}return[r,s]}const toBig=(e,t)=>BigInt(e>>>0)<<_32n|BigInt(t>>>0),shrSH=(e,t,r)=>e>>>r,shrSL=(e,t,r)=>e<<32-r|t>>>r,rotrSH=(e,t,r)=>e>>>r|t<<32-r,rotrSL=(e,t,r)=>e<<32-r|t>>>r,rotrBH=(e,t,r)=>e<<64-r|t>>>r-32,rotrBL=(e,t,r)=>e>>>r-32|t<<64-r,rotr32H=(e,t)=>t,rotr32L=(e,t)=>e,rotlSH=(e,t,r)=>e<<r|t>>>32-r,rotlSL=(e,t,r)=>t<<r|e>>>32-r,rotlBH=(e,t,r)=>t<<r-32|e>>>64-r,rotlBL=(e,t,r)=>e<<r-32|t>>>64-r;function add(e,t,r,s){const o=(t>>>0)+(s>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}const add3L=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),add3H=(e,t,r,s)=>t+r+s+(e/2**32|0)|0,add4L=(e,t,r,s)=>(e>>>0)+(t>>>0)+(r>>>0)+(s>>>0),add4H=(e,t,r,s,o)=>t+r+s+o+(e/2**32|0)|0,add5L=(e,t,r,s,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(s>>>0)+(o>>>0),add5H=(e,t,r,s,o,n)=>t+r+s+o+n+(e/2**32|0)|0,u64={fromBig,split,toBig,shrSH,shrSL,rotrSH,rotrSL,rotrBH,rotrBL,rotr32H,rotr32L,rotlSH,rotlSL,rotlBH,rotlBL,add,add3L,add3H,add4L,add4H,add5H,add5L},[SHA512_Kh,SHA512_Kl]=u64.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),SHA512_W_H=new Uint32Array(80),SHA512_W_L=new Uint32Array(80);class SHA512 extends HashMD{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:t,Al:r,Bh:s,Bl:o,Ch:n,Cl:a,Dh:l,Dl:p,Eh:u,El:c,Fh:v,Fl:w,Gh:b,Gl:E,Hh:I,Hl:x}=this;return[t,r,s,o,n,a,l,p,u,c,v,w,b,E,I,x]}set(t,r,s,o,n,a,l,p,u,c,v,w,b,E,I,x){this.Ah=t|0,this.Al=r|0,this.Bh=s|0,this.Bl=o|0,this.Ch=n|0,this.Cl=a|0,this.Dh=l|0,this.Dl=p|0,this.Eh=u|0,this.El=c|0,this.Fh=v|0,this.Fl=w|0,this.Gh=b|0,this.Gl=E|0,this.Hh=I|0,this.Hl=x|0}process(t,r){for(let q=0;q<16;q++,r+=4)SHA512_W_H[q]=t.getUint32(r),SHA512_W_L[q]=t.getUint32(r+=4);for(let q=16;q<80;q++){const U=SHA512_W_H[q-15]|0,F=SHA512_W_L[q-15]|0,j=u64.rotrSH(U,F,1)^u64.rotrSH(U,F,8)^u64.shrSH(U,F,7),y=u64.rotrSL(U,F,1)^u64.rotrSL(U,F,8)^u64.shrSL(U,F,7),T=SHA512_W_H[q-2]|0,D=SHA512_W_L[q-2]|0,L=u64.rotrSH(T,D,19)^u64.rotrBH(T,D,61)^u64.shrSH(T,D,6),C=u64.rotrSL(T,D,19)^u64.rotrBL(T,D,61)^u64.shrSL(T,D,6),d=u64.add4L(y,C,SHA512_W_L[q-7],SHA512_W_L[q-16]),_=u64.add4H(d,j,L,SHA512_W_H[q-7],SHA512_W_H[q-16]);SHA512_W_H[q]=_|0,SHA512_W_L[q]=d|0}let{Ah:s,Al:o,Bh:n,Bl:a,Ch:l,Cl:p,Dh:u,Dl:c,Eh:v,El:w,Fh:b,Fl:E,Gh:I,Gl:x,Hh:B,Hl:M}=this;for(let q=0;q<80;q++){const U=u64.rotrSH(v,w,14)^u64.rotrSH(v,w,18)^u64.rotrBH(v,w,41),F=u64.rotrSL(v,w,14)^u64.rotrSL(v,w,18)^u64.rotrBL(v,w,41),j=v&b^~v&I,y=w&E^~w&x,T=u64.add5L(M,F,y,SHA512_Kl[q],SHA512_W_L[q]),D=u64.add5H(T,B,U,j,SHA512_Kh[q],SHA512_W_H[q]),L=T|0,C=u64.rotrSH(s,o,28)^u64.rotrBH(s,o,34)^u64.rotrBH(s,o,39),d=u64.rotrSL(s,o,28)^u64.rotrBL(s,o,34)^u64.rotrBL(s,o,39),_=s&n^s&l^n&l,$=o&a^o&p^a&p;B=I|0,M=x|0,I=b|0,x=E|0,b=v|0,E=w|0,{h:v,l:w}=u64.add(u|0,c|0,D|0,L|0),u=l|0,c=p|0,l=n|0,p=a|0,n=s|0,a=o|0;const S=u64.add3L(L,d,$);s=u64.add3H(S,D,C,_),o=S|0}({h:s,l:o}=u64.add(this.Ah|0,this.Al|0,s|0,o|0)),{h:n,l:a}=u64.add(this.Bh|0,this.Bl|0,n|0,a|0),{h:l,l:p}=u64.add(this.Ch|0,this.Cl|0,l|0,p|0),{h:u,l:c}=u64.add(this.Dh|0,this.Dl|0,u|0,c|0),{h:v,l:w}=u64.add(this.Eh|0,this.El|0,v|0,w|0),{h:b,l:E}=u64.add(this.Fh|0,this.Fl|0,b|0,E|0),{h:I,l:x}=u64.add(this.Gh|0,this.Gl|0,I|0,x|0),{h:B,l:M}=u64.add(this.Hh|0,this.Hl|0,B|0,M|0),this.set(s,o,n,a,l,p,u,c,v,w,b,E,I,x,B,M)}roundClean(){SHA512_W_H.fill(0),SHA512_W_L.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const sha512=wrapConstructor(()=>new SHA512);function isBytes(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function chain(...e){const t=n=>n,r=(n,a)=>l=>n(a(l)),s=e.map(n=>n.encode).reduceRight(r,t),o=e.map(n=>n.decode).reduce(r,t);return{encode:s,decode:o}}function alphabet(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return t.map(r=>{if(r<0||r>=e.length)throw new Error(`Digit index outside alphabet: ${r} (alphabet: ${e.length})`);return e[r]})},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("alphabet.decode input should be array of strings");return t.map(r=>{if(typeof r!="string")throw new Error(`alphabet.decode: not string element=${r}`);const s=e.indexOf(r);if(s===-1)throw new Error(`Unknown letter: "${r}". Allowed: ${e}`);return s})}}}function join(e=""){if(typeof e!="string")throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("join.encode input should be array of strings");for(let r of t)if(typeof r!="string")throw new Error(`join.encode: non-string input=${r}`);return t.join(e)},decode:t=>{if(typeof t!="string")throw new Error("join.decode input should be string");return t.split(e)}}}function convertRadix(e,t,r){if(t<2)throw new Error(`convertRadix: wrong from=${t}, base cannot be less than 2`);if(r<2)throw new Error(`convertRadix: wrong to=${r}, base cannot be less than 2`);if(!Array.isArray(e))throw new Error("convertRadix: data should be array");if(!e.length)return[];let s=0;const o=[],n=Array.from(e);for(n.forEach(a=>{if(a<0||a>=t)throw new Error(`Wrong integer: ${a}`)});;){let a=0,l=!0;for(let p=s;p<n.length;p++){const u=n[p],c=t*a+u;if(!Number.isSafeInteger(c)||t*a/t!==a||c-u!==t*a)throw new Error("convertRadix: carry overflow");a=c%r;const v=Math.floor(c/r);if(n[p]=v,!Number.isSafeInteger(v)||v*r+a!==c)throw new Error("convertRadix: carry overflow");if(l)v?l=!1:s=p;else continue}if(o.push(a),l)break}for(let a=0;a<e.length-1&&e[a]===0;a++)o.push(0);return o.reverse()}function radix(e){return{encode:t=>{if(!isBytes(t))throw new Error("radix.encode input should be Uint8Array");return convertRadix(Array.from(t),2**8,e)},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("radix.decode input should be array of numbers");return Uint8Array.from(convertRadix(t,e,2**8))}}}function checksum(e,t){if(typeof t!="function")throw new Error("checksum fn should be function");return{encode(r){if(!isBytes(r))throw new Error("checksum.encode: input should be Uint8Array");const s=t(r).slice(0,e),o=new Uint8Array(r.length+e);return o.set(r),o.set(s,r.length),o},decode(r){if(!isBytes(r))throw new Error("checksum.decode: input should be Uint8Array");const s=r.slice(0,-e),o=t(s).slice(0,e),n=r.slice(-e);for(let a=0;a<e;a++)if(o[a]!==n[a])throw new Error("Invalid checksum");return s}}}const genBase58=e=>chain(radix(58),alphabet(e),join("")),base58=genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),createBase58check=e=>chain(checksum(4,t=>e(e(t))),base58);const Point=secp256k1.ProjectivePoint,base58check=createBase58check(sha256);function bytesToNumber(e){return BigInt(`0x${bytesToHex(e)}`)}function numberToBytes(e){return hexToBytes(e.toString(16).padStart(64,"0"))}const MASTER_SECRET=utf8ToBytes("Bitcoin seed"),BITCOIN_VERSIONS={private:76066276,public:76067358},HARDENED_OFFSET=2147483648,hash160=e=>ripemd160$1(sha256(e)),fromU32=e=>createView(e).getUint32(0,!1),toU32=e=>{if(!Number.isSafeInteger(e)||e<0||e>2**32-1)throw new Error(`Invalid number=${e}. Should be from 0 to 2 ** 32 - 1`);const t=new Uint8Array(4);return createView(t).setUint32(0,e,!1),t};class HDKey{get fingerprint(){if(!this.pubHash)throw new Error("No publicKey set!");return fromU32(this.pubHash)}get identifier(){return this.pubHash}get pubKeyHash(){return this.pubHash}get privateKey(){return this.privKeyBytes||null}get publicKey(){return this.pubKey||null}get privateExtendedKey(){const t=this.privateKey;if(!t)throw new Error("No private key");return base58check.encode(this.serialize(this.versions.private,concatBytes(new Uint8Array([0]),t)))}get publicExtendedKey(){if(!this.pubKey)throw new Error("No public key");return base58check.encode(this.serialize(this.versions.public,this.pubKey))}static fromMasterSeed(t,r=BITCOIN_VERSIONS){if(bytes(t),8*t.length<128||8*t.length>512)throw new Error(`HDKey: wrong seed length=${t.length}. Should be between 128 and 512 bits; 256 bits is advised)`);const s=hmac(sha512,MASTER_SECRET,t);return new HDKey({versions:r,chainCode:s.slice(32),privateKey:s.slice(0,32)})}static fromExtendedKey(t,r=BITCOIN_VERSIONS){const s=base58check.decode(t),o=createView(s),n=o.getUint32(0,!1),a={versions:r,depth:s[4],parentFingerprint:o.getUint32(5,!1),index:o.getUint32(9,!1),chainCode:s.slice(13,45)},l=s.slice(45),p=l[0]===0;if(n!==r[p?"private":"public"])throw new Error("Version mismatch");return p?new HDKey({...a,privateKey:l.slice(1)}):new HDKey({...a,publicKey:l})}static fromJSON(t){return HDKey.fromExtendedKey(t.xpriv)}constructor(t){if(this.depth=0,this.index=0,this.chainCode=null,this.parentFingerprint=0,!t||typeof t!="object")throw new Error("HDKey.constructor must not be called directly");if(this.versions=t.versions||BITCOIN_VERSIONS,this.depth=t.depth||0,this.chainCode=t.chainCode||null,this.index=t.index||0,this.parentFingerprint=t.parentFingerprint||0,!this.depth&&(this.parentFingerprint||this.index))throw new Error("HDKey: zero depth with non-zero index/parent fingerprint");if(t.publicKey&&t.privateKey)throw new Error("HDKey: publicKey and privateKey at same time.");if(t.privateKey){if(!secp256k1.utils.isValidPrivateKey(t.privateKey))throw new Error("Invalid private key");this.privKey=typeof t.privateKey=="bigint"?t.privateKey:bytesToNumber(t.privateKey),this.privKeyBytes=numberToBytes(this.privKey),this.pubKey=secp256k1.getPublicKey(t.privateKey,!0)}else if(t.publicKey)this.pubKey=Point.fromHex(t.publicKey).toRawBytes(!0);else throw new Error("HDKey: no public or private key provided");this.pubHash=hash160(this.pubKey)}derive(t){if(!/^[mM]'?/.test(t))throw new Error('Path must start with "m" or "M"');if(/^[mM]'?$/.test(t))return this;const r=t.replace(/^[mM]'?\//,"").split("/");let s=this;for(const o of r){const n=/^(\d+)('?)$/.exec(o),a=n&&n[1];if(!n||n.length!==3||typeof a!="string")throw new Error(`Invalid child index: ${o}`);let l=+a;if(!Number.isSafeInteger(l)||l>=HARDENED_OFFSET)throw new Error("Invalid index");n[2]==="'"&&(l+=HARDENED_OFFSET),s=s.deriveChild(l)}return s}deriveChild(t){if(!this.pubKey||!this.chainCode)throw new Error("No publicKey or chainCode set");let r=toU32(t);if(t>=HARDENED_OFFSET){const l=this.privateKey;if(!l)throw new Error("Could not derive hardened child key");r=concatBytes(new Uint8Array([0]),l,r)}else r=concatBytes(this.pubKey,r);const s=hmac(sha512,this.chainCode,r),o=bytesToNumber(s.slice(0,32)),n=s.slice(32);if(!secp256k1.utils.isValidPrivateKey(o))throw new Error("Tweak bigger than curve order");const a={versions:this.versions,chainCode:n,depth:this.depth+1,parentFingerprint:this.fingerprint,index:t};try{if(this.privateKey){const l=mod(this.privKey+o,secp256k1.CURVE.n);if(!secp256k1.utils.isValidPrivateKey(l))throw new Error("The tweak was out of range or the resulted private key is invalid");a.privateKey=l}else{const l=Point.fromHex(this.pubKey).add(Point.fromPrivateKey(o));if(l.equals(Point.ZERO))throw new Error("The tweak was equal to negative P, which made the result key invalid");a.publicKey=l.toRawBytes(!0)}return new HDKey(a)}catch{return this.deriveChild(t+1)}}sign(t){if(!this.privateKey)throw new Error("No privateKey set!");return bytes(t,32),secp256k1.sign(t,this.privKey).toCompactRawBytes()}verify(t,r){if(bytes(t,32),bytes(r,64),!this.publicKey)throw new Error("No publicKey set!");let s;try{s=secp256k1.Signature.fromCompact(r)}catch{return!1}return secp256k1.verify(s,t,this.publicKey)}wipePrivateData(){return this.privKey=void 0,this.privKeyBytes&&(this.privKeyBytes.fill(0),this.privKeyBytes=void 0),this}toJSON(){return{xpriv:this.privateExtendedKey,xpub:this.publicExtendedKey}}serialize(t,r){if(!this.chainCode)throw new Error("No chainCode set");return bytes(r,33),concatBytes(toU32(t),new Uint8Array([this.depth]),toU32(this.parentFingerprint),toU32(this.index),this.chainCode,r)}}var bip341={},ecc_lib={};Object.defineProperty(ecc_lib,"__esModule",{value:!0});ecc_lib.getEccLib=ecc_lib.initEccLib=void 0;const _ECCLIB_CACHE={};function initEccLib(e){e?e!==_ECCLIB_CACHE.eccLib&&(verifyEcc(e),_ECCLIB_CACHE.eccLib=e):_ECCLIB_CACHE.eccLib=e}ecc_lib.initEccLib=initEccLib;function getEccLib(){if(!_ECCLIB_CACHE.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return _ECCLIB_CACHE.eccLib}ecc_lib.getEccLib=getEccLib;const h=e=>Buffer$e.from(e,"hex");function verifyEcc(e){assert(typeof e.isXOnlyPoint=="function"),assert(e.isXOnlyPoint(h("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),assert(e.isXOnlyPoint(h("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),assert(e.isXOnlyPoint(h("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),assert(e.isXOnlyPoint(h("0000000000000000000000000000000000000000000000000000000000000001"))),assert(!e.isXOnlyPoint(h("0000000000000000000000000000000000000000000000000000000000000000"))),assert(!e.isXOnlyPoint(h("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),assert(typeof e.xOnlyPointAddTweak=="function"),tweakAddVectors.forEach(t=>{const r=e.xOnlyPointAddTweak(h(t.pubkey),h(t.tweak));t.result===null?assert(r===null):(assert(r!==null),assert(r.parity===t.parity),assert(Buffer$e.from(r.xOnlyPubkey).equals(h(t.result))))})}function assert(e){if(!e)throw new Error("ecc library invalid")}const tweakAddVectors=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}];var crypto$1={},ripemd160={};Object.defineProperty(ripemd160,"__esModule",{value:!0});ripemd160.ripemd160=ripemd160.RIPEMD160=void 0;const _md_js_1$1=_md,utils_js_1$1=utils$b,Rho=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Id=new Uint8Array(new Array(16).fill(0).map((e,t)=>t)),Pi=Id.map(e=>(9*e+5)%16);let idxL=[Id],idxR=[Pi];for(let e=0;e<4;e++)for(let t of[idxL,idxR])t.push(t[e].map(r=>Rho[r]));const shifts=[[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)),shiftsL=idxL.map((e,t)=>e.map(r=>shifts[t][r])),shiftsR=idxR.map((e,t)=>e.map(r=>shifts[t][r])),Kl=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),Kr=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function f(e,t,r,s){return e===0?t^r^s:e===1?t&r|~t&s:e===2?(t|~r)^s:e===3?t&s|r&~s:t^(r|~s)}const R_BUF=new Uint32Array(16);class RIPEMD160 extends _md_js_1$1.HashMD{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:s,h3:o,h4:n}=this;return[t,r,s,o,n]}set(t,r,s,o,n){this.h0=t|0,this.h1=r|0,this.h2=s|0,this.h3=o|0,this.h4=n|0}process(t,r){for(let b=0;b<16;b++,r+=4)R_BUF[b]=t.getUint32(r,!0);let s=this.h0|0,o=s,n=this.h1|0,a=n,l=this.h2|0,p=l,u=this.h3|0,c=u,v=this.h4|0,w=v;for(let b=0;b<5;b++){const E=4-b,I=Kl[b],x=Kr[b],B=idxL[b],M=idxR[b],q=shiftsL[b],U=shiftsR[b];for(let F=0;F<16;F++){const j=(0,utils_js_1$1.rotl)(s+f(b,n,l,u)+R_BUF[B[F]]+I,q[F])+v|0;s=v,v=u,u=(0,utils_js_1$1.rotl)(l,10)|0,l=n,n=j}for(let F=0;F<16;F++){const j=(0,utils_js_1$1.rotl)(o+f(E,a,p,c)+R_BUF[M[F]]+x,U[F])+w|0;o=w,w=c,c=(0,utils_js_1$1.rotl)(p,10)|0,p=a,a=j}}this.set(this.h1+l+c|0,this.h2+u+w|0,this.h3+v+o|0,this.h4+s+a|0,this.h0+n+p|0)}roundClean(){R_BUF.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}ripemd160.RIPEMD160=RIPEMD160;ripemd160.ripemd160=(0,utils_js_1$1.wrapConstructor)(()=>new RIPEMD160);var sha1={};Object.defineProperty(sha1,"__esModule",{value:!0});sha1.sha1=sha1.SHA1=void 0;const _md_js_1=_md,utils_js_1=utils$b,SHA1_IV=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),SHA1_W=new Uint32Array(80);class SHA1 extends _md_js_1.HashMD{constructor(){super(64,20,8,!1),this.A=SHA1_IV[0]|0,this.B=SHA1_IV[1]|0,this.C=SHA1_IV[2]|0,this.D=SHA1_IV[3]|0,this.E=SHA1_IV[4]|0}get(){const{A:t,B:r,C:s,D:o,E:n}=this;return[t,r,s,o,n]}set(t,r,s,o,n){this.A=t|0,this.B=r|0,this.C=s|0,this.D=o|0,this.E=n|0}process(t,r){for(let p=0;p<16;p++,r+=4)SHA1_W[p]=t.getUint32(r,!1);for(let p=16;p<80;p++)SHA1_W[p]=(0,utils_js_1.rotl)(SHA1_W[p-3]^SHA1_W[p-8]^SHA1_W[p-14]^SHA1_W[p-16],1);let{A:s,B:o,C:n,D:a,E:l}=this;for(let p=0;p<80;p++){let u,c;p<20?(u=(0,_md_js_1.Chi)(o,n,a),c=1518500249):p<40?(u=o^n^a,c=1859775393):p<60?(u=(0,_md_js_1.Maj)(o,n,a),c=2400959708):(u=o^n^a,c=3395469782);const v=(0,utils_js_1.rotl)(s,5)+u+l+c+SHA1_W[p]|0;l=a,a=n,n=(0,utils_js_1.rotl)(o,30),o=s,s=v}s=s+this.A|0,o=o+this.B|0,n=n+this.C|0,a=a+this.D|0,l=l+this.E|0,this.set(s,o,n,a,l)}roundClean(){SHA1_W.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}}sha1.SHA1=SHA1;sha1.sha1=(0,utils_js_1.wrapConstructor)(()=>new SHA1);(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.taggedHash=e.TAGGED_HASH_PREFIXES=e.TAGS=e.hash256=e.hash160=e.sha256=e.sha1=e.ripemd160=void 0;const t=ripemd160,r=sha1,s=sha256$2;function o(c){return Buffer$e.from((0,t.ripemd160)(Uint8Array.from(c)))}e.ripemd160=o;function n(c){return Buffer$e.from((0,r.sha1)(Uint8Array.from(c)))}e.sha1=n;function a(c){return Buffer$e.from((0,s.sha256)(Uint8Array.from(c)))}e.sha256=a;function l(c){return Buffer$e.from((0,t.ripemd160)((0,s.sha256)(Uint8Array.from(c))))}e.hash160=l;function p(c){return Buffer$e.from((0,s.sha256)((0,s.sha256)(Uint8Array.from(c))))}e.hash256=p,e.TAGS=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],e.TAGGED_HASH_PREFIXES={"BIP0340/challenge":Buffer$e.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":Buffer$e.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":Buffer$e.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:Buffer$e.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:Buffer$e.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:Buffer$e.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:Buffer$e.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":Buffer$e.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":Buffer$e.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 u(c,v){return a(Buffer$e.concat([e.TAGGED_HASH_PREFIXES[c],v]))}e.taggedHash=u})(crypto$1);var bufferutils={},types$4={},types$3={Array:function(e){return e!=null&&e.constructor===Array},Boolean:function(e){return typeof e=="boolean"},Function:function(e){return typeof e=="function"},Nil:function(e){return e==null},Number:function(e){return typeof e=="number"},Object:function(e){return typeof e=="object"},String:function(e){return typeof e=="string"},"":function(){return!0}};types$3.Null=types$3.Nil;for(var typeName$1 in types$3)types$3[typeName$1].toJSON=(function(e){return e}).bind(null,typeName$1);var native$2=types$3,native$1=native$2;function getTypeName(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function getValueTypeName$1(e){return native$1.Nil(e)?"":getTypeName(e.constructor)}function getValue(e){return native$1.Function(e)?"":native$1.String(e)?JSON.stringify(e):e&&native$1.Object(e)?"":e}function captureStackTrace(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function tfJSON$1(e){return native$1.Function(e)?e.toJSON?e.toJSON():getTypeName(e):native$1.Array(e)?"Array":e&&native$1.Object(e)?"Object":e!==void 0?e:""}function tfErrorString(e,t,r){var s=getValue(t);return"Expected "+tfJSON$1(e)+", got"+(r!==""?" "+r:"")+(s!==""?" "+s:"")}function TfTypeError$1(e,t,r){r=r||getValueTypeName$1(t),this.message=tfErrorString(e,t,r),captureStackTrace(this,TfTypeError$1),this.__type=e,this.__value=t,this.__valueTypeName=r}TfTypeError$1.prototype=Object.create(Error.prototype);TfTypeError$1.prototype.constructor=TfTypeError$1;function tfPropertyErrorString(e,t,r,s,o){var n='" of type ';return t==="key"&&(n='" with key type '),tfErrorString('property "'+tfJSON$1(r)+n+tfJSON$1(e),s,o)}function TfPropertyTypeError$1(e,t,r,s,o){e?(o=o||getValueTypeName$1(s),this.message=tfPropertyErrorString(e,r,t,s,o)):this.message='Unexpected property "'+t+'"',captureStackTrace(this,TfTypeError$1),this.__label=r,this.__property=t,this.__type=e,this.__value=s,this.__valueTypeName=o}TfPropertyTypeError$1.prototype=Object.create(Error.prototype);TfPropertyTypeError$1.prototype.constructor=TfTypeError$1;function tfCustomError(e,t){return new TfTypeError$1(e,{},t)}function tfSubError$1(e,t,r){return e instanceof TfPropertyTypeError$1?(t=t+"."+e.__property,e=new TfPropertyTypeError$1(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof TfTypeError$1&&(e=new TfPropertyTypeError$1(e.__type,t,r,e.__value,e.__valueTypeName)),captureStackTrace(e),e}var errors={TfTypeError:TfTypeError$1,TfPropertyTypeError:TfPropertyTypeError$1,tfCustomError,tfSubError:tfSubError$1,tfJSON:tfJSON$1,getValueTypeName:getValueTypeName$1},extra,hasRequiredExtra;function requireExtra(){if(hasRequiredExtra)return extra;hasRequiredExtra=1;var e=native$2,t=errors;function r(j){return Buffer$e.isBuffer(j)}function s(j){return typeof j=="string"&&/^([0-9a-f]{2})+$/i.test(j)}function o(j,y){var T=j.toJSON();function D(L){if(!j(L))return!1;if(L.length===y)return!0;throw t.tfCustomError(T+"(Length: "+y+")",T+"(Length: "+L.length+")")}return D.toJSON=function(){return T},D}var n=o.bind(null,e.Array),a=o.bind(null,r),l=o.bind(null,s),p=o.bind(null,e.String);function u(j,y,T){T=T||e.Number;function D(L,C){return T(L,C)&&L>j&&L<y}return D.toJSON=function(){return`${T.toJSON()} between [${j}, ${y}]`},D}var c=Math.pow(2,53)-1;function v(j){return typeof j=="number"&&isFinite(j)}function w(j){return j<<24>>24===j}function b(j){return j<<16>>16===j}function E(j){return(j|0)===j}function I(j){return typeof j=="number"&&j>=-c&&j<=c&&Math.floor(j)===j}function x(j){return(j&255)===j}function B(j){return(j&65535)===j}function M(j){return j>>>0===j}function q(j){return typeof j=="number"&&j>=0&&j<=c&&Math.floor(j)===j}var U={ArrayN:n,Buffer:r,BufferN:a,Finite:v,Hex:s,HexN:l,Int8:w,Int16:b,Int32:E,Int53:I,Range:u,StringN:p,UInt8:x,UInt16:B,UInt32:M,UInt53:q};for(var F in U)U[F].toJSON=(function(j){return j}).bind(null,F);return extra=U,extra}var ERRORS=errors,NATIVE=native$2,tfJSON=ERRORS.tfJSON,TfTypeError=ERRORS.TfTypeError,TfPropertyTypeError=ERRORS.TfPropertyTypeError,tfSubError=ERRORS.tfSubError,getValueTypeName=ERRORS.getValueTypeName,TYPES={arrayOf:function e(t,r){t=compile(t),r=r||{};function s(o,n){return!NATIVE.Array(o)||NATIVE.Nil(o)||r.minLength!==void 0&&o.length<r.minLength||r.maxLength!==void 0&&o.length>r.maxLength||r.length!==void 0&&o.length!==r.length?!1:o.every(function(a,l){try{return typeforce$3(t,a,n)}catch(p){throw tfSubError(p,l)}})}return s.toJSON=function(){var o="["+tfJSON(t)+"]";return r.length!==void 0?o+="{"+r.length+"}":(r.minLength!==void 0||r.maxLength!==void 0)&&(o+="{"+(r.minLength===void 0?0:r.minLength)+","+(r.maxLength===void 0?1/0:r.maxLength)+"}"),o},s},maybe:function e(t){t=compile(t);function r(s,o){return NATIVE.Nil(s)||t(s,o,e)}return r.toJSON=function(){return"?"+tfJSON(t)},r},map:function e(t,r){t=compile(t),r&&(r=compile(r));function s(o,n){if(!NATIVE.Object(o)||NATIVE.Nil(o))return!1;for(var a in o){try{r&&typeforce$3(r,a,n)}catch(p){throw tfSubError(p,a,"key")}try{var l=o[a];typeforce$3(t,l,n)}catch(p){throw tfSubError(p,a)}}return!0}return r?s.toJSON=function(){return"{"+tfJSON(r)+": "+tfJSON(t)+"}"}:s.toJSON=function(){return"{"+tfJSON(t)+"}"},s},object:function e(t){var r={};for(var s in t)r[s]=compile(t[s]);function o(n,a){if(!NATIVE.Object(n)||NATIVE.Nil(n))return!1;var l;try{for(l in r){var p=r[l],u=n[l];typeforce$3(p,u,a)}}catch(c){throw tfSubError(c,l)}if(a){for(l in n)if(!r[l])throw new TfPropertyTypeError(void 0,l)}return!0}return o.toJSON=function(){return tfJSON(r)},o},anyOf:function e(){var t=[].slice.call(arguments).map(compile);function r(s,o){return t.some(function(n){try{return typeforce$3(n,s,o)}catch{return!1}})}return r.toJSON=function(){return t.map(tfJSON).join("|")},r},allOf:function e(){var t=[].slice.call(arguments).map(compile);function r(s,o){return t.every(function(n){try{return typeforce$3(n,s,o)}catch{return!1}})}return r.toJSON=function(){return t.map(tfJSON).join(" & ")},r},quacksLike:function e(t){function r(s){return t===getValueTypeName(s)}return r.toJSON=function(){return t},r},tuple:function e(){var t=[].slice.call(arguments).map(compile);function r(s,o){return NATIVE.Nil(s)||NATIVE.Nil(s.length)||o&&s.length!==t.length?!1:t.every(function(n,a){try{return typeforce$3(n,s[a],o)}catch(l){throw tfSubError(l,a)}})}return r.toJSON=function(){return"("+t.map(tfJSON).join(", ")+")"},r},value:function e(t){function r(s){return s===t}return r.toJSON=function(){return t},r}};TYPES.oneOf=TYPES.anyOf;function compile(e){if(NATIVE.String(e))return e[0]==="?"?TYPES.maybe(e.slice(1)):NATIVE[e]||TYPES.quacksLike(e);if(e&&NATIVE.Object(e)){if(NATIVE.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return TYPES.arrayOf(e[0])}return TYPES.object(e)}else if(NATIVE.Function(e))return e;return TYPES.value(e)}function typeforce$3(e,t,r,s){if(NATIVE.Function(e)){if(e(t,r))return!0;throw new TfTypeError(s||e,t)}return typeforce$3(compile(e),t,r)}for(var typeName in NATIVE)typeforce$3[typeName]=NATIVE[typeName];for(typeName in TYPES)typeforce$3[typeName]=TYPES[typeName];var EXTRA=requireExtra();for(typeName in EXTRA)typeforce$3[typeName]=EXTRA[typeName];typeforce$3.compile=compile;typeforce$3.TfTypeError=TfTypeError;typeforce$3.TfPropertyTypeError=TfPropertyTypeError;var typeforce_1=typeforce$3;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.oneOf=e.Null=e.BufferN=e.Function=e.UInt32=e.UInt8=e.tuple=e.maybe=e.Hex=e.Buffer=e.String=e.Boolean=e.Array=e.Number=e.Hash256bit=e.Hash160bit=e.Buffer256bit=e.isTaptree=e.isTapleaf=e.TAPLEAF_VERSION_MASK=e.Network=e.ECPoint=e.Satoshi=e.Signer=e.BIP32Path=e.UInt31=e.isPoint=e.typeforce=void 0;const t=require$$0$3;e.typeforce=typeforce_1;const r=t.Buffer.alloc(32,0),s=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function o(b){if(!t.Buffer.isBuffer(b)||b.length<33)return!1;const E=b[0],I=b.slice(1,33);if(I.compare(r)===0||I.compare(s)>=0)return!1;if((E===2||E===3)&&b.length===33)return!0;const x=b.slice(33);return x.compare(r)===0||x.compare(s)>=0?!1:E===4&&b.length===65}e.isPoint=o;const n=Math.pow(2,31)-1;function a(b){return e.typeforce.UInt32(b)&&b<=n}e.UInt31=a;function l(b){return e.typeforce.String(b)&&!!b.match(/^(m\/)?(\d+'?\/)*\d+'?$/)}e.BIP32Path=l,l.toJSON=()=>"BIP32 derivation path";function p(b){return(e.typeforce.Buffer(b.publicKey)||typeof b.getPublicKey=="function")&&typeof b.sign=="function"}e.Signer=p;const u=21*1e14;function c(b){return e.typeforce.UInt53(b)&&b<=u}e.Satoshi=c,e.ECPoint=e.typeforce.quacksLike("Point"),e.Network=e.typeforce.compile({messagePrefix:e.typeforce.oneOf(e.typeforce.Buffer,e.typeforce.String),bip32:{public:e.typeforce.UInt32,private:e.typeforce.UInt32},pubKeyHash:e.typeforce.UInt8,scriptHash:e.typeforce.UInt8,wif:e.typeforce.UInt8}),e.TAPLEAF_VERSION_MASK=254;function v(b){return!b||!("output"in b)||!t.Buffer.isBuffer(b.output)?!1:b.version!==void 0?(b.version&e.TAPLEAF_VERSION_MASK)===b.version:!0}e.isTapleaf=v;function w(b){return(0,e.Array)(b)?b.length!==2?!1:b.every(E=>w(E)):v(b)}e.isTaptree=w,e.Buffer256bit=e.typeforce.BufferN(32),e.Hash160bit=e.typeforce.BufferN(20),e.Hash256bit=e.typeforce.BufferN(32),e.Number=e.typeforce.Number,e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.String=e.typeforce.String,e.Buffer=e.typeforce.Buffer,e.Hex=e.typeforce.Hex,e.maybe=e.typeforce.maybe,e.tuple=e.typeforce.tuple,e.UInt8=e.typeforce.UInt8,e.UInt32=e.typeforce.UInt32,e.Function=e.typeforce.Function,e.BufferN=e.typeforce.BufferN,e.Null=e.typeforce.Null,e.oneOf=e.typeforce.oneOf})(types$4);var Buffer=safeBufferExports.Buffer,MAX_SAFE_INTEGER$1=9007199254740991;function checkUInt53$1(e){if(e<0||e>MAX_SAFE_INTEGER$1||e%1!==0)throw new RangeError("value out of range")}function encode$5(e,t,r){if(checkUInt53$1(e),t||(t=Buffer.allocUnsafe(encodingLength$2(e))),!Buffer.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");return r||(r=0),e<253?(t.writeUInt8(e,r),encode$5.bytes=1):e<=65535?(t.writeUInt8(253,r),t.writeUInt16LE(e,r+1),encode$5.bytes=3):e<=4294967295?(t.writeUInt8(254,r),t.writeUInt32LE(e,r+1),encode$5.bytes=5):(t.writeUInt8(255,r),t.writeUInt32LE(e>>>0,r+1),t.writeUInt32LE(e/4294967296|0,r+5),encode$5.bytes=9),t}function decode$5(e,t){if(!Buffer.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");t||(t=0);var r=e.readUInt8(t);if(r<253)return decode$5.bytes=1,r;if(r===253)return decode$5.bytes=3,e.readUInt16LE(t+1);if(r===254)return decode$5.bytes=5,e.readUInt32LE(t+1);decode$5.bytes=9;var s=e.readUInt32LE(t+1),o=e.readUInt32LE(t+5),n=o*4294967296+s;return checkUInt53$1(n),n}function encodingLength$2(e){return checkUInt53$1(e),e<253?1:e<=65535?3:e<=4294967295?5:9}var varuintBitcoin={encode:encode$5,decode:decode$5,encodingLength:encodingLength$2};Object.defineProperty(bufferutils,"__esModule",{value:!0});bufferutils.BufferReader=bufferutils.BufferWriter=bufferutils.cloneBuffer=bufferutils.reverseBuffer=bufferutils.writeUInt64LE=bufferutils.readUInt64LE=bufferutils.varuint=void 0;const types$2=types$4,{typeforce:typeforce$2}=types$2,varuint$1=varuintBitcoin;bufferutils.varuint=varuint$1;function verifuint(e,t){if(typeof e!="number")throw new Error("cannot write a non-number as a number");if(e<0)throw new Error("specified a negative value for writing an unsigned value");if(e>t)throw new Error("RangeError: value out of range");if(Math.floor(e)!==e)throw new Error("value has a fractional component")}function readUInt64LE(e,t){const r=e.readUInt32LE(t);let s=e.readUInt32LE(t+4);return s*=4294967296,verifuint(s+r,9007199254740991),s+r}bufferutils.readUInt64LE=readUInt64LE;function writeUInt64LE(e,t,r){return verifuint(t,9007199254740991),e.writeInt32LE(t&-1,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}bufferutils.writeUInt64LE=writeUInt64LE;function reverseBuffer(e){if(e.length<1)return e;let t=e.length-1,r=0;for(let s=0;s<e.length/2;s++)r=e[s],e[s]=e[t],e[t]=r,t--;return e}bufferutils.reverseBuffer=reverseBuffer;function cloneBuffer(e){const t=Buffer$e.allocUnsafe(e.length);return e.copy(t),t}bufferutils.cloneBuffer=cloneBuffer;class BufferWriter{static withCapacity(t){return new BufferWriter(Buffer$e.alloc(t))}constructor(t,r=0){this.buffer=t,this.offset=r,typeforce$2(types$2.tuple(types$2.Buffer,types$2.UInt32),[t,r])}writeUInt8(t){this.offset=this.buffer.writeUInt8(t,this.offset)}writeInt32(t){this.offset=this.buffer.writeInt32LE(t,this.offset)}writeUInt32(t){this.offset=this.buffer.writeUInt32LE(t,this.offset)}writeUInt64(t){this.offset=writeUInt64LE(this.buffer,t,this.offset)}writeVarInt(t){varuint$1.encode(t,this.buffer,this.offset),this.offset+=varuint$1.encode.bytes}writeSlice(t){if(this.buffer.length<this.offset+t.length)throw new Error("Cannot write slice out of bounds");this.offset+=t.copy(this.buffer,this.offset)}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}`)}}bufferutils.BufferWriter=BufferWriter;class BufferReader{constructor(t,r=0){this.buffer=t,this.offset=r,typeforce$2(types$2.tuple(types$2.Buffer,types$2.UInt32),[t,r])}readUInt8(){const t=this.buffer.readUInt8(this.offset);return this.offset++,t}readInt32(){const t=this.buffer.readInt32LE(this.offset);return this.offset+=4,t}readUInt32(){const t=this.buffer.readUInt32LE(this.offset);return this.offset+=4,t}readUInt64(){const t=readUInt64LE(this.buffer,this.offset);return this.offset+=8,t}readVarInt(){const t=varuint$1.decode(this.buffer,this.offset);return this.offset+=varuint$1.decode.bytes,t}readSlice(t){if(this.buffer.length<this.offset+t)throw new Error("Cannot read slice out of bounds");const r=this.buffer.slice(this.offset,this.offset+t);return this.offset+=t,r}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const t=this.readVarInt(),r=[];for(let s=0;s<t;s++)r.push(this.readVarSlice());return r}}bufferutils.BufferReader=BufferReader;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.tweakKey=e.tapTweakHash=e.tapleafHash=e.findScriptPath=e.toHashTree=e.rootHashFromPath=e.MAX_TAPTREE_DEPTH=e.LEAF_VERSION_TAPSCRIPT=void 0;const t=require$$0$3,r=ecc_lib,s=crypto$1,o=bufferutils,n=types$4;e.LEAF_VERSION_TAPSCRIPT=192,e.MAX_TAPTREE_DEPTH=128;const a=I=>"left"in I&&"right"in I;function l(I,x){if(I.length<33)throw new TypeError(`The control-block length is too small. Got ${I.length}, expected min 33.`);const B=(I.length-33)/32;let M=x;for(let q=0;q<B;q++){const U=I.slice(33+32*q,65+32*q);M.compare(U)<0?M=b(M,U):M=b(U,M)}return M}e.rootHashFromPath=l;function p(I){if((0,n.isTapleaf)(I))return{hash:c(I)};const x=[p(I[0]),p(I[1])];x.sort((q,U)=>q.hash.compare(U.hash));const[B,M]=x;return{hash:b(B.hash,M.hash),left:B,right:M}}e.toHashTree=p;function u(I,x){if(a(I)){const B=u(I.left,x);if(B!==void 0)return[...B,I.right.hash];const M=u(I.right,x);if(M!==void 0)return[...M,I.left.hash]}else if(I.hash.equals(x))return[]}e.findScriptPath=u;function c(I){const x=I.version||e.LEAF_VERSION_TAPSCRIPT;return s.taggedHash("TapLeaf",t.Buffer.concat([t.Buffer.from([x]),E(I.output)]))}e.tapleafHash=c;function v(I,x){return s.taggedHash("TapTweak",t.Buffer.concat(x?[I,x]:[I]))}e.tapTweakHash=v;function w(I,x){if(!t.Buffer.isBuffer(I)||I.length!==32||x&&x.length!==32)return null;const B=v(I,x),M=(0,r.getEccLib)().xOnlyPointAddTweak(I,B);return!M||M.xOnlyPubkey===null?null:{parity:M.parity,x:t.Buffer.from(M.xOnlyPubkey)}}e.tweakKey=w;function b(I,x){return s.taggedHash("TapBranch",t.Buffer.concat([I,x]))}function E(I){const x=o.varuint.encodingLength(I.length),B=t.Buffer.allocUnsafe(x);return o.varuint.encode(I.length,B),t.Buffer.concat([B,I])}})(bip341);var bip371={},transaction={},script={},bip66$1={};Object.defineProperty(bip66$1,"__esModule",{value:!0});bip66$1.encode=bip66$1.decode=bip66$1.check=void 0;function check(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))}bip66$1.check=check;function decode$4(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)}}bip66$1.decode=decode$4;function encode$4(e,t){const r=e.length,s=t.length;if(r===0)throw new Error("R length is zero");if(s===0)throw new Error("S length is zero");if(r>33)throw new Error("R length is too long");if(s>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(s>1&&t[0]===0&&!(t[1]&128))throw new Error("S value excessively padded");const o=Buffer$e.allocUnsafe(6+r+s);return o[0]=48,o[1]=o.length-2,o[2]=2,o[3]=e.length,e.copy(o,4),o[4+r]=2,o[5+r]=t.length,t.copy(o,6+r),o}bip66$1.encode=encode$4;var ops={};Object.defineProperty(ops,"__esModule",{value:!0});ops.REVERSE_OPS=ops.OPS=void 0;const OPS$8={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};ops.OPS=OPS$8;const REVERSE_OPS={};ops.REVERSE_OPS=REVERSE_OPS;for(const e of Object.keys(OPS$8)){const t=OPS$8[e];REVERSE_OPS[t]=e}var push_data={};Object.defineProperty(push_data,"__esModule",{value:!0});push_data.decode=push_data.encode=push_data.encodingLength=void 0;const ops_1=ops;function encodingLength$1(e){return e<ops_1.OPS.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}push_data.encodingLength=encodingLength$1;function encode$3(e,t,r){const s=encodingLength$1(t);return s===1?e.writeUInt8(t,r):s===2?(e.writeUInt8(ops_1.OPS.OP_PUSHDATA1,r),e.writeUInt8(t,r+1)):s===3?(e.writeUInt8(ops_1.OPS.OP_PUSHDATA2,r),e.writeUInt16LE(t,r+1)):(e.writeUInt8(ops_1.OPS.OP_PUSHDATA4,r),e.writeUInt32LE(t,r+1)),s}push_data.encode=encode$3;function decode$3(e,t){const r=e.readUInt8(t);let s,o;if(r<ops_1.OPS.OP_PUSHDATA1)s=r,o=1;else if(r===ops_1.OPS.OP_PUSHDATA1){if(t+2>e.length)return null;s=e.readUInt8(t+1),o=2}else if(r===ops_1.OPS.OP_PUSHDATA2){if(t+3>e.length)return null;s=e.readUInt16LE(t+1),o=3}else{if(t+5>e.length)return null;if(r!==ops_1.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");s=e.readUInt32LE(t+1),o=5}return{opcode:r,number:s,size:o}}push_data.decode=decode$3;var script_number={};Object.defineProperty(script_number,"__esModule",{value:!0});script_number.encode=script_number.decode=void 0;function decode$2(e,t,r){t=t||4,r=r===void 0?!0:r;const s=e.length;if(s===0)return 0;if(s>t)throw new TypeError("Script number overflow");if(r&&!(e[s-1]&127)&&(s<=1||!(e[s-2]&128)))throw new Error("Non-minimally encoded script number");if(s===5){const n=e.readUInt32LE(0),a=e.readUInt8(4);return a&128?-((a&-129)*4294967296+n):a*4294967296+n}let o=0;for(let n=0;n<s;++n)o|=e[n]<<8*n;return e[s-1]&128?-(o&~(128<<8*(s-1))):o}script_number.decode=decode$2;function scriptNumSize(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function encode$2(e){let t=Math.abs(e);const r=scriptNumSize(t),s=Buffer$e.allocUnsafe(r),o=e<0;for(let n=0;n<r;++n)s.writeUInt8(t&255,n),t>>=8;return s[r-1]&128?s.writeUInt8(o?128:0,r-1):o&&(s[r-1]|=128),s}script_number.encode=encode$2;var script_signature={};Object.defineProperty(script_signature,"__esModule",{value:!0});script_signature.encode=script_signature.decode=void 0;const bip66=bip66$1,types$1=types$4,{typeforce:typeforce$1}=types$1,ZERO$1=Buffer$e.alloc(1,0);function toDER(e){let t=0;for(;e[t]===0;)++t;return t===e.length?ZERO$1:(e=e.slice(t),e[0]&128?Buffer$e.concat([ZERO$1,e],1+e.length):e)}function fromDER(e){e[0]===0&&(e=e.slice(1));const t=Buffer$e.alloc(32,0),r=Math.max(0,32-e.length);return e.copy(t,r),t}function decode$1(e){const t=e.readUInt8(e.length-1),r=t&-129;if(r<=0||r>=4)throw new Error("Invalid hashType "+t);const s=bip66.decode(e.slice(0,-1)),o=fromDER(s.r),n=fromDER(s.s);return{signature:Buffer$e.concat([o,n],64),hashType:t}}script_signature.decode=decode$1;function encode$1(e,t){typeforce$1({signature:types$1.BufferN(64),hashType:types$1.UInt8},{signature:e,hashType:t});const r=t&-129;if(r<=0||r>=4)throw new Error("Invalid hashType "+t);const s=Buffer$e.allocUnsafe(1);s.writeUInt8(t,0);const o=toDER(e.slice(0,32)),n=toDER(e.slice(32,64));return Buffer$e.concat([bip66.encode(o,n),s])}script_signature.encode=encode$1;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.signature=e.number=e.isCanonicalScriptSignature=e.isDefinedHashType=e.isCanonicalPubKey=e.toStack=e.fromASM=e.toASM=e.decompile=e.compile=e.countNonPushOnlyOPs=e.isPushOnly=e.OPS=void 0;const t=bip66$1,r=ops;Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return r.OPS}});const s=push_data,o=script_number,n=script_signature,a=types$4,{typeforce:l}=a,p=r.OPS.OP_RESERVED;function u(D){return a.Number(D)&&(D===r.OPS.OP_0||D>=r.OPS.OP_1&&D<=r.OPS.OP_16||D===r.OPS.OP_1NEGATE)}function c(D){return a.Buffer(D)||u(D)}function v(D){return a.Array(D)&&D.every(c)}e.isPushOnly=v;function w(D){return D.length-D.filter(c).length}e.countNonPushOnlyOPs=w;function b(D){if(D.length===0)return r.OPS.OP_0;if(D.length===1){if(D[0]>=1&&D[0]<=16)return p+D[0];if(D[0]===129)return r.OPS.OP_1NEGATE}}function E(D){return Buffer$e.isBuffer(D)}function I(D){return a.Array(D)}function x(D){return Buffer$e.isBuffer(D)}function B(D){if(E(D))return D;l(a.Array,D);const L=D.reduce((_,$)=>x($)?$.length===1&&b($)!==void 0?_+1:_+s.encodingLength($.length)+$.length:_+1,0),C=Buffer$e.allocUnsafe(L);let d=0;if(D.forEach(_=>{if(x(_)){const $=b(_);if($!==void 0){C.writeUInt8($,d),d+=1;return}d+=s.encode(C,_.length,d),_.copy(C,d),d+=_.length}else C.writeUInt8(_,d),d+=1}),d!==C.length)throw new Error("Could not decode chunks");return C}e.compile=B;function M(D){if(I(D))return D;l(a.Buffer,D);const L=[];let C=0;for(;C<D.length;){const d=D[C];if(d>r.OPS.OP_0&&d<=r.OPS.OP_PUSHDATA4){const _=s.decode(D,C);if(_===null||(C+=_.size,C+_.number>D.length))return null;const $=D.slice(C,C+_.number);C+=_.number;const S=b($);S!==void 0?L.push(S):L.push($)}else L.push(d),C+=1}return L}e.decompile=M;function q(D){return E(D)&&(D=M(D)),D.map(L=>{if(x(L)){const C=b(L);if(C===void 0)return L.toString("hex");L=C}return r.REVERSE_OPS[L]}).join(" ")}e.toASM=q;function U(D){return l(a.String,D),B(D.split(" ").map(L=>r.OPS[L]!==void 0?r.OPS[L]:(l(a.Hex,L),Buffer$e.from(L,"hex"))))}e.fromASM=U;function F(D){return D=M(D),l(v,D),D.map(L=>x(L)?L:L===r.OPS.OP_0?Buffer$e.allocUnsafe(0):o.encode(L-p))}e.toStack=F;function j(D){return a.isPoint(D)}e.isCanonicalPubKey=j;function y(D){const L=D&-129;return L>0&&L<4}e.isDefinedHashType=y;function T(D){return!Buffer$e.isBuffer(D)||!y(D[D.length-1])?!1:t.check(D.slice(0,-1))}e.isCanonicalScriptSignature=T,e.number=o,e.signature=n})(script);Object.defineProperty(transaction,"__esModule",{value:!0});transaction.Transaction=void 0;const bufferutils_1=bufferutils,bcrypto$4=crypto$1,bscript$9=script,script_1=script,types=types$4,{typeforce}=types;function varSliceSize(e){const t=e.length;return bufferutils_1.varuint.encodingLength(t)+t}function vectorSize(e){const t=e.length;return bufferutils_1.varuint.encodingLength(t)+e.reduce((r,s)=>r+varSliceSize(s),0)}const EMPTY_BUFFER$2=Buffer$e.allocUnsafe(0),EMPTY_WITNESS=[],ZERO=Buffer$e.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),ONE=Buffer$e.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),VALUE_UINT64_MAX=Buffer$e.from("ffffffffffffffff","hex"),BLANK_OUTPUT={script:EMPTY_BUFFER$2,valueBuffer:VALUE_UINT64_MAX};function isOutput(e){return e.value!==void 0}class Transaction{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(t,r){const s=new bufferutils_1.BufferReader(t),o=new Transaction;o.version=s.readInt32();const n=s.readUInt8(),a=s.readUInt8();let l=!1;n===Transaction.ADVANCED_TRANSACTION_MARKER&&a===Transaction.ADVANCED_TRANSACTION_FLAG?l=!0:s.offset-=2;const p=s.readVarInt();for(let c=0;c<p;++c)o.ins.push({hash:s.readSlice(32),index:s.readUInt32(),script:s.readVarSlice(),sequence:s.readUInt32(),witness:EMPTY_WITNESS});const u=s.readVarInt();for(let c=0;c<u;++c)o.outs.push({value:s.readUInt64(),script:s.readVarSlice()});if(l){for(let c=0;c<p;++c)o.ins[c].witness=s.readVector();if(!o.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(o.locktime=s.readUInt32(),r)return o;if(s.offset!==t.length)throw new Error("Transaction has unexpected data");return o}static fromHex(t){return Transaction.fromBuffer(Buffer$e.from(t,"hex"),!1)}static isCoinbaseHash(t){typeforce(types.Hash256bit,t);for(let r=0;r<32;++r)if(t[r]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&Transaction.isCoinbaseHash(this.ins[0].hash)}addInput(t,r,s,o){return typeforce(types.tuple(types.Hash256bit,types.UInt32,types.maybe(types.UInt32),types.maybe(types.Buffer)),arguments),types.Null(s)&&(s=Transaction.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:r,script:o||EMPTY_BUFFER$2,sequence:s,witness:EMPTY_WITNESS})-1}addOutput(t,r){return typeforce(types.tuple(types.Buffer,types.Satoshi),arguments),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)+bufferutils_1.varuint.encodingLength(this.ins.length)+bufferutils_1.varuint.encodingLength(this.outs.length)+this.ins.reduce((s,o)=>s+40+varSliceSize(o.script),0)+this.outs.reduce((s,o)=>s+8+varSliceSize(o.script),0)+(r?this.ins.reduce((s,o)=>s+vectorSize(o.witness),0):0)}clone(){const t=new Transaction;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,s){if(typeforce(types.tuple(types.UInt32,types.Buffer,types.Number),arguments),t>=this.ins.length)return ONE;const o=bscript$9.compile(bscript$9.decompile(r).filter(l=>l!==script_1.OPS.OP_CODESEPARATOR)),n=this.clone();if((s&31)===Transaction.SIGHASH_NONE)n.outs=[],n.ins.forEach((l,p)=>{p!==t&&(l.sequence=0)});else if((s&31)===Transaction.SIGHASH_SINGLE){if(t>=this.outs.length)return ONE;n.outs.length=t+1;for(let l=0;l<t;l++)n.outs[l]=BLANK_OUTPUT;n.ins.forEach((l,p)=>{p!==t&&(l.sequence=0)})}s&Transaction.SIGHASH_ANYONECANPAY?(n.ins=[n.ins[t]],n.ins[0].script=o):(n.ins.forEach(l=>{l.script=EMPTY_BUFFER$2}),n.ins[t].script=o);const a=Buffer$e.allocUnsafe(n.byteLength(!1)+4);return a.writeInt32LE(s,a.length-4),n.__toBuffer(a,0,!1),bcrypto$4.hash256(a)}hashForWitnessV1(t,r,s,o,n,a){if(typeforce(types.tuple(types.UInt32,typeforce.arrayOf(types.Buffer),typeforce.arrayOf(types.Satoshi),types.UInt32),arguments),s.length!==this.ins.length||r.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const l=o===Transaction.SIGHASH_DEFAULT?Transaction.SIGHASH_ALL:o&Transaction.SIGHASH_OUTPUT_MASK,u=(o&Transaction.SIGHASH_INPUT_MASK)===Transaction.SIGHASH_ANYONECANPAY,c=l===Transaction.SIGHASH_NONE,v=l===Transaction.SIGHASH_SINGLE;let w=EMPTY_BUFFER$2,b=EMPTY_BUFFER$2,E=EMPTY_BUFFER$2,I=EMPTY_BUFFER$2,x=EMPTY_BUFFER$2;if(!u){let U=bufferutils_1.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(F=>{U.writeSlice(F.hash),U.writeUInt32(F.index)}),w=bcrypto$4.sha256(U.end()),U=bufferutils_1.BufferWriter.withCapacity(8*this.ins.length),s.forEach(F=>U.writeUInt64(F)),b=bcrypto$4.sha256(U.end()),U=bufferutils_1.BufferWriter.withCapacity(r.map(varSliceSize).reduce((F,j)=>F+j)),r.forEach(F=>U.writeVarSlice(F)),E=bcrypto$4.sha256(U.end()),U=bufferutils_1.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(F=>U.writeUInt32(F.sequence)),I=bcrypto$4.sha256(U.end())}if(c||v){if(v&&t<this.outs.length){const U=this.outs[t],F=bufferutils_1.BufferWriter.withCapacity(8+varSliceSize(U.script));F.writeUInt64(U.value),F.writeVarSlice(U.script),x=bcrypto$4.sha256(F.end())}}else{const U=this.outs.map(j=>8+varSliceSize(j.script)).reduce((j,y)=>j+y),F=bufferutils_1.BufferWriter.withCapacity(U);this.outs.forEach(j=>{F.writeUInt64(j.value),F.writeVarSlice(j.script)}),x=bcrypto$4.sha256(F.end())}const B=(n?2:0)+(a?1:0),M=174-(u?49:0)-(c?32:0)+(a?32:0)+(n?37:0),q=bufferutils_1.BufferWriter.withCapacity(M);if(q.writeUInt8(o),q.writeInt32(this.version),q.writeUInt32(this.locktime),q.writeSlice(w),q.writeSlice(b),q.writeSlice(E),q.writeSlice(I),c||v||q.writeSlice(x),q.writeUInt8(B),u){const U=this.ins[t];q.writeSlice(U.hash),q.writeUInt32(U.index),q.writeUInt64(s[t]),q.writeVarSlice(r[t]),q.writeUInt32(U.sequence)}else q.writeUInt32(t);if(a){const U=bufferutils_1.BufferWriter.withCapacity(varSliceSize(a));U.writeVarSlice(a),q.writeSlice(bcrypto$4.sha256(U.end()))}return v&&q.writeSlice(x),n&&(q.writeSlice(n),q.writeUInt8(0),q.writeUInt32(4294967295)),bcrypto$4.taggedHash("TapSighash",Buffer$e.concat([Buffer$e.from([0]),q.end()]))}hashForWitnessV0(t,r,s,o){typeforce(types.tuple(types.UInt32,types.Buffer,types.Satoshi,types.UInt32),arguments);let n=Buffer$e.from([]),a,l=ZERO,p=ZERO,u=ZERO;if(o&Transaction.SIGHASH_ANYONECANPAY||(n=Buffer$e.allocUnsafe(36*this.ins.length),a=new bufferutils_1.BufferWriter(n,0),this.ins.forEach(v=>{a.writeSlice(v.hash),a.writeUInt32(v.index)}),p=bcrypto$4.hash256(n)),!(o&Transaction.SIGHASH_ANYONECANPAY)&&(o&31)!==Transaction.SIGHASH_SINGLE&&(o&31)!==Transaction.SIGHASH_NONE&&(n=Buffer$e.allocUnsafe(4*this.ins.length),a=new bufferutils_1.BufferWriter(n,0),this.ins.forEach(v=>{a.writeUInt32(v.sequence)}),u=bcrypto$4.hash256(n)),(o&31)!==Transaction.SIGHASH_SINGLE&&(o&31)!==Transaction.SIGHASH_NONE){const v=this.outs.reduce((w,b)=>w+8+varSliceSize(b.script),0);n=Buffer$e.allocUnsafe(v),a=new bufferutils_1.BufferWriter(n,0),this.outs.forEach(w=>{a.writeUInt64(w.value),a.writeVarSlice(w.script)}),l=bcrypto$4.hash256(n)}else if((o&31)===Transaction.SIGHASH_SINGLE&&t<this.outs.length){const v=this.outs[t];n=Buffer$e.allocUnsafe(8+varSliceSize(v.script)),a=new bufferutils_1.BufferWriter(n,0),a.writeUInt64(v.value),a.writeVarSlice(v.script),l=bcrypto$4.hash256(n)}n=Buffer$e.allocUnsafe(156+varSliceSize(r)),a=new bufferutils_1.BufferWriter(n,0);const c=this.ins[t];return a.writeInt32(this.version),a.writeSlice(p),a.writeSlice(u),a.writeSlice(c.hash),a.writeUInt32(c.index),a.writeVarSlice(r),a.writeUInt64(s),a.writeUInt32(c.sequence),a.writeSlice(l),a.writeUInt32(this.locktime),a.writeUInt32(o),bcrypto$4.hash256(n)}getHash(t){return t&&this.isCoinbase()?Buffer$e.alloc(32,0):bcrypto$4.hash256(this.__toBuffer(void 0,void 0,t))}getId(){return(0,bufferutils_1.reverseBuffer)(this.getHash(!1)).toString("hex")}toBuffer(t,r){return this.__toBuffer(t,r,!0)}toHex(){return this.toBuffer(void 0,void 0).toString("hex")}setInputScript(t,r){typeforce(types.tuple(types.Number,types.Buffer),arguments),this.ins[t].script=r}setWitness(t,r){typeforce(types.tuple(types.Number,[types.Buffer]),arguments),this.ins[t].witness=r}__toBuffer(t,r,s=!1){t||(t=Buffer$e.allocUnsafe(this.byteLength(s)));const o=new bufferutils_1.BufferWriter(t,r||0);o.writeInt32(this.version);const n=s&&this.hasWitnesses();return n&&(o.writeUInt8(Transaction.ADVANCED_TRANSACTION_MARKER),o.writeUInt8(Transaction.ADVANCED_TRANSACTION_FLAG)),o.writeVarInt(this.ins.length),this.ins.forEach(a=>{o.writeSlice(a.hash),o.writeUInt32(a.index),o.writeVarSlice(a.script),o.writeUInt32(a.sequence)}),o.writeVarInt(this.outs.length),this.outs.forEach(a=>{isOutput(a)?o.writeUInt64(a.value):o.writeSlice(a.valueBuffer),o.writeVarSlice(a.script)}),n&&this.ins.forEach(a=>{o.writeVector(a.witness)}),o.writeUInt32(this.locktime),r!==void 0?t.slice(r,o.offset):t}}transaction.Transaction=Transaction;Transaction.DEFAULT_SEQUENCE=4294967295;Transaction.SIGHASH_DEFAULT=0;Transaction.SIGHASH_ALL=1;Transaction.SIGHASH_NONE=2;Transaction.SIGHASH_SINGLE=3;Transaction.SIGHASH_ANYONECANPAY=128;Transaction.SIGHASH_OUTPUT_MASK=3;Transaction.SIGHASH_INPUT_MASK=128;Transaction.ADVANCED_TRANSACTION_MARKER=0;Transaction.ADVANCED_TRANSACTION_FLAG=1;var psbtutils={},varint={};Object.defineProperty(varint,"__esModule",{value:!0});const MAX_SAFE_INTEGER=9007199254740991;function checkUInt53(e){if(e<0||e>MAX_SAFE_INTEGER||e%1!==0)throw new RangeError("value out of range")}function encode(e,t,r){if(checkUInt53(e),t||(t=Buffer$e.allocUnsafe(encodingLength(e))),!Buffer$e.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");return r||(r=0),e<253?(t.writeUInt8(e,r),Object.assign(encode,{bytes:1})):e<=65535?(t.writeUInt8(253,r),t.writeUInt16LE(e,r+1),Object.assign(encode,{bytes:3})):e<=4294967295?(t.writeUInt8(254,r),t.writeUInt32LE(e,r+1),Object.assign(encode,{bytes:5})):(t.writeUInt8(255,r),t.writeUInt32LE(e>>>0,r+1),t.writeUInt32LE(e/4294967296|0,r+5),Object.assign(encode,{bytes:9})),t}varint.encode=encode;function decode(e,t){if(!Buffer$e.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");t||(t=0);const r=e.readUInt8(t);if(r<253)return Object.assign(decode,{bytes:1}),r;if(r===253)return Object.assign(decode,{bytes:3}),e.readUInt16LE(t+1);if(r===254)return Object.assign(decode,{bytes:5}),e.readUInt32LE(t+1);{Object.assign(decode,{bytes:9});const s=e.readUInt32LE(t+1),n=e.readUInt32LE(t+5)*4294967296+s;return checkUInt53(n),n}}varint.decode=decode;function encodingLength(e){return checkUInt53(e),e<253?1:e<=65535?3:e<=4294967295?5:9}varint.encodingLength=encodingLength;var payments$1={},embed={},networks={};Object.defineProperty(networks,"__esModule",{value:!0});networks.testnet=networks.regtest=networks.bitcoin=void 0;networks.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
77
77
|
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};networks.regtest={messagePrefix:`Bitcoin Signed Message:
|
|
78
78
|
`,bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};networks.testnet={messagePrefix:`Bitcoin Signed Message:
|
|
79
|
-
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var lazy$8={};Object.defineProperty(lazy$8,"__esModule",{value:!0});lazy$8.value=lazy$8.prop=void 0;function prop(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){const s=r.call(this);return this[t]=s,s},set(s){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,value:s,writable:!0})}})}lazy$8.prop=prop;function value(e){let t;return()=>(t!==void 0||(t=e()),t)}lazy$8.value=value;Object.defineProperty(embed,"__esModule",{value:!0});embed.p2data=void 0;const networks_1$7=networks,bscript$8=script,types_1$8=types$4,lazy$7=lazy$8,OPS$7=bscript$8.OPS;function stacksEqual$4(e,t){return e.length!==t.length?!1:e.every((r,s)=>r.equals(t[s]))}function p2data(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,types_1$8.typeforce)({network:types_1$8.typeforce.maybe(types_1$8.typeforce.Object),output:types_1$8.typeforce.maybe(types_1$8.typeforce.Buffer),data:types_1$8.typeforce.maybe(types_1$8.typeforce.arrayOf(types_1$8.typeforce.Buffer))},e);const s={name:"embed",network:e.network||networks_1$7.bitcoin};if(lazy$7.prop(s,"output",()=>{if(e.data)return bscript$8.compile([OPS$7.OP_RETURN].concat(e.data))}),lazy$7.prop(s,"data",()=>{if(e.output)return bscript$8.decompile(e.output).slice(1)}),t.validate&&e.output){const o=bscript$8.decompile(e.output);if(o[0]!==OPS$7.OP_RETURN)throw new TypeError("Output is invalid");if(!o.slice(1).every(types_1$8.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!stacksEqual$4(e.data,s.data))throw new TypeError("Data mismatch")}return Object.assign(s,e)}embed.p2data=p2data;var p2ms$1={};Object.defineProperty(p2ms$1,"__esModule",{value:!0});p2ms$1.p2ms=void 0;const networks_1$6=networks,bscript$7=script,types_1$7=types$4,lazy$6=lazy$8,OPS$6=bscript$7.OPS,OP_INT_BASE=OPS$6.OP_RESERVED;function stacksEqual$3(e,t){return e.length!==t.length?!1:e.every((r,s)=>r.equals(t[s]))}function p2ms(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(p){return bscript$7.isCanonicalScriptSignature(p)||(t.allowIncomplete&&p===OPS$6.OP_0)!==void 0}(0,types_1$7.typeforce)({network:types_1$7.typeforce.maybe(types_1$7.typeforce.Object),m:types_1$7.typeforce.maybe(types_1$7.typeforce.Number),n:types_1$7.typeforce.maybe(types_1$7.typeforce.Number),output:types_1$7.typeforce.maybe(types_1$7.typeforce.Buffer),pubkeys:types_1$7.typeforce.maybe(types_1$7.typeforce.arrayOf(types_1$7.isPoint)),signatures:types_1$7.typeforce.maybe(types_1$7.typeforce.arrayOf(r)),input:types_1$7.typeforce.maybe(types_1$7.typeforce.Buffer)},e);const o={network:e.network||networks_1$6.bitcoin};let n=[],a=!1;function l(p){a||(a=!0,n=bscript$7.decompile(p),o.m=n[0]-OP_INT_BASE,o.n=n[n.length-2]-OP_INT_BASE,o.pubkeys=n.slice(1,-2))}if(lazy$6.prop(o,"output",()=>{if(e.m&&o.n&&e.pubkeys)return bscript$7.compile([].concat(OP_INT_BASE+e.m,e.pubkeys,OP_INT_BASE+o.n,OPS$6.OP_CHECKMULTISIG))}),lazy$6.prop(o,"m",()=>{if(o.output)return l(o.output),o.m}),lazy$6.prop(o,"n",()=>{if(o.pubkeys)return o.pubkeys.length}),lazy$6.prop(o,"pubkeys",()=>{if(e.output)return l(e.output),o.pubkeys}),lazy$6.prop(o,"signatures",()=>{if(e.input)return bscript$7.decompile(e.input).slice(1)}),lazy$6.prop(o,"input",()=>{if(e.signatures)return bscript$7.compile([OPS$6.OP_0].concat(e.signatures))}),lazy$6.prop(o,"witness",()=>{if(o.input)return[]}),lazy$6.prop(o,"name",()=>{if(!(!o.m||!o.n))return`p2ms(${o.m} of ${o.n})`}),t.validate){if(e.output){if(l(e.output),!types_1$7.typeforce.Number(n[0]))throw new TypeError("Output is invalid");if(!types_1$7.typeforce.Number(n[n.length-2]))throw new TypeError("Output is invalid");if(n[n.length-1]!==OPS$6.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(o.m<=0||o.n>16||o.m>o.n||o.n!==n.length-3)throw new TypeError("Output is invalid");if(!o.pubkeys.every(p=>(0,types_1$7.isPoint)(p)))throw new TypeError("Output is invalid");if(e.m!==void 0&&e.m!==o.m)throw new TypeError("m mismatch");if(e.n!==void 0&&e.n!==o.n)throw new TypeError("n mismatch");if(e.pubkeys&&!stacksEqual$3(e.pubkeys,o.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(o.n=e.pubkeys.length,o.n<o.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<o.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>o.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==OPS$6.OP_0)throw new TypeError("Input is invalid");if(o.signatures.length===0||!o.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!stacksEqual$3(e.signatures,o.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(o,e)}p2ms$1.p2ms=p2ms;var p2pk$1={};Object.defineProperty(p2pk$1,"__esModule",{value:!0});p2pk$1.p2pk=void 0;const networks_1$5=networks,bscript$6=script,types_1$6=types$4,lazy$5=lazy$8,OPS$5=bscript$6.OPS;function p2pk(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||{}),(0,types_1$6.typeforce)({network:types_1$6.typeforce.maybe(types_1$6.typeforce.Object),output:types_1$6.typeforce.maybe(types_1$6.typeforce.Buffer),pubkey:types_1$6.typeforce.maybe(types_1$6.isPoint),signature:types_1$6.typeforce.maybe(bscript$6.isCanonicalScriptSignature),input:types_1$6.typeforce.maybe(types_1$6.typeforce.Buffer)},e);const r=lazy$5.value(()=>bscript$6.decompile(e.input)),o={name:"p2pk",network:e.network||networks_1$5.bitcoin};if(lazy$5.prop(o,"output",()=>{if(e.pubkey)return bscript$6.compile([e.pubkey,OPS$5.OP_CHECKSIG])}),lazy$5.prop(o,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),lazy$5.prop(o,"signature",()=>{if(e.input)return r()[0]}),lazy$5.prop(o,"input",()=>{if(e.signature)return bscript$6.compile([e.signature])}),lazy$5.prop(o,"witness",()=>{if(o.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==OPS$5.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,types_1$6.isPoint)(o.pubkey))throw new TypeError("Output pubkey is invalid");if(e.pubkey&&!e.pubkey.equals(o.pubkey))throw new TypeError("Pubkey mismatch")}if(e.signature&&e.input&&!e.input.equals(o.input))throw new TypeError("Signature mismatch");if(e.input){if(r().length!==1)throw new TypeError("Input is invalid");if(!bscript$6.isCanonicalScriptSignature(o.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(o,e)}p2pk$1.p2pk=p2pk;var p2pkh$1={};Object.defineProperty(p2pkh$1,"__esModule",{value:!0});p2pkh$1.p2pkh=void 0;const bcrypto$3=crypto$1,networks_1$4=networks,bscript$5=script,types_1$5=types$4,lazy$4=lazy$8,bs58check$1=bs58check$a,OPS$4=bscript$5.OPS;function p2pkh(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||{}),(0,types_1$5.typeforce)({network:types_1$5.typeforce.maybe(types_1$5.typeforce.Object),address:types_1$5.typeforce.maybe(types_1$5.typeforce.String),hash:types_1$5.typeforce.maybe(types_1$5.typeforce.BufferN(20)),output:types_1$5.typeforce.maybe(types_1$5.typeforce.BufferN(25)),pubkey:types_1$5.typeforce.maybe(types_1$5.isPoint),signature:types_1$5.typeforce.maybe(bscript$5.isCanonicalScriptSignature),input:types_1$5.typeforce.maybe(types_1$5.typeforce.Buffer)},e);const r=lazy$4.value(()=>{const a=Buffer$e.from(bs58check$1.decode(e.address)),l=a.readUInt8(0),p=a.slice(1);return{version:l,hash:p}}),s=lazy$4.value(()=>bscript$5.decompile(e.input)),o=e.network||networks_1$4.bitcoin,n={name:"p2pkh",network:o};if(lazy$4.prop(n,"address",()=>{if(!n.hash)return;const a=Buffer$e.allocUnsafe(21);return a.writeUInt8(o.pubKeyHash,0),n.hash.copy(a,1),bs58check$1.encode(a)}),lazy$4.prop(n,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return r().hash;if(e.pubkey||n.pubkey)return bcrypto$3.hash160(e.pubkey||n.pubkey)}),lazy$4.prop(n,"output",()=>{if(n.hash)return bscript$5.compile([OPS$4.OP_DUP,OPS$4.OP_HASH160,n.hash,OPS$4.OP_EQUALVERIFY,OPS$4.OP_CHECKSIG])}),lazy$4.prop(n,"pubkey",()=>{if(e.input)return s()[1]}),lazy$4.prop(n,"signature",()=>{if(e.input)return s()[0]}),lazy$4.prop(n,"input",()=>{if(e.pubkey&&e.signature)return bscript$5.compile([e.signature,e.pubkey])}),lazy$4.prop(n,"witness",()=>{if(n.input)return[]}),t.validate){let a=Buffer$e.from([]);if(e.address){if(r().version!==o.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(r().hash.length!==20)throw new TypeError("Invalid address");a=r().hash}if(e.hash){if(a.length>0&&!a.equals(e.hash))throw new TypeError("Hash mismatch");a=e.hash}if(e.output){if(e.output.length!==25||e.output[0]!==OPS$4.OP_DUP||e.output[1]!==OPS$4.OP_HASH160||e.output[2]!==20||e.output[23]!==OPS$4.OP_EQUALVERIFY||e.output[24]!==OPS$4.OP_CHECKSIG)throw new TypeError("Output is invalid");const l=e.output.slice(3,23);if(a.length>0&&!a.equals(l))throw new TypeError("Hash mismatch");a=l}if(e.pubkey){const l=bcrypto$3.hash160(e.pubkey);if(a.length>0&&!a.equals(l))throw new TypeError("Hash mismatch");a=l}if(e.input){const l=s();if(l.length!==2)throw new TypeError("Input is invalid");if(!bscript$5.isCanonicalScriptSignature(l[0]))throw new TypeError("Input has invalid signature");if(!(0,types_1$5.isPoint)(l[1]))throw new TypeError("Input has invalid pubkey");if(e.signature&&!e.signature.equals(l[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(l[1]))throw new TypeError("Pubkey mismatch");const p=bcrypto$3.hash160(l[1]);if(a.length>0&&!a.equals(p))throw new TypeError("Hash mismatch")}}return Object.assign(n,e)}p2pkh$1.p2pkh=p2pkh;var p2sh$1={};Object.defineProperty(p2sh$1,"__esModule",{value:!0});p2sh$1.p2sh=void 0;const bcrypto$2=crypto$1,networks_1$3=networks,bscript$4=script,types_1$4=types$4,lazy$3=lazy$8,bs58check=bs58check$a,OPS$3=bscript$4.OPS;function stacksEqual$2(e,t){return e.length!==t.length?!1:e.every((r,s)=>r.equals(t[s]))}function p2sh(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||{}),(0,types_1$4.typeforce)({network:types_1$4.typeforce.maybe(types_1$4.typeforce.Object),address:types_1$4.typeforce.maybe(types_1$4.typeforce.String),hash:types_1$4.typeforce.maybe(types_1$4.typeforce.BufferN(20)),output:types_1$4.typeforce.maybe(types_1$4.typeforce.BufferN(23)),redeem:types_1$4.typeforce.maybe({network:types_1$4.typeforce.maybe(types_1$4.typeforce.Object),output:types_1$4.typeforce.maybe(types_1$4.typeforce.Buffer),input:types_1$4.typeforce.maybe(types_1$4.typeforce.Buffer),witness:types_1$4.typeforce.maybe(types_1$4.typeforce.arrayOf(types_1$4.typeforce.Buffer))}),input:types_1$4.typeforce.maybe(types_1$4.typeforce.Buffer),witness:types_1$4.typeforce.maybe(types_1$4.typeforce.arrayOf(types_1$4.typeforce.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||networks_1$3.bitcoin);const s={network:r},o=lazy$3.value(()=>{const l=Buffer$e.from(bs58check.decode(e.address)),p=l.readUInt8(0),u=l.slice(1);return{version:p,hash:u}}),n=lazy$3.value(()=>bscript$4.decompile(e.input)),a=lazy$3.value(()=>{const l=n(),p=l[l.length-1];return{network:r,output:p===OPS$3.OP_FALSE?Buffer$e.from([]):p,input:bscript$4.compile(l.slice(0,-1)),witness:e.witness||[]}});if(lazy$3.prop(s,"address",()=>{if(!s.hash)return;const l=Buffer$e.allocUnsafe(21);return l.writeUInt8(s.network.scriptHash,0),s.hash.copy(l,1),bs58check.encode(l)}),lazy$3.prop(s,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return o().hash;if(s.redeem&&s.redeem.output)return bcrypto$2.hash160(s.redeem.output)}),lazy$3.prop(s,"output",()=>{if(s.hash)return bscript$4.compile([OPS$3.OP_HASH160,s.hash,OPS$3.OP_EQUAL])}),lazy$3.prop(s,"redeem",()=>{if(e.input)return a()}),lazy$3.prop(s,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return bscript$4.compile([].concat(bscript$4.decompile(e.redeem.input),e.redeem.output))}),lazy$3.prop(s,"witness",()=>{if(s.redeem&&s.redeem.witness)return s.redeem.witness;if(s.input)return[]}),lazy$3.prop(s,"name",()=>{const l=["p2sh"];return s.redeem!==void 0&&s.redeem.name!==void 0&&l.push(s.redeem.name),l.join("-")}),t.validate){let l=Buffer$e.from([]);if(e.address){if(o().version!==r.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(o().hash.length!==20)throw new TypeError("Invalid address");l=o().hash}if(e.hash){if(l.length>0&&!l.equals(e.hash))throw new TypeError("Hash mismatch");l=e.hash}if(e.output){if(e.output.length!==23||e.output[0]!==OPS$3.OP_HASH160||e.output[1]!==20||e.output[22]!==OPS$3.OP_EQUAL)throw new TypeError("Output is invalid");const u=e.output.slice(2,22);if(l.length>0&&!l.equals(u))throw new TypeError("Hash mismatch");l=u}const p=u=>{if(u.output){const c=bscript$4.decompile(u.output);if(!c||c.length<1)throw new TypeError("Redeem.output too short");if(u.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(bscript$4.countNonPushOnlyOPs(c)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const v=bcrypto$2.hash160(u.output);if(l.length>0&&!l.equals(v))throw new TypeError("Hash mismatch");l=v}if(u.input){const c=u.input.length>0,v=u.witness&&u.witness.length>0;if(!c&&!v)throw new TypeError("Empty input");if(c&&v)throw new TypeError("Input and witness provided");if(c){const w=bscript$4.decompile(u.input);if(!bscript$4.isPushOnly(w))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const u=n();if(!u||u.length<1)throw new TypeError("Input too short");if(!Buffer$e.isBuffer(a().output))throw new TypeError("Input is invalid");p(a())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==r)throw new TypeError("Network mismatch");if(e.input){const u=a();if(e.redeem.output&&!e.redeem.output.equals(u.output))throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&!e.redeem.input.equals(u.input))throw new TypeError("Redeem.input mismatch")}p(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!stacksEqual$2(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(s,e)}p2sh$1.p2sh=p2sh;var p2wpkh$1={},dist={};Object.defineProperty(dist,"__esModule",{value:!0});dist.bech32m=dist.bech32=void 0;const ALPHABET="qpzry9x8gf2tvdw0s3jn54khce6mua7l",ALPHABET_MAP={};for(let e=0;e<ALPHABET.length;e++){const t=ALPHABET.charAt(e);ALPHABET_MAP[t]=e}function polymodStep(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 prefixChk(e){let t=1;for(let r=0;r<e.length;++r){const s=e.charCodeAt(r);if(s<33||s>126)return"Invalid prefix ("+e+")";t=polymodStep(t)^s>>5}t=polymodStep(t);for(let r=0;r<e.length;++r){const s=e.charCodeAt(r);t=polymodStep(t)^s&31}return t}function convert(e,t,r,s){let o=0,n=0;const a=(1<<r)-1,l=[];for(let p=0;p<e.length;++p)for(o=o<<t|e[p],n+=t;n>=r;)n-=r,l.push(o>>n&a);if(s)n>0&&l.push(o<<r-n&a);else{if(n>=t)return"Excess padding";if(o<<r-n&a)return"Non-zero padding"}return l}function toWords(e){return convert(e,8,5,!0)}function fromWordsUnsafe(e){const t=convert(e,5,8,!1);if(Array.isArray(t))return t}function fromWords(e){const t=convert(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function getLibraryFromEncoding(e){let t;e==="bech32"?t=1:t=734539939;function r(a,l,p){if(p=p||90,a.length+7+l.length>p)throw new TypeError("Exceeds length limit");a=a.toLowerCase();let u=prefixChk(a);if(typeof u=="string")throw new Error(u);let c=a+"1";for(let v=0;v<l.length;++v){const w=l[v];if(w>>5)throw new Error("Non 5-bit word");u=polymodStep(u)^w,c+=ALPHABET.charAt(w)}for(let v=0;v<6;++v)u=polymodStep(u);u^=t;for(let v=0;v<6;++v){const w=u>>(5-v)*5&31;c+=ALPHABET.charAt(w)}return c}function s(a,l){if(l=l||90,a.length<8)return a+" too short";if(a.length>l)return"Exceeds length limit";const p=a.toLowerCase(),u=a.toUpperCase();if(a!==p&&a!==u)return"Mixed-case string "+a;a=p;const c=a.lastIndexOf("1");if(c===-1)return"No separator character for "+a;if(c===0)return"Missing prefix for "+a;const v=a.slice(0,c),w=a.slice(c+1);if(w.length<6)return"Data too short";let b=prefixChk(v);if(typeof b=="string")return b;const E=[];for(let I=0;I<w.length;++I){const x=w.charAt(I),B=ALPHABET_MAP[x];if(B===void 0)return"Unknown character "+x;b=polymodStep(b)^B,!(I+6>=w.length)&&E.push(B)}return b!==t?"Invalid checksum for "+a:{prefix:v,words:E}}function o(a,l){const p=s(a,l);if(typeof p=="object")return p}function n(a,l){const p=s(a,l);if(typeof p=="object")return p;throw new Error(p)}return{decodeUnsafe:o,decode:n,encode:r,toWords,fromWordsUnsafe,fromWords}}dist.bech32=getLibraryFromEncoding("bech32");dist.bech32m=getLibraryFromEncoding("bech32m");Object.defineProperty(p2wpkh$1,"__esModule",{value:!0});p2wpkh$1.p2wpkh=void 0;const bcrypto$1=crypto$1,networks_1$2=networks,bscript$3=script,types_1$3=types$4,lazy$2=lazy$8,bech32_1$2=dist,OPS$2=bscript$3.OPS,EMPTY_BUFFER$1=Buffer$e.alloc(0);function p2wpkh(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||{}),(0,types_1$3.typeforce)({address:types_1$3.typeforce.maybe(types_1$3.typeforce.String),hash:types_1$3.typeforce.maybe(types_1$3.typeforce.BufferN(20)),input:types_1$3.typeforce.maybe(types_1$3.typeforce.BufferN(0)),network:types_1$3.typeforce.maybe(types_1$3.typeforce.Object),output:types_1$3.typeforce.maybe(types_1$3.typeforce.BufferN(22)),pubkey:types_1$3.typeforce.maybe(types_1$3.isPoint),signature:types_1$3.typeforce.maybe(bscript$3.isCanonicalScriptSignature),witness:types_1$3.typeforce.maybe(types_1$3.typeforce.arrayOf(types_1$3.typeforce.Buffer))},e);const r=lazy$2.value(()=>{const n=bech32_1$2.bech32.decode(e.address),a=n.words.shift(),l=bech32_1$2.bech32.fromWords(n.words);return{version:a,prefix:n.prefix,data:Buffer$e.from(l)}}),s=e.network||networks_1$2.bitcoin,o={name:"p2wpkh",network:s};if(lazy$2.prop(o,"address",()=>{if(!o.hash)return;const n=bech32_1$2.bech32.toWords(o.hash);return n.unshift(0),bech32_1$2.bech32.encode(s.bech32,n)}),lazy$2.prop(o,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return r().data;if(e.pubkey||o.pubkey)return bcrypto$1.hash160(e.pubkey||o.pubkey)}),lazy$2.prop(o,"output",()=>{if(o.hash)return bscript$3.compile([OPS$2.OP_0,o.hash])}),lazy$2.prop(o,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),lazy$2.prop(o,"signature",()=>{if(e.witness)return e.witness[0]}),lazy$2.prop(o,"input",()=>{if(o.witness)return EMPTY_BUFFER$1}),lazy$2.prop(o,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let n=Buffer$e.from([]);if(e.address){if(s&&s.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");n=r().data}if(e.hash){if(n.length>0&&!n.equals(e.hash))throw new TypeError("Hash mismatch");n=e.hash}if(e.output){if(e.output.length!==22||e.output[0]!==OPS$2.OP_0||e.output[1]!==20)throw new TypeError("Output is invalid");if(n.length>0&&!n.equals(e.output.slice(2)))throw new TypeError("Hash mismatch");n=e.output.slice(2)}if(e.pubkey){const a=bcrypto$1.hash160(e.pubkey);if(n.length>0&&!n.equals(a))throw new TypeError("Hash mismatch");if(n=a,!(0,types_1$3.isPoint)(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(!bscript$3.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,types_1$3.isPoint)(e.witness[1])||e.witness[1].length!==33)throw new TypeError("Witness has invalid pubkey");if(e.signature&&!e.signature.equals(e.witness[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(e.witness[1]))throw new TypeError("Pubkey mismatch");const a=bcrypto$1.hash160(e.witness[1]);if(n.length>0&&!n.equals(a))throw new TypeError("Hash mismatch")}}return Object.assign(o,e)}p2wpkh$1.p2wpkh=p2wpkh;var p2wsh$1={};Object.defineProperty(p2wsh$1,"__esModule",{value:!0});p2wsh$1.p2wsh=void 0;const bcrypto=crypto$1,networks_1$1=networks,bscript$2=script,types_1$2=types$4,lazy$1=lazy$8,bech32_1$1=dist,OPS$1=bscript$2.OPS,EMPTY_BUFFER=Buffer$e.alloc(0);function stacksEqual$1(e,t){return e.length!==t.length?!1:e.every((r,s)=>r.equals(t[s]))}function chunkHasUncompressedPubkey(e){return!!(Buffer$e.isBuffer(e)&&e.length===65&&e[0]===4&&(0,types_1$2.isPoint)(e))}function p2wsh(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||{}),(0,types_1$2.typeforce)({network:types_1$2.typeforce.maybe(types_1$2.typeforce.Object),address:types_1$2.typeforce.maybe(types_1$2.typeforce.String),hash:types_1$2.typeforce.maybe(types_1$2.typeforce.BufferN(32)),output:types_1$2.typeforce.maybe(types_1$2.typeforce.BufferN(34)),redeem:types_1$2.typeforce.maybe({input:types_1$2.typeforce.maybe(types_1$2.typeforce.Buffer),network:types_1$2.typeforce.maybe(types_1$2.typeforce.Object),output:types_1$2.typeforce.maybe(types_1$2.typeforce.Buffer),witness:types_1$2.typeforce.maybe(types_1$2.typeforce.arrayOf(types_1$2.typeforce.Buffer))}),input:types_1$2.typeforce.maybe(types_1$2.typeforce.BufferN(0)),witness:types_1$2.typeforce.maybe(types_1$2.typeforce.arrayOf(types_1$2.typeforce.Buffer))},e);const r=lazy$1.value(()=>{const a=bech32_1$1.bech32.decode(e.address),l=a.words.shift(),p=bech32_1$1.bech32.fromWords(a.words);return{version:l,prefix:a.prefix,data:Buffer$e.from(p)}}),s=lazy$1.value(()=>bscript$2.decompile(e.redeem.input));let o=e.network;o||(o=e.redeem&&e.redeem.network||networks_1$1.bitcoin);const n={network:o};if(lazy$1.prop(n,"address",()=>{if(!n.hash)return;const a=bech32_1$1.bech32.toWords(n.hash);return a.unshift(0),bech32_1$1.bech32.encode(o.bech32,a)}),lazy$1.prop(n,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return r().data;if(n.redeem&&n.redeem.output)return bcrypto.sha256(n.redeem.output)}),lazy$1.prop(n,"output",()=>{if(n.hash)return bscript$2.compile([OPS$1.OP_0,n.hash])}),lazy$1.prop(n,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:EMPTY_BUFFER,witness:e.witness.slice(0,-1)}}),lazy$1.prop(n,"input",()=>{if(n.witness)return EMPTY_BUFFER}),lazy$1.prop(n,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const a=bscript$2.toStack(s());return n.redeem=Object.assign({witness:a},e.redeem),n.redeem.input=EMPTY_BUFFER,[].concat(a,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),lazy$1.prop(n,"name",()=>{const a=["p2wsh"];return n.redeem!==void 0&&n.redeem.name!==void 0&&a.push(n.redeem.name),a.join("-")}),t.validate){let a=Buffer$e.from([]);if(e.address){if(r().prefix!==o.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");a=r().data}if(e.hash){if(a.length>0&&!a.equals(e.hash))throw new TypeError("Hash mismatch");a=e.hash}if(e.output){if(e.output.length!==34||e.output[0]!==OPS$1.OP_0||e.output[1]!==32)throw new TypeError("Output is invalid");const l=e.output.slice(2);if(a.length>0&&!a.equals(l))throw new TypeError("Hash mismatch");a=l}if(e.redeem){if(e.redeem.network&&e.redeem.network!==o)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 l=bscript$2.decompile(e.redeem.output);if(!l||l.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(bscript$2.countNonPushOnlyOPs(l)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const p=bcrypto.sha256(e.redeem.output);if(a.length>0&&!a.equals(p))throw new TypeError("Hash mismatch");a=p}if(e.redeem.input&&!bscript$2.isPushOnly(s()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!stacksEqual$1(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&s().some(chunkHasUncompressedPubkey)||e.redeem.output&&(bscript$2.decompile(e.redeem.output)||[]).some(chunkHasUncompressedPubkey))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(e.witness&&e.witness.length>0){const l=e.witness[e.witness.length-1];if(e.redeem&&e.redeem.output&&!e.redeem.output.equals(l))throw new TypeError("Witness and redeem.output mismatch");if(e.witness.some(chunkHasUncompressedPubkey)||(bscript$2.decompile(l)||[]).some(chunkHasUncompressedPubkey))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(n,e)}p2wsh$1.p2wsh=p2wsh;var p2tr$1={};Object.defineProperty(p2tr$1,"__esModule",{value:!0});p2tr$1.p2tr=void 0;const buffer_1=require$$0$3,networks_1=networks,bscript$1=script,types_1$1=types$4,ecc_lib_1=ecc_lib,bip341_1$1=bip341,lazy=lazy$8,bech32_1=dist,OPS=bscript$1.OPS,TAPROOT_WITNESS_VERSION=1,ANNEX_PREFIX=80;function p2tr(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||{}),(0,types_1$1.typeforce)({address:types_1$1.typeforce.maybe(types_1$1.typeforce.String),input:types_1$1.typeforce.maybe(types_1$1.typeforce.BufferN(0)),network:types_1$1.typeforce.maybe(types_1$1.typeforce.Object),output:types_1$1.typeforce.maybe(types_1$1.typeforce.BufferN(34)),internalPubkey:types_1$1.typeforce.maybe(types_1$1.typeforce.BufferN(32)),hash:types_1$1.typeforce.maybe(types_1$1.typeforce.BufferN(32)),pubkey:types_1$1.typeforce.maybe(types_1$1.typeforce.BufferN(32)),signature:types_1$1.typeforce.maybe(types_1$1.typeforce.anyOf(types_1$1.typeforce.BufferN(64),types_1$1.typeforce.BufferN(65))),witness:types_1$1.typeforce.maybe(types_1$1.typeforce.arrayOf(types_1$1.typeforce.Buffer)),scriptTree:types_1$1.typeforce.maybe(types_1$1.isTaptree),redeem:types_1$1.typeforce.maybe({output:types_1$1.typeforce.maybe(types_1$1.typeforce.Buffer),redeemVersion:types_1$1.typeforce.maybe(types_1$1.typeforce.Number),witness:types_1$1.typeforce.maybe(types_1$1.typeforce.arrayOf(types_1$1.typeforce.Buffer))}),redeemVersion:types_1$1.typeforce.maybe(types_1$1.typeforce.Number)},e);const r=lazy.value(()=>{const l=bech32_1.bech32m.decode(e.address),p=l.words.shift(),u=bech32_1.bech32m.fromWords(l.words);return{version:p,prefix:l.prefix,data:buffer_1.Buffer.from(u)}}),s=lazy.value(()=>{if(!(!e.witness||!e.witness.length))return e.witness.length>=2&&e.witness[e.witness.length-1][0]===ANNEX_PREFIX?e.witness.slice(0,-1):e.witness.slice()}),o=lazy.value(()=>{if(e.scriptTree)return(0,bip341_1$1.toHashTree)(e.scriptTree);if(e.hash)return{hash:e.hash}}),n=e.network||networks_1.bitcoin,a={name:"p2tr",network:n};if(lazy.prop(a,"address",()=>{if(!a.pubkey)return;const l=bech32_1.bech32m.toWords(a.pubkey);return l.unshift(TAPROOT_WITNESS_VERSION),bech32_1.bech32m.encode(n.bech32,l)}),lazy.prop(a,"hash",()=>{const l=o();if(l)return l.hash;const p=s();if(p&&p.length>1){const u=p[p.length-1],c=u[0]&types_1$1.TAPLEAF_VERSION_MASK,v=p[p.length-2],w=(0,bip341_1$1.tapleafHash)({output:v,version:c});return(0,bip341_1$1.rootHashFromPath)(u,w)}return null}),lazy.prop(a,"output",()=>{if(a.pubkey)return bscript$1.compile([OPS.OP_1,a.pubkey])}),lazy.prop(a,"redeemVersion",()=>e.redeemVersion?e.redeemVersion:e.redeem&&e.redeem.redeemVersion!==void 0&&e.redeem.redeemVersion!==null?e.redeem.redeemVersion:bip341_1$1.LEAF_VERSION_TAPSCRIPT),lazy.prop(a,"redeem",()=>{const l=s();if(!(!l||l.length<2))return{output:l[l.length-2],witness:l.slice(0,-2),redeemVersion:l[l.length-1][0]&types_1$1.TAPLEAF_VERSION_MASK}}),lazy.prop(a,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.output)return e.output.slice(2);if(e.address)return r().data;if(a.internalPubkey){const l=(0,bip341_1$1.tweakKey)(a.internalPubkey,a.hash);if(l)return l.x}}),lazy.prop(a,"internalPubkey",()=>{if(e.internalPubkey)return e.internalPubkey;const l=s();if(l&&l.length>1)return l[l.length-1].slice(1,33)}),lazy.prop(a,"signature",()=>{if(e.signature)return e.signature;const l=s();if(!(!l||l.length!==1))return l[0]}),lazy.prop(a,"witness",()=>{if(e.witness)return e.witness;const l=o();if(l&&e.redeem&&e.redeem.output&&e.internalPubkey){const p=(0,bip341_1$1.tapleafHash)({output:e.redeem.output,version:a.redeemVersion}),u=(0,bip341_1$1.findScriptPath)(l,p);if(!u)return;const c=(0,bip341_1$1.tweakKey)(e.internalPubkey,l.hash);if(!c)return;const v=buffer_1.Buffer.concat([buffer_1.Buffer.from([a.redeemVersion|c.parity]),e.internalPubkey].concat(u));return[e.redeem.output,v]}if(e.signature)return[e.signature]}),t.validate){let l=buffer_1.Buffer.from([]);if(e.address){if(n&&n.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==TAPROOT_WITNESS_VERSION)throw new TypeError("Invalid address version");if(r().data.length!==32)throw new TypeError("Invalid address data");l=r().data}if(e.pubkey){if(l.length>0&&!l.equals(e.pubkey))throw new TypeError("Pubkey mismatch");l=e.pubkey}if(e.output){if(e.output.length!==34||e.output[0]!==OPS.OP_1||e.output[1]!==32)throw new TypeError("Output is invalid");if(l.length>0&&!l.equals(e.output.slice(2)))throw new TypeError("Pubkey mismatch");l=e.output.slice(2)}if(e.internalPubkey){const c=(0,bip341_1$1.tweakKey)(e.internalPubkey,a.hash);if(l.length>0&&!l.equals(c.x))throw new TypeError("Pubkey mismatch");l=c.x}if(l&&l.length&&!(0,ecc_lib_1.getEccLib)().isXOnlyPoint(l))throw new TypeError("Invalid pubkey for p2tr");const p=o();if(e.hash&&p&&!e.hash.equals(p.hash))throw new TypeError("Hash mismatch");if(e.redeem&&e.redeem.output&&p){const c=(0,bip341_1$1.tapleafHash)({output:e.redeem.output,version:a.redeemVersion});if(!(0,bip341_1$1.findScriptPath)(p,c))throw new TypeError("Redeem script not in tree")}const u=s();if(e.redeem&&a.redeem){if(e.redeem.redeemVersion&&e.redeem.redeemVersion!==a.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(e.redeem.output){if(bscript$1.decompile(e.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(a.redeem.output&&!e.redeem.output.equals(a.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(e.redeem.witness&&a.redeem.witness&&!stacksEqual(e.redeem.witness,a.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(u&&u.length)if(u.length===1){if(e.signature&&!e.signature.equals(u[0]))throw new TypeError("Signature mismatch")}else{const c=u[u.length-1];if(c.length<33)throw new TypeError(`The control-block length is too small. Got ${c.length}, expected min 33.`);if((c.length-33)%32!==0)throw new TypeError(`The control-block length of ${c.length} is incorrect!`);const v=(c.length-33)/32;if(v>128)throw new TypeError(`The script path is too long. Got ${v}, expected max 128.`);const w=c.slice(1,33);if(e.internalPubkey&&!e.internalPubkey.equals(w))throw new TypeError("Internal pubkey mismatch");if(!(0,ecc_lib_1.getEccLib)().isXOnlyPoint(w))throw new TypeError("Invalid internalPubkey for p2tr witness");const b=c[0]&types_1$1.TAPLEAF_VERSION_MASK,E=u[u.length-2],I=(0,bip341_1$1.tapleafHash)({output:E,version:b}),x=(0,bip341_1$1.rootHashFromPath)(c,I),B=(0,bip341_1$1.tweakKey)(w,x);if(!B)throw new TypeError("Invalid outputKey for p2tr witness");if(l.length&&!l.equals(B.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(B.parity!==(c[0]&1))throw new Error("Incorrect parity")}}return Object.assign(a,e)}p2tr$1.p2tr=p2tr;function stacksEqual(e,t){return e.length!==t.length?!1:e.every((r,s)=>r.equals(t[s]))}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.p2tr=e.p2wsh=e.p2wpkh=e.p2sh=e.p2pkh=e.p2pk=e.p2ms=e.embed=void 0;const t=embed;Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const r=p2ms$1;Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return r.p2ms}});const s=p2pk$1;Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return s.p2pk}});const o=p2pkh$1;Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return o.p2pkh}});const n=p2sh$1;Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return n.p2sh}});const a=p2wpkh$1;Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return a.p2wpkh}});const l=p2wsh$1;Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return l.p2wsh}});const p=p2tr$1;Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return p.p2tr}})})(payments$1);Object.defineProperty(psbtutils,"__esModule",{value:!0});psbtutils.signatureBlocksAction=psbtutils.checkInputForSig=pubkeyInScript_1=psbtutils.pubkeyInScript=psbtutils.pubkeyPositionInScript=psbtutils.witnessStackToScriptWitness=psbtutils.isP2TR=psbtutils.isP2SHScript=psbtutils.isP2WSHScript=psbtutils.isP2WPKH=psbtutils.isP2PKH=psbtutils.isP2PK=psbtutils.isP2MS=void 0;const varuint=varint,bscript=script,transaction_1$1=transaction,crypto_1=crypto$1,payments=payments$1;function isPaymentFactory(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}psbtutils.isP2MS=isPaymentFactory(payments.p2ms);psbtutils.isP2PK=isPaymentFactory(payments.p2pk);psbtutils.isP2PKH=isPaymentFactory(payments.p2pkh);psbtutils.isP2WPKH=isPaymentFactory(payments.p2wpkh);psbtutils.isP2WSHScript=isPaymentFactory(payments.p2wsh);psbtutils.isP2SHScript=isPaymentFactory(payments.p2sh);psbtutils.isP2TR=isPaymentFactory(payments.p2tr);function witnessStackToScriptWitness(e){let t=Buffer$e.allocUnsafe(0);function r(a){t=Buffer$e.concat([t,Buffer$e.from(a)])}function s(a){const l=t.length,p=varuint.encodingLength(a);t=Buffer$e.concat([t,Buffer$e.allocUnsafe(p)]),varuint.encode(a,t,l)}function o(a){s(a.length),r(a)}function n(a){s(a.length),a.forEach(o)}return n(e),t}psbtutils.witnessStackToScriptWitness=witnessStackToScriptWitness;function pubkeyPositionInScript(e,t){const r=(0,crypto_1.hash160)(e),s=e.slice(1,33),o=bscript.decompile(t);if(o===null)throw new Error("Unknown script error");return o.findIndex(n=>typeof n=="number"?!1:n.equals(e)||n.equals(r)||n.equals(s))}psbtutils.pubkeyPositionInScript=pubkeyPositionInScript;function pubkeyInScript(e,t){return pubkeyPositionInScript(e,t)!==-1}var pubkeyInScript_1=psbtutils.pubkeyInScript=pubkeyInScript;function checkInputForSig(e,t){return extractPartialSigs(e).some(s=>signatureBlocksAction(s,bscript.signature.decode,t))}psbtutils.checkInputForSig=checkInputForSig;function signatureBlocksAction(e,t,r){const{hashType:s}=t(e),o=[];switch(s&transaction_1$1.Transaction.SIGHASH_ANYONECANPAY&&o.push("addInput"),s&31){case transaction_1$1.Transaction.SIGHASH_ALL:break;case transaction_1$1.Transaction.SIGHASH_SINGLE:case transaction_1$1.Transaction.SIGHASH_NONE:o.push("addOutput"),o.push("setInputSequence");break}return o.indexOf(r)===-1}psbtutils.signatureBlocksAction=signatureBlocksAction;function extractPartialSigs(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=getPsigsFromInputFinalScripts(e)}else t=e.partialSig;return t.map(r=>r.signature)}function getPsigsFromInputFinalScripts(e){const t=e.finalScriptSig?bscript.decompile(e.finalScriptSig)||[]:[],r=e.finalScriptWitness?bscript.decompile(e.finalScriptWitness)||[]:[];return t.concat(r).filter(s=>Buffer$e.isBuffer(s)&&bscript.isCanonicalScriptSignature(s)).map(s=>({signature:s}))}Object.defineProperty(bip371,"__esModule",{value:!0});bip371.checkTaprootInputForSigs=bip371.tapTreeFromList=bip371.tapTreeToList=bip371.tweakInternalPubKey=bip371.checkTaprootOutputFields=bip371.checkTaprootInputFields=bip371.isTaprootOutput=bip371.isTaprootInput=bip371.serializeTaprootSignature=bip371.tapScriptFinalizer=toXOnly_1=bip371.toXOnly=void 0;const types_1=types$4,transaction_1=transaction,psbtutils_1=psbtutils,bip341_1=bip341,payments_1=payments$1,psbtutils_2=psbtutils,toXOnly=e=>e.length===32?e:e.slice(1,33);var toXOnly_1=bip371.toXOnly=toXOnly;function tapScriptFinalizer(e,t,r){const s=findTapLeafToFinalize(t,e,r);try{const n=sortSignatures(t,s).concat(s.script).concat(s.controlBlock);return{finalScriptWitness:(0,psbtutils_1.witnessStackToScriptWitness)(n)}}catch(o){throw new Error(`Can not finalize taproot input #${e}: ${o}`)}}bip371.tapScriptFinalizer=tapScriptFinalizer;function serializeTaprootSignature(e,t){const r=t?Buffer$e.from([t]):Buffer$e.from([]);return Buffer$e.concat([e,r])}bip371.serializeTaprootSignature=serializeTaprootSignature;function isTaprootInput(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&(0,psbtutils_1.isP2TR)(e.witnessUtxo.script))}bip371.isTaprootInput=isTaprootInput;function isTaprootOutput(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t&&(0,psbtutils_1.isP2TR)(t))}bip371.isTaprootOutput=isTaprootOutput;function checkTaprootInputFields(e,t,r){checkMixedTaprootAndNonTaprootInputFields(e,t,r),checkIfTapLeafInTree(e,t,r)}bip371.checkTaprootInputFields=checkTaprootInputFields;function checkTaprootOutputFields(e,t,r){checkMixedTaprootAndNonTaprootOutputFields(e,t,r),checkTaprootScriptPubkey(e,t)}bip371.checkTaprootOutputFields=checkTaprootOutputFields;function checkTaprootScriptPubkey(e,t){if(!t.tapTree&&!t.tapInternalKey)return;const r=t.tapInternalKey||e.tapInternalKey,s=t.tapTree||e.tapTree;if(r){const{script:o}=e,n=getTaprootScripPubkey(r,s);if(o&&!o.equals(n))throw new Error("Error adding output. Script or address missmatch.")}}function getTaprootScripPubkey(e,t){const r=t&&tapTreeFromList(t.leaves),{output:s}=(0,payments_1.p2tr)({internalPubkey:e,scriptTree:r});return s}function tweakInternalPubKey(e,t){const r=t.tapInternalKey,s=r&&(0,bip341_1.tweakKey)(r,t.tapMerkleRoot);if(!s)throw new Error(`Cannot tweak tap internal key for input #${e}. Public key: ${r&&r.toString("hex")}`);return s.x}bip371.tweakInternalPubKey=tweakInternalPubKey;function tapTreeToList(e){if(!(0,types_1.isTaptree)(e))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return _tapTreeToList(e)}bip371.tapTreeToList=tapTreeToList;function tapTreeFromList(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:instertLeavesInTree(e)}bip371.tapTreeFromList=tapTreeFromList;function checkTaprootInputForSigs(e,t){return extractTaprootSigs(e).some(s=>(0,psbtutils_2.signatureBlocksAction)(s,decodeSchnorrSignature,t))}bip371.checkTaprootInputForSigs=checkTaprootInputForSigs;function decodeSchnorrSignature(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||transaction_1.Transaction.SIGHASH_DEFAULT}}function extractTaprootSigs(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(r=>r.signature)),!t.length){const r=getTapKeySigFromWithness(e.finalScriptWitness);r&&t.push(r)}return t}function getTapKeySigFromWithness(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function _tapTreeToList(e,t=[],r=0){if(r>bip341_1.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return e?(0,types_1.isTapleaf)(e)?(t.push({depth:r,leafVersion:e.version||bip341_1.LEAF_VERSION_TAPSCRIPT,script:e.output}),t):(e[0]&&_tapTreeToList(e[0],t,r+1),e[1]&&_tapTreeToList(e[1],t,r+1),t):[]}function instertLeavesInTree(e){let t;for(const r of e)if(t=instertLeafInTree(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function instertLeafInTree(e,t,r=0){if(r>bip341_1.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");if(e.depth===r)return t?void 0:{output:e.script,version:e.leafVersion};if((0,types_1.isTapleaf)(t))return;const s=instertLeafInTree(e,t&&t[0],r+1);if(s)return[s,t&&t[1]];const o=instertLeafInTree(e,t&&t[1],r+1);if(o)return[t&&t[0],o]}function checkMixedTaprootAndNonTaprootInputFields(e,t,r){const s=isTaprootInput(e)&&hasNonTaprootFields(t),o=hasNonTaprootFields(e)&&isTaprootInput(t),n=e===t&&isTaprootInput(t)&&hasNonTaprootFields(t);if(s||o||n)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function checkMixedTaprootAndNonTaprootOutputFields(e,t,r){const s=isTaprootOutput(e)&&hasNonTaprootFields(t),o=hasNonTaprootFields(e)&&isTaprootOutput(t),n=e===t&&isTaprootOutput(t)&&hasNonTaprootFields(t);if(s||o||n)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function checkIfTapLeafInTree(e,t,r){if(t.tapMerkleRoot){const s=(t.tapLeafScript||[]).every(n=>isTapLeafInTree(n,t.tapMerkleRoot)),o=(e.tapLeafScript||[]).every(n=>isTapLeafInTree(n,t.tapMerkleRoot));if(!s||!o)throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}else if(e.tapMerkleRoot&&!(t.tapLeafScript||[]).every(o=>isTapLeafInTree(o,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}function isTapLeafInTree(e,t){if(!t)return!0;const r=(0,bip341_1.tapleafHash)({output:e.script,version:e.leafVersion});return(0,bip341_1.rootHashFromPath)(e.controlBlock,r).equals(t)}function sortSignatures(e,t){const r=(0,bip341_1.tapleafHash)({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(s=>s.leafHash.equals(r)).map(s=>addPubkeyPositionInScript(t.script,s)).sort((s,o)=>o.positionInScript-s.positionInScript).map(s=>s.signature)}function addPubkeyPositionInScript(e,t){return Object.assign({positionInScript:(0,psbtutils_1.pubkeyPositionInScript)(t.pubkey,e)},t)}function findTapLeafToFinalize(e,t,r){if(!e.tapScriptSig||!e.tapScriptSig.length)throw new Error(`Can not finalize taproot input #${t}. No tapleaf script signature provided.`);const s=(e.tapLeafScript||[]).sort((o,n)=>o.controlBlock.length-n.controlBlock.length).find(o=>canFinalizeLeaf(o,e.tapScriptSig,r));if(!s)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return s}function canFinalizeLeaf(e,t,r){const s=(0,bip341_1.tapleafHash)({output:e.script,version:e.leafVersion});return(!r||r.equals(s))&&t.find(n=>n.leafHash.equals(s))!==void 0}function hasNonTaprootFields(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const byteToHex=[];for(let e=0;e<256;++e)byteToHex.push((e+256).toString(16).slice(1));function unsafeStringify(e,t=0){return(byteToHex[e[t+0]]+byteToHex[e[t+1]]+byteToHex[e[t+2]]+byteToHex[e[t+3]]+"-"+byteToHex[e[t+4]]+byteToHex[e[t+5]]+"-"+byteToHex[e[t+6]]+byteToHex[e[t+7]]+"-"+byteToHex[e[t+8]]+byteToHex[e[t+9]]+"-"+byteToHex[e[t+10]]+byteToHex[e[t+11]]+byteToHex[e[t+12]]+byteToHex[e[t+13]]+byteToHex[e[t+14]]+byteToHex[e[t+15]]).toLowerCase()}let getRandomValues;const rnds8=new Uint8Array(16);function rng(){if(!getRandomValues){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");getRandomValues=crypto.getRandomValues.bind(crypto)}return getRandomValues(rnds8)}const randomUUID=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),native={randomUUID};function v4(e,t,r){var o;if(native.randomUUID&&!t&&!e)return native.randomUUID();e=e||{};const s=e.random??((o=e.rng)==null?void 0:o.call(e))??rng();if(s.length<16)throw new Error("Random bytes length must be >= 16");return s[6]=s[6]&15|64,s[8]=s[8]&63|128,unsafeStringify(s)}const COMPRESSED_PUBLIC_KEY_HEX_LENGTH=66,NETWORKS={[Network.MAINNET]:{name:"Mainnet",config:bitcoinjsLib.networks.bitcoin,addressPrefix:{common:"bc1",nativeSegWit:"bc1q",taproot:"bc1p"}},[Network.CANARY]:{name:"Canary",config:bitcoinjsLib.networks.bitcoin,addressPrefix:{common:"bc1",nativeSegWit:"bc1q",taproot:"bc1p"}},[Network.TESTNET]:{name:"Testnet",config:bitcoinjsLib.networks.testnet,addressPrefix:{common:"tb1",nativeSegWit:"tb1q",taproot:"tb1p"}},[Network.SIGNET]:{name:"Signet",config:bitcoinjsLib.networks.testnet,addressPrefix:{common:"tb1",nativeSegWit:"tb1q",taproot:"tb1p"}}},getTaprootAddress=(e,t)=>{e.length==COMPRESSED_PUBLIC_KEY_HEX_LENGTH&&(e=e.slice(2));const r=Buffer$e.from(e,"hex"),{address:s,output:o}=bitcoinjsLib.payments.p2tr({internalPubkey:toXOnly_1(r),network:NETWORKS[t].config});if(!s||!o)throw new Error("Failed to generate taproot address or script from public key");return s},getNativeSegwitAddress=(e,t)=>{if(e.length!==COMPRESSED_PUBLIC_KEY_HEX_LENGTH)throw new Error("Invalid public key length for generating native segwit address");const r=Buffer$e.from(e,"hex"),{address:s,output:o}=bitcoinjsLib.payments.p2wpkh({pubkey:r,network:NETWORKS[t].config});if(!s||!o)throw new Error("Failed to generate native segwit address or script from public key");return s};function validateAddressWithPK(e,t,r){return e.startsWith(NETWORKS[r].addressPrefix.taproot)?e===getTaprootAddress(t,r):e.startsWith(NETWORKS[r].addressPrefix.nativeSegWit)?e===getNativeSegwitAddress(t,r):!1}function validateAddress(e,t){const{addressPrefix:r,name:s}=NETWORKS[e];if(!(e in NETWORKS))throw new Error(`Unsupported network: ${e}. Please provide a valid network.`);if(!t.startsWith(r.common))throw new Error(`Incorrect address prefix for ${s}. Expected address to start with '${r}'.`)}const toNetwork=e=>NETWORKS[e].config,WALLET_PROVIDER_NAME$3="Keystone";class KeystoneProvider{constructor(t,r){at(this,"keystoneWaleltInfo");at(this,"viewSDK");at(this,"dataSdk");at(this,"config");at(this,"connectWallet",async()=>{const r=await(await this.viewSDK.getSdk()).read([sdk$1.SupportedResult.UR_CRYPTO_ACCOUNT],{title:"Sync Keystone with Babylon Staking App",description:"Please scan the QR code displayed on your Keystone, Currently only the first Taproot Address will be used",renderInitial:{walletMode:"btc",link:"",description:["1. Turn on your Keystone 3 with BTC only firmware.",'2. Click connect software wallet and use "Sparrow" for connection.','3. Press the "Sync Keystone" button and scan the QR Code displayed on your Keystone hardware wallet',"4. The first Taproot address will be used for staking."]},URTypeErrorMessage:"The scanned QR code is not the sync code from the Keystone hardware wallet. Please verify the code and try again."});if(r.status===sdk$1.ReadStatus.canceled)throw new Error("Connection to Keystone was canceled");if(r.status!==sdk$1.ReadStatus.success)throw new Error("Error reading QR code, Please try again.");const s=this.dataSdk.parseAccount(r.result),o=3,n=s.keys[o].extendedPublicKey;if(this.keystoneWaleltInfo={mfp:s.masterFingerprint,extendedPublicKey:n,path:s.keys[o].path,address:void 0,publicKeyHex:void 0,scriptPubKeyHex:void 0},!this.keystoneWaleltInfo.extendedPublicKey)throw new Error("Could not retrieve the extended public key");const{address:a,pubkeyHex:l,scriptPubKeyHex:p}=generateP2trAddressFromXpub(this.keystoneWaleltInfo.extendedPublicKey,"M/0/0",toNetwork(this.config.network));this.keystoneWaleltInfo.address=a,this.keystoneWaleltInfo.publicKeyHex=l,this.keystoneWaleltInfo.scriptPubKeyHex=p});at(this,"getAddress",async()=>{var t;if(!((t=this.keystoneWaleltInfo)!=null&&t.address))throw new Error("Could not retrieve the address");return this.keystoneWaleltInfo.address});at(this,"getPublicKeyHex",async()=>{var t;if(!((t=this.keystoneWaleltInfo)!=null&&t.publicKeyHex))throw new Error("Could not retrieve the BTC public key");return this.keystoneWaleltInfo.publicKeyHex});at(this,"signPsbt",async t=>{var n,a;if(!((n=this.keystoneWaleltInfo)!=null&&n.address)||!((a=this.keystoneWaleltInfo)!=null&&a.publicKeyHex))throw new Error("Keystone Wallet not connected");if(!t)throw new Error("psbt hex is required");let r=bitcoinjsLib.Psbt.fromHex(t);r=this.enhancePsbt(r);const s=r.toHex();return(await this.sign(s)).toHex()});at(this,"signPsbts",async t=>{var s,o;if(!((s=this.keystoneWaleltInfo)!=null&&s.address)||!((o=this.keystoneWaleltInfo)!=null&&o.publicKeyHex))throw new Error("Keystone Wallet not connected");if(!t&&!Array.isArray(t))throw new Error("psbts hexes are required");const r=[];for(const n of t){const a=await this.signPsbt(n);r.push(a)}return r});at(this,"getNetwork",async()=>this.config.network);at(this,"signMessage",async(t,r)=>{if(r!=="ecdsa")throw new Error("Only ECDSA signature is supported");if(!this.keystoneWaleltInfo)throw new Error("Keystone Wallet not connected");const s=this.dataSdk.btc.generateSignRequest({requestId:v4(),signData:Buffer$1$1.from(t,"utf-8").toString("hex"),dataType:dist$v.KeystoneBitcoinSDK.DataType.message,accounts:[{path:`${this.keystoneWaleltInfo.path}/0/0`,xfp:`${this.keystoneWaleltInfo.mfp}`,address:this.keystoneWaleltInfo.address}],origin:"babylon staking app"}),o=composeQRProcess(sdk$1.SupportedResult.UR_BTC_SIGNATURE),n=await this.viewSDK.getSdk(),a=await o(n,s),l=this.dataSdk.btc.parseSignature(a);return Buffer$1$1.from(l.signature,"hex").toString("base64")});at(this,"getInscriptions",async()=>{throw new Error("Method not implemented.")});at(this,"on",()=>{});at(this,"off",()=>{});at(this,"getWalletProviderName",async()=>WALLET_PROVIDER_NAME$3);at(this,"getWalletProviderIcon",async()=>logo$3);at(this,"sign",async t=>{if(!t)throw new Error("psbt hex is required");const r=this.dataSdk.btc.generatePSBT(Buffer$1$1.from(t,"hex")),s=composeQRProcess(sdk$1.SupportedResult.UR_PSBT),o=await this.viewSDK.getSdk(),n=await s(o,r),a=this.dataSdk.btc.parsePSBT(n),l=bitcoinjsLib.Psbt.fromHex(a);return l.finalizeAllInputs(),l});at(this,"enhancePsbt",t=>{var s,o,n,a;if(!((s=this.keystoneWaleltInfo)!=null&&s.scriptPubKeyHex)||!((o=this.keystoneWaleltInfo)!=null&&o.publicKeyHex)||!((n=this.keystoneWaleltInfo)!=null&&n.mfp)||!((a=this.keystoneWaleltInfo)!=null&&a.path))throw new Error("Keystone Wallet not connected");const r={masterFingerprint:Buffer$1$1.from(this.keystoneWaleltInfo.mfp,"hex"),path:`${this.keystoneWaleltInfo.path}/0/0`,pubkey:Buffer$1$1.from(this.keystoneWaleltInfo.publicKeyHex,"hex")};return t.data.inputs.forEach(l=>{l.tapBip32Derivation=[{...r,pubkey:toXOnly_1(r.pubkey),leafHashes:caculateTapLeafHash(l,r.pubkey)}]}),t});this.config=r,sdk$1.viewSdk.bootstrap(),this.viewSDK=sdk$1.viewSdk,this.dataSdk=new dist$v.KeystoneSDK({origin:"babylon staking app"})}}const composeQRProcess=e=>async(t,r)=>{if(await t.play(r,{title:"Scan the QR Code",description:"Please scan the QR code with your Keystone device."})!==sdk$1.PlayStatus.success)throw new Error("Could not generate the QR code, please try again.");const o=await t.read([e],{title:"Get the Signature from Keystone",description:"Please scan the QR code displayed on your Keystone",URTypeErrorMessage:"The scanned QR code can't be read. please verify and try again."});if(o.status!==sdk$1.ReadStatus.success)throw new Error("Could not extract the signature, please try again.");return o.result},generateP2trAddressFromXpub=(e,t,r)=>{const o=HDKey.fromExtendedKey(e).derive(t),n=Buffer$1$1.from(o.publicKey),a=toXOnly_1(n);let l,p;try{const u=bitcoinjsLib.payments.p2tr({internalPubkey:a,network:r});l=u.address,p=u.output}catch(u){if(u instanceof Error&&u.message.includes("ECC")){btcStakingTs.initBTCCurve();const c=bitcoinjsLib.payments.p2tr({internalPubkey:a,network:r});l=c.address,p=c.output}else throw new Error(u)}return{address:l,pubkeyHex:n.toString("hex"),scriptPubKeyHex:p.toString("hex")}},caculateTapLeafHash=(e,t)=>e.tapInternalKey&&!e.tapLeafScript?[]:(e.tapLeafScript||[]).filter(s=>pubkeyInScript_1(t,s.script)).map(s=>{const o=bip341.tapleafHash({output:s.script,version:s.leafVersion});return Object.assign({hash:o},s)}).map(s=>s.hash),metadata$5={id:"keystone",name:WALLET_PROVIDER_NAME$3,icon:logo$3,docs:"https://www.keyst.one/btc-only",createProvider:(e,t)=>new KeystoneProvider(e,t),networks:[Network.MAINNET,Network.SIGNET],label:"Hardware wallet"},logo$2="data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='UTF-8'?%3e%3csvg%20width='225px'%20height='224px'%20viewBox='0%200%20225%20224'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3ctitle%3eokx%3c/title%3e%3cg%20id='Page-1'%20stroke='none'%20strokeWidth='1'%20fill='none'%20fill-rule='evenodd'%3e%3cg%20id='okx'%20transform='translate(0.401000,%200.006000)'%20fill='%23000000'%20fill-rule='nonzero'%3e%3cpath%20d='M144.382,74.667%20L79.673,74.667%20C76.924,74.667%2074.695,76.895%2074.695,79.644%20L74.695,144.354%20C74.695,147.103%2076.924,149.332%2079.673,149.332%20L144.382,149.332%20C147.131,149.332%20149.36,147.103%20149.36,144.354%20L149.36,79.644%20C149.36,76.895%20147.131,74.667%20144.382,74.667%20Z'%20id='Path'%3e%3c/path%3e%3cpath%20d='M69.687,0%20L4.978,0%20C2.229,0%200,2.228%200,4.978%20L0,69.687%20C0,72.436%202.229,74.665%204.978,74.665%20L69.687,74.665%20C72.437,74.665%2074.665,72.436%2074.665,69.687%20L74.665,4.978%20C74.665,2.228%2072.437,0%2069.687,0%20Z'%20id='Path'%3e%3c/path%3e%3cpath%20d='M219.017,0%20L154.307,0%20C151.558,0%20149.329,2.228%20149.329,4.978%20L149.329,69.687%20C149.329,72.436%20151.558,74.665%20154.307,74.665%20L219.017,74.665%20C221.766,74.665%20223.994,72.436%20223.994,69.687%20L223.994,4.978%20C223.994,2.228%20221.766,0%20219.017,0%20Z'%20id='Path'%3e%3c/path%3e%3cpath%20d='M69.687,149.328%20L4.978,149.328%20C2.229,149.328%200,151.556%200,154.305%20L0,219.015%20C0,221.764%202.229,223.993%204.978,223.993%20L69.687,223.993%20C72.437,223.993%2074.665,221.764%2074.665,219.015%20L74.665,154.305%20C74.665,151.556%2072.437,149.328%2069.687,149.328%20Z'%20id='Path'%3e%3c/path%3e%3cpath%20d='M219.017,149.328%20L154.307,149.328%20C151.558,149.328%20149.329,151.556%20149.329,154.305%20L149.329,219.015%20C149.329,221.764%20151.558,223.993%20154.307,223.993%20L219.017,223.993%20C221.766,223.993%20223.994,221.764%20223.994,219.015%20L223.994,154.305%20C223.994,151.556%20221.766,149.328%20219.017,149.328%20Z'%20id='Path'%3e%3c/path%3e%3c/g%3e%3c/g%3e%3c/svg%3e",PROVIDER_NAMES={[Network.MAINNET]:"bitcoin",[Network.CANARY]:"bitcoin",[Network.TESTNET]:"bitcoinTestnet",[Network.SIGNET]:"bitcoinSignet"},WALLET_PROVIDER_NAME$2="OKX";class OKXProvider{constructor(t,r){at(this,"provider");at(this,"walletInfo");at(this,"config");at(this,"connectWallet",async()=>{var o;try{await this.wallet.enable()}catch(n){throw(o=n==null?void 0:n.message)!=null&&o.includes("rejected")?new Error("Connection to OKX Wallet was rejected"):new Error(n==null?void 0:n.message)}let t;try{t=await this.provider.connect()}catch{throw new Error(`BTC ${this.config.network} is not enabled in OKX Wallet`)}const{address:r,compressedPublicKey:s}=t;if(validateAddress(this.config.network,r),s&&r)this.walletInfo={publicKeyHex:s,address:r};else throw new Error("Could not connect to OKX Wallet")});at(this,"getAddress",async()=>{if(!this.walletInfo)throw new Error("OKX Wallet not connected");return this.walletInfo.address});at(this,"getPublicKeyHex",async()=>{if(!this.walletInfo)throw new Error("OKX Wallet not connected");return this.walletInfo.publicKeyHex});at(this,"signPsbt",async t=>{if(!this.walletInfo)throw new Error("OKX Wallet not connected");return await this.provider.signPsbt(t)});at(this,"signPsbts",async t=>{if(!this.walletInfo)throw new Error("OKX Wallet not connected");return await this.provider.signPsbts(t)});at(this,"getNetwork",async()=>{if(!this.config.network)throw new Error("Network not set");return this.config.network});at(this,"signMessage",async(t,r)=>{if(!this.walletInfo)throw new Error("OKX Wallet not connected");return await this.provider.signMessage(t,r)});at(this,"getInscriptions",async()=>{if(!this.walletInfo)throw new Error("OKX Wallet not connected");if(this.config.network!==Network.MAINNET)throw new Error("Inscriptions are only available on OKX Wallet BTC mainnet");const t=100,r=100,s=[];let o=0,n=0;try{for(;n<t;){const{list:a}=await this.provider.getInscriptions(o,r),l=a.map(p=>{const[u,c]=p.output.split(":");return{txid:u,vout:c}});if(s.push(...l),a.length<r)break;if(o+=r,n++,n>=t)throw new Error("Exceeded maximum iterations when fetching inscriptions")}}catch{throw new Error("Failed to get inscriptions from OKX Wallet")}return s});at(this,"on",(t,r)=>{if(!this.walletInfo)throw new Error("OKX Wallet not connected");if(t==="accountChanged")return this.provider.on(t,r)});at(this,"off",(t,r)=>{if(!this.walletInfo)throw new Error("OKX Wallet not connected");if(t==="accountChanged")return this.provider.off(t,r)});at(this,"getWalletProviderName",async()=>WALLET_PROVIDER_NAME$2);at(this,"getWalletProviderIcon",async()=>logo$2);if(this.wallet=t,this.config=r,!t)throw new Error("OKX Wallet extension not found");const s=PROVIDER_NAMES[r.network];if(!s)throw new Error("Unsupported network");this.provider=t[s]}}const metadata$4={id:"okx",name:WALLET_PROVIDER_NAME$2,icon:logo$2,docs:"https://www.okx.com/web3",wallet:"okxwallet",createProvider:(e,t)=>new OKXProvider(e,t),networks:[Network.MAINNET,Network.SIGNET]},logo$1="data:image/svg+xml,%3csvg%20width='128'%20height='128'%20viewBox='0%200%20128%20128'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20clip-path='url(%23clip0_45922_88)'%3e%3cpath%20d='M127.61%2063.8049C127.61%20107.853%20107.853%20127.61%2063.8049%20127.61C19.7568%20127.61%200%20107.853%200%2063.8049C0%2019.7568%2019.7568%200%2063.8049%200C107.853%200%20127.61%2019.7568%20127.61%2063.8049Z'%20fill='%233BD23D'/%3e%3cpath%20d='M69.5699%2027.0557L51.8197%2027.0557L48.7056%2036.4719H58.5645L58.5645%2056.3063H69.5699V27.0557Z'%20fill='black'/%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M84.0486%2080.3111C84.0486%2091.4912%2074.9854%20100.554%2063.8053%20100.554C52.6253%20100.554%2043.5621%2091.4912%2043.5621%2080.3111C43.5621%2069.1311%2052.6253%2060.0678%2063.8053%2060.0678C74.9854%2060.0678%2084.0486%2069.1311%2084.0486%2080.3111ZM74.8584%2080.3111C74.8584%2086.4155%2069.9097%2091.3641%2063.8053%2091.3641C57.7008%2091.3641%2052.7522%2086.4155%2052.7522%2080.3111C52.7522%2074.2066%2057.7008%2069.258%2063.8053%2069.258C69.9097%2069.258%2074.8584%2074.2066%2074.8584%2080.3111Z'%20fill='black'/%3e%3c/g%3e%3cdefs%3e%3cclipPath%20id='clip0_45922_88'%3e%3crect%20width='128'%20height='128'%20fill='white'/%3e%3c/clipPath%3e%3c/defs%3e%3c/svg%3e",INTERNAL_NETWORK_NAMES={[Network.MAINNET]:"livenet",[Network.TESTNET]:"testnet",[Network.SIGNET]:"signet"},WALLET_PROVIDER_NAME$1="OneKey";class OneKeyProvider{constructor(t,r){at(this,"provider");at(this,"walletInfo");at(this,"config");at(this,"connectWallet",async()=>{var s;try{await this.provider.connectWallet()}catch(o){throw(s=o==null?void 0:o.message)!=null&&s.includes("rejected")?new Error("Connection to OneKey Wallet was rejected"):new Error(o==null?void 0:o.message)}const t=await this.provider.getAddress();validateAddress(this.config.network,t);const r=await this.provider.getPublicKeyHex();if(r&&t)this.walletInfo={publicKeyHex:r,address:t};else throw new Error("Could not connect to OneKey Wallet")});at(this,"getAddress",async()=>{if(!this.walletInfo)throw new Error("OneKey Wallet not connected");return this.walletInfo.address});at(this,"getPublicKeyHex",async()=>{if(!this.walletInfo)throw new Error("OneKey Wallet not connected");return this.walletInfo.publicKeyHex});at(this,"signPsbt",async t=>{if(!this.walletInfo)throw new Error("OneKey Wallet not connected");if(!t)throw new Error("psbt hex is required");return this.provider.signPsbt(t)});at(this,"signPsbts",async t=>{if(!this.walletInfo)throw new Error("OneKey Wallet not connected");if(!t&&!Array.isArray(t))throw new Error("psbts hexes are required");return this.provider.signPsbts(t)});at(this,"getNetwork",async()=>{const t=await this.provider.getNetwork();for(const[r,s]of Object.entries(INTERNAL_NETWORK_NAMES)){if(s==="testnet")return Network.SIGNET;if(s===t)return r}throw new Error("Unsupported network")});at(this,"signMessage",async(t,r)=>{if(!this.walletInfo)throw new Error("OneKey Wallet not connected");return await this.provider.signMessage(t,r)});at(this,"getInscriptions",async()=>{if(!this.walletInfo)throw new Error("OneKey Wallet not connected");if(this.config.network!==Network.MAINNET)throw new Error("Inscriptions are only available on OneKey Wallet BTC Mainnet");const t=100,r=100,s=[];let o=0,n=0;try{for(;n<t;){const{list:a}=await this.provider.getInscriptions(o,r),l=a.map(p=>{const[u,c]=p.output.split(":");return{txid:u,vout:c}});if(s.push(...l),a.length<r)break;if(o+=r,n++,n>=t)throw new Error("Exceeded maximum iterations when fetching inscriptions")}}catch{throw new Error("Failed to get inscriptions from OneKey Wallet")}return s});at(this,"on",(t,r)=>{if(!this.walletInfo)throw new Error("OneKey Wallet not connected");if(t==="accountChanged")return this.provider.on(t,r)});at(this,"off",(t,r)=>{if(!this.walletInfo)throw new Error("OneKey Wallet not connected");if(t==="accountChanged")return this.provider.off(t,r)});at(this,"getWalletProviderName",async()=>WALLET_PROVIDER_NAME$1);at(this,"getWalletProviderIcon",async()=>logo$1);if(this.config=r,!(t!=null&&t.btcwallet))throw new Error("OneKey Wallet extension not found");this.provider=t.btcwallet}}const metadata$3={id:"onekey",name:WALLET_PROVIDER_NAME$1,icon:logo$1,docs:"https://onekey.so/download",wallet:"$onekey",createProvider:(e,t)=>new OneKeyProvider(e,t),networks:[Network.MAINNET,Network.SIGNET]},logo="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='59'%20height='59'%3e%3cdefs%3e%3clinearGradient%20id='a'%20x1='91.9%25'%20x2='5.127%25'%20y1='28.561%25'%20y2='67.452%25'%3e%3cstop%20offset='0%25'%20stop-color='%23070100'/%3e%3cstop%20offset='36%25'%20stop-color='%2377390D'/%3e%3cstop%20offset='67%25'%20stop-color='%23EA8101'/%3e%3cstop%20offset='100%25'%20stop-color='%23F4B852'/%3e%3c/linearGradient%3e%3clinearGradient%20id='b'%20x1='10.514%25'%20x2='111.046%25'%20y1='63.228%25'%20y2='37.55%25'%3e%3cstop%20offset='0%25'%20stop-color='%23070100'/%3e%3cstop%20offset='37%25'%20stop-color='%2377390D'/%3e%3cstop%20offset='67%25'%20stop-color='%23EA8101'/%3e%3cstop%20offset='100%25'%20stop-color='%23F4FB52'/%3e%3c/linearGradient%3e%3cradialGradient%20id='c'%20cx='49.933%25'%20cy='50.067%25'%20r='50%25'%20fx='49.933%25'%20fy='50.067%25'%3e%3cstop%20offset='0%25'%20stop-color='%23F4B852'/%3e%3cstop%20offset='33%25'%20stop-color='%23EA8101'/%3e%3cstop%20offset='64%25'%20stop-color='%2377390D'/%3e%3cstop%20offset='100%25'%20stop-color='%23070100'/%3e%3c/radialGradient%3e%3c/defs%3e%3cg%20fill='none'%20fill-rule='nonzero'%20transform='translate(7%201)'%3e%3cpath%20fill='url(%23a)'%20d='m31.764%205.2%2011.761%2011.745c1%20.997%201.492%202.006%201.475%203.027-.018%201.014-.446%201.947-1.29%202.787-.879.88-1.827%201.33-2.845%201.347-1.017.018-2.023-.478-3.03-1.475L25.81%2010.617c-1.365-1.364-2.683-2.332-3.955-2.898-1.267-.566-2.602-.653-4.002-.268-1.399.385-2.902%201.382-4.51%202.991-2.22%202.217-3.278%204.298-3.168%206.246.11%201.948%201.208%203.96%203.301%206.054L25.6%2034.854c1.012%201.01%201.51%202.018%201.492%203.021-.017%201.003-.45%201.936-1.307%202.788-.855.851-1.792%201.3-2.821%201.335-1.024.035-2.041-.455-3.053-1.464L8.16%2028.79c-1.913-1.913-3.295-3.72-4.145-5.423-.85-1.703-1.168-3.633-.949-5.785.197-1.843.787-3.628%201.758-5.36.977-1.732%202.37-3.499%204.18-5.313%202.157-2.157%204.216-3.808%206.182-4.957C17.153.803%2019.049.161%2020.882.027c1.833-.134%203.643.233%205.435%201.102%201.787.869%203.603%202.222%205.453%204.07h-.006Z'/%3e%3cpath%20fill='url(%23b)'%20d='M13.234%2051.841%201.474%2040.188c-1-.99-1.49-1.99-1.474-3.003.018-1.012.446-1.932%201.29-2.766.878-.873%201.827-1.319%202.844-1.336%201.018-.017%202.024.469%203.03%201.464l12.025%2011.919c1.37%201.354%202.682%202.314%203.954%202.876%201.272.56%202.602.648%204%20.266%201.4-.382%202.903-1.372%204.51-2.968%202.22-2.2%203.278-4.265%203.169-6.197-.11-1.933-1.209-3.935-3.302-6.006l-6.457-6.347c-1.012-1.001-1.51-2.002-1.492-2.998.017-.995.451-1.92%201.307-2.765.855-.845%201.792-1.29%202.82-1.325%201.024-.035%202.042.451%203.053%201.452l6.088%205.983c1.914%201.898%203.296%203.691%204.145%205.38.85%201.69%201.168%203.605.949%205.74-.197%201.829-.787%203.6-1.758%205.318-.977%201.718-2.37%203.471-4.18%205.27-2.156%202.142-4.214%203.78-6.18%204.919-1.966%201.14-3.862%201.776-5.695%201.91-1.832.132-3.642-.232-5.434-1.094-1.787-.862-3.608-2.205-5.452-4.039Z'/%3e%3ccircle%20cx='20'%20cy='18'%20r='4'%20fill='url(%23c)'/%3e%3c/g%3e%3c/svg%3e",WALLET_PROVIDER_NAME="Unisat";class UnisatProvider{constructor(t,r){at(this,"provider");at(this,"walletInfo");at(this,"config");at(this,"connectWallet",async()=>{var o;let t;try{t=await this.provider.requestAccounts()}catch(n){throw(o=n==null?void 0:n.message)!=null&&o.includes("rejected")?new Error("Connection to Unisat Wallet was rejected"):new Error(n==null?void 0:n.message)}const r=t[0];validateAddress(this.config.network,r);const s=await this.provider.getPublicKey();if(s&&r)this.walletInfo={publicKeyHex:s,address:r};else throw new Error("Could not connect to Unisat Wallet")});at(this,"getAddress",async()=>{if(!this.walletInfo)throw new Error("Unisat Wallet not connected");return this.walletInfo.address});at(this,"getPublicKeyHex",async()=>{if(!this.walletInfo)throw new Error("Unisat Wallet not connected");return this.walletInfo.publicKeyHex});at(this,"signPsbt",async t=>{if(!this.walletInfo)throw new Error("Unisat Wallet not connected");if(!t)throw new Error("psbt hex is required");const r=await this.getNetwork();try{return await this.provider.signPsbt(t,this.getSignPsbtDefaultOptions(t,r))}catch(s){throw new Error((s==null?void 0:s.message)||s)}});at(this,"signPsbts",async t=>{if(!this.walletInfo)throw new Error("Unisat Wallet not connected");if(!t&&!Array.isArray(t))throw new Error("psbts hexes are required");const r=await this.getNetwork();try{return await this.provider.signPsbts(t,t.map(s=>this.getSignPsbtDefaultOptions(s,r)))}catch(s){throw new Error((s==null?void 0:s.message)||s)}});at(this,"getNetwork",async()=>{switch((await this.provider.getChain()).enum){case"BITCOIN_MAINNET":return Network.MAINNET;case"BITCOIN_SIGNET":return Network.SIGNET;case"BITCOIN_TESTNET":return Network.SIGNET;default:throw new Error("Unsupported network")}});at(this,"signMessage",async(t,r)=>{if(!this.walletInfo)throw new Error("Unisat Wallet not connected");return await this.provider.signMessage(t,r)});at(this,"getInscriptions",async()=>{if(!this.walletInfo)throw new Error("Unisat Wallet not connected");if(this.config.network!==Network.MAINNET)throw new Error("Inscriptions are only available on Unisat Wallet BTC Mainnet");const t=100,r=100,s=[];let o=0,n=0;try{for(;n<t;){const{list:a}=await this.provider.getInscriptions(o,r),l=a.map(p=>{const[u,c]=p.output.split(":");return{txid:u,vout:c}});if(s.push(...l),a.length<r)break;if(o+=r,n++,n>=t)throw new Error("Exceeded maximum iterations when fetching inscriptions")}}catch{throw new Error("Failed to get inscriptions from Unisat Wallet")}return s});at(this,"on",(t,r)=>{if(!this.walletInfo)throw new Error("Unisat Wallet not connected");if(t==="accountChanged")return this.provider.on("accountsChanged",r)});at(this,"off",(t,r)=>{if(!this.walletInfo)throw new Error("Unisat Wallet not connected");if(t==="accountChanged")return this.provider.removeListener("accountsChanged",r)});at(this,"getWalletProviderName",async()=>WALLET_PROVIDER_NAME);at(this,"getWalletProviderIcon",async()=>logo);if(this.config=r,!t)throw new Error("Unisat Wallet extension not found");this.provider=t}getSignPsbtDefaultOptions(t,r){const s=[];return bitcoinjsLib.Psbt.fromHex(t).data.inputs.forEach((n,a)=>{var u,c;let l=!1;if(n.witnessUtxo&&n.witnessUtxo.script){let v=bitcoinjsLib.networks.bitcoin;(r===Network.TESTNET||r===Network.SIGNET)&&(v=bitcoinjsLib.networks.testnet);let w;try{w=bitcoinjsLib.address.fromOutputScript(n.witnessUtxo.script,v)}catch(I){if(I instanceof Error&&I.message.toLowerCase().includes("has no matching address"))btcStakingTs.initBTCCurve(),w=bitcoinjsLib.address.fromOutputScript(n.witnessUtxo.script,v);else throw new Error(I)}const b=w.indexOf("tb1p")===0||w.indexOf("bc1p")===0,E=w===((u=this.walletInfo)==null?void 0:u.address);b&&E&&(l=!0)}n.finalScriptSig||n.finalScriptWitness||s.push({index:a,publicKey:(c=this.walletInfo)==null?void 0:c.publicKeyHex,sighashTypes:void 0,useTweakedSigner:l})}),{autoFinalized:!0,toSignInputs:s}}}const metadata$2={id:"unisat",name:WALLET_PROVIDER_NAME,icon:logo,docs:"https://unisat.io/download",wallet:"unisat",createProvider:(e,t)=>new UnisatProvider(e,t),networks:[Network.MAINNET,Network.SIGNET]},metadata$1={chain:"BTC",name:"Bitcoin",icon,wallets:[metadata$6,metadata$4,metadata$3,metadata$2,metadata$5]},metadata={BTC:metadata$1,BBN:metadata$7};function usePersistState(e,t,r){function s(){const a=r;if(typeof t>"u")return a;const l=t.getItem(e);return(l?JSON.parse(l):null)??a}const[o,n]=react.useState(s);return react.useEffect(function(){t.setItem(e,JSON.stringify(o??""))},[e,t,o]),[o,n]}const Context$2=react.createContext({lockInscriptions:!0,showAgain:!0});function InscriptionProvider({children:e,context:t}){const[r,s]=usePersistState("bwc-inscription-modal-show-again",t.localStorage,!0),[o,n]=usePersistState("bwc-inscription-modal-lock",t.localStorage,!0),a=react.useMemo(()=>({showAgain:r,lockInscriptions:o,toggleLockInscriptions:n,toggleShowAgain:s}),[r,o,n,s]);return jsxRuntime.jsx(Context$2.Provider,{value:a,children:e})}const useInscriptionProvider=()=>react.useContext(Context$2),defaultState$2={confirmed:!1,visible:!1,screen:{type:"TERMS_OF_SERVICE"},chains:{},selectedWallets:{}},StateContext=react.createContext(defaultState$2);function StateProvider({children:e,chains:t}){const[r,s]=react.useState(defaultState$2);react.useEffect(()=>{s(a=>({...a,chains:t.reduce((l,p)=>({...l,[p.id]:p}),{})}))},[t]);const o=react.useMemo(()=>({open:()=>{s(a=>({...a,visible:!0}))},close:()=>{s(a=>({...a,visible:!1}))},reset:()=>{s(({chains:a})=>({...defaultState$2,chains:a}))},displayLoader:(a="")=>{s(l=>({...l,screen:{type:"LOADER",params:{message:a}}}))},displayTermsOfService:()=>{s(a=>({...a,screen:{type:"TERMS_OF_SERVICE"}}))},displayChains:()=>{s(a=>({...a,screen:{type:"CHAINS"}}))},displayWallets:a=>{s(l=>({...l,screen:{type:"WALLETS",params:{chain:a}}}))},displayInscriptions:()=>{s(a=>({...a,screen:{type:"INSCRIPTIONS"}}))},displayError:a=>{s(l=>({...l,screen:{type:"ERROR",params:a}}))},selectWallet:(a,l)=>{s(p=>({...p,selectedWallets:{...p.selectedWallets,[a]:l}}))},removeWallet:a=>{s(l=>({...l,selectedWallets:{...l.selectedWallets,[a]:void 0}}))},confirm:()=>{s(a=>({...a,confirmed:!0}))}}),[]),n=react.useMemo(()=>({...r,...o}),[r,o]);return jsxRuntime.jsx(StateContext.Provider,{value:n,children:e})}const defaultState$1={BTC:null,BBN:null},Context$1=react.createContext(defaultState$1);function ChainProvider({storage:e,children:t,context:r,config:s,onError:o}){const[n,a]=react.useState(defaultState$1),l=react.useCallback(async()=>{const u=s.filter(v=>metadata[v.chain]).map(({chain:v,config:w})=>createWalletConnector({metadata:metadata[v],context:r,config:w,accountStorage:e}));return(await Promise.all(u)).reduce((v,w)=>({...v,[w.id]:w}),{})},[]);react.useEffect(()=>{l().then(u=>{a(u)}).catch(o)},[a,l,o]);const p=react.useMemo(()=>Object.values(n).filter(Boolean),[n]);return jsxRuntime.jsx(InscriptionProvider,{context:r,children:jsxRuntime.jsx(StateProvider,{chains:p,children:jsxRuntime.jsx(Context$1.Provider,{value:n,children:t})})})}const useChainProviders=()=>react.useContext(Context$1),Context=react.createContext({});function LifeCycleHooksProvider({children:e,value:t}){const r=react.useMemo(()=>t??{},[t]);return jsxRuntime.jsx(Context.Provider,{value:r,children:e})}const useLifeCycleHooks=()=>react.useContext(Context),CONNECTED_ACCOUNTS_KEY="baby-connected-wallet-accounts",createAccountStorage=e=>({get:t=>{const r=localStorage.getItem(CONNECTED_ACCOUNTS_KEY)?JSON.parse(localStorage.getItem(CONNECTED_ACCOUNTS_KEY)||"{}"):{};if(!(r._timestamp&&Date.now()-r._timestamp>e))return r[t]},has:t=>{const r=localStorage.getItem(CONNECTED_ACCOUNTS_KEY)?JSON.parse(localStorage.getItem(CONNECTED_ACCOUNTS_KEY)||"{}"):{};return r._timestamp&&Date.now()-r._timestamp>e?!1:!!r[t]},set:(t,r)=>{const s=localStorage.getItem(CONNECTED_ACCOUNTS_KEY)?JSON.parse(localStorage.getItem(CONNECTED_ACCOUNTS_KEY)||"{}"):{};s[t]=r,s._timestamp=Date.now(),localStorage.setItem(CONNECTED_ACCOUNTS_KEY,JSON.stringify(s))},delete:t=>{const r=localStorage.getItem(CONNECTED_ACCOUNTS_KEY)?JSON.parse(localStorage.getItem(CONNECTED_ACCOUNTS_KEY)||"{}"):{},s=Reflect.deleteProperty(r,t);return localStorage.setItem(CONNECTED_ACCOUNTS_KEY,JSON.stringify(r)),s}});var freeGlobal=typeof commonjsGlobal=="object"&&commonjsGlobal&&commonjsGlobal.Object===Object&&commonjsGlobal,freeSelf=typeof self=="object"&&self&&self.Object===Object&&self;freeGlobal||freeSelf||Function("return this")();var useIsomorphicLayoutEffect=typeof window<"u"?react.useLayoutEffect:react.useEffect,IS_SERVER2=typeof window>"u";function useMediaQuery(e,{defaultValue:t=!1,initializeWithValue:r=!0}={}){const s=l=>IS_SERVER2?t:window.matchMedia(l).matches,[o,n]=react.useState(()=>r?s(e):t);function a(){n(s(e))}return useIsomorphicLayoutEffect(()=>{const l=window.matchMedia(e);return a(),l.addListener?l.addListener(a):l.addEventListener("change",a),()=>{l.removeListener?l.removeListener(a):l.removeEventListener("change",a)}},[e]),o}const useIsMobileView=()=>useMediaQuery("(max-width: 768px)");function ResponsiveDialog(e){const r=useIsMobileView()?coreUi.MobileDialog:coreUi.Dialog;return jsxRuntime.jsx(r,{...e})}const useWidgetState=()=>react.useContext(StateContext);function useWalletConnect(){const{confirmed:e,chains:t,selectedWallets:r,open:s,reset:o}=useWidgetState(),n=useChainProviders(),a=react.useCallback(()=>{o==null||o(),s==null||s()},[s,o]),l=react.useCallback(async()=>{for(const u of Object.values(n))u&&await u.disconnect();o==null||o()},[n,o]),p=react.useMemo(()=>Object.values(t).filter(Boolean).map(v=>r[v.id]).every(Boolean),[t,r]);return{selected:p,connected:p&&e,open:a,disconnect:l}}const ANIMATION_DELAY$1=1e3;function useWalletConnectors({accountStorage:e,onError:t}){const r=useChainProviders(),{selectWallet:s,removeWallet:o,displayLoader:n,displayChains:a,displayInscriptions:l,displayError:p,confirm:u,close:c,reset:v}=useWidgetState(),{showAgain:w}=useInscriptionProvider(),{verifyBTCAddress:b}=useLifeCycleHooks();react.useEffect(()=>{const B=Object.values(r).filter(Boolean).map(M=>M.on("connecting",q=>{n==null||n(q)}));return()=>B.forEach(M=>M())},[n,r]),react.useEffect(()=>{const x=Object.values(r).filter(Boolean),B={BTC:q=>async U=>{var j,y,T;U&&(s==null||s("BTC",U),e.set(q.id,U.id));const F=()=>void(w?l==null?void 0:l():a==null?void 0:a());if(!validateAddressWithPK(((j=U.account)==null?void 0:j.address)??"",((y=U.account)==null?void 0:y.publicKeyHex)??"",q.config.network)){p==null||p({title:"Public Key Mismatch",description:"The Bitcoin address and Public Key for this wallet do not match. Please contact your wallet provider for support.",onSubmit:F,onCancel:()=>{o==null||o(q.id),a==null||a()}});return}if(b&&!await b(((T=U.account)==null?void 0:T.address)??"")){for(const D of x)await D.disconnect();p==null||p({title:"Connection Failed",description:"The wallet cannot be connected.",submitButton:"",cancelButton:"Done",onCancel:async()=>{c==null||c(),setTimeout(()=>void(v==null?void 0:v()),ANIMATION_DELAY$1)}});return}F()},BBN:q=>U=>{U&&(s==null||s(q.id,U),e.set(q.id,U.id)),a==null||a()}},M=x.map(q=>{var U;return q.on("connect",(U=B[q.id])==null?void 0:U.call(B,q))});return x.forEach(q=>{s==null||s(q.id,q.connectedWallet)}),()=>M.forEach(q=>q())},[s,o,l,a,b,v,c,r,w]),react.useEffect(()=>{const B=Object.values(r).filter(Boolean).map(M=>M.on("disconnect",q=>{q&&(o==null||o(M.id),a==null||a(),e.delete(M.id))}));return()=>B.forEach(M=>M())},[o,a,r]),react.useEffect(()=>{const B=Object.values(r).filter(Boolean).map(M=>M.on("error",q=>{t==null||t(q),a==null||a()}));return()=>B.forEach(M=>M())},[t,a,r]),react.useEffect(()=>{const x=Object.values(r).filter(Boolean);x.length&&x.every(B=>e.has(B.id))&&(u==null||u(),a==null||a())},[r,u,a]);const E=react.useCallback(async(x,B)=>{const M=r[x.id];await(M==null?void 0:M.connect(B.id))},[r]),I=react.useCallback(async x=>{const B=r[x];await(B==null?void 0:B.disconnect())},[r]);return{connect:E,disconnect:I}}function useWalletWidgets(e,t){const r=react.useCallback((s,o)=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:o.map(({id:n,widget:a})=>jsxRuntime.jsx(a,{id:n,connector:e[s],createWallet:createExternalWallet},n))}),[e]);return react.useMemo(()=>t.reduce((s,o)=>({...s,[o.chain]:r(o.chain,o.connectors??[])}),{}),[r,t])}function ChainButton({className:e,disabled:t,alt:r,logo:s,title:o,children:n,onClick:a}){const l=typeof s=="string"?jsxRuntime.jsx(coreUi.Avatar,{url:s,alt:r}):jsxRuntime.jsx(coreUi.Avatar,{children:s});return jsxRuntime.jsxs(coreUi.Text,{disabled:t,as:t?"div":"button",className:tailwindMerge.twMerge("flex w-full flex-col gap-2.5 rounded border border-secondary-strokeLight bg-surface p-4 text-accent-primary",t?"pointer-events-none":"pointer-events-auto",t?"cursor-default":"cursor-pointer",e),onClick:a,children:[jsxRuntime.jsxs("div",{className:"flex w-full items-center gap-2.5",children:[jsxRuntime.jsx("div",{className:"flex items-center",children:l}),o,!t&&jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",className:"ml-auto block",children:jsxRuntime.jsx("path",{d:"M8.58984 16.59L13.1698 12L8.58984 7.41L9.99984 6L15.9998 12L9.99984 18L8.58984 16.59Z",fill:"currentColor"})})]}),n&&jsxRuntime.jsx("div",{className:"pointer-events-auto w-full",onClick:p=>p.stopPropagation(),children:n})]})}const formatAddress=(e,t=8)=>e.length<=t?e:t===0?"...":`${e.slice(0,t/2)}...${e.slice(-t/2)}`,ConnectedWallet=react.memo(({className:e,chainId:t,logo:r,name:s,address:o,onDisconnect:n})=>jsxRuntime.jsxs("div",{className:tailwindMerge.twMerge("flex shrink-0 items-center gap-2.5 rounded border border-secondary-main/30 p-2",e),children:[jsxRuntime.jsx(coreUi.Avatar,{variant:"rounded",size:"medium",url:r}),jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col items-start",children:[jsxRuntime.jsx(coreUi.Text,{as:"div",variant:"body2",className:"leading-4 text-accent-primary",children:s}),!!o&&jsxRuntime.jsx(coreUi.Text,{as:"div",variant:"caption",className:"leading-4 text-accent-secondary",children:formatAddress(o)})]}),jsxRuntime.jsx("button",{className:"shrink-0 cursor-pointer",onClick:()=>void(n==null?void 0:n(t)),children:jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",className:"text-secondary-main",fill:"none",children:jsxRuntime.jsx("path",{d:"M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12L19 6.41Z",fill:"currentColor"})})})]})),Chains=react.memo(({disabled:e=!1,chains:t,selectedWallets:r={},className:s,onClose:o,onConfirm:n,onSelectChain:a,onDisconnectWallet:l})=>jsxRuntime.jsxs("div",{className:tailwindMerge.twMerge("flex flex-1 flex-col text-accent-primary",s),children:[jsxRuntime.jsx(coreUi.DialogHeader,{className:"mb-10",title:"Connect Wallets",onClose:o,children:jsxRuntime.jsx(coreUi.Text,{className:"text-accent-secondary",children:"Connect to both Bitcoin and Babylon Chain Wallets"})}),jsxRuntime.jsx(coreUi.DialogBody,{className:"flex flex-col gap-6",children:t.map(p=>{var c;const u=r[p.id];return jsxRuntime.jsx(ChainButton,{disabled:!!u,title:`Select ${p.name} Wallet`,logo:p.icon,alt:p.name,onClick:()=>void(a==null?void 0:a(p)),children:u&&jsxRuntime.jsx(ConnectedWallet,{chainId:p.id,logo:u.icon,name:u.name,address:((c=u.account)==null?void 0:c.address)??"",onDisconnect:l})},p.id)})}),jsxRuntime.jsxs(coreUi.DialogFooter,{className:"mt-auto flex gap-4 pt-10",children:[jsxRuntime.jsx(coreUi.Button,{variant:"outlined",fluid:!0,onClick:o,children:"Cancel"}),jsxRuntime.jsx(coreUi.Button,{disabled:e,fluid:!0,onClick:n,children:"Done"})]})]}));function ChainsContainer(e){const{chains:t,selectedWallets:r,displayWallets:s}=useWidgetState(),{selected:o}=useWalletConnect(),n=react.useMemo(()=>Object.values(t),[t]),a=react.useCallback(l=>{s==null||s(l.id)},[s]);return jsxRuntime.jsx(Chains,{disabled:!o,chains:n,selectedWallets:r,onSelectChain:a,...e})}const DEFAULT_ICON=jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"52",height:"52",viewBox:"0 0 52 52",fill:"none",children:jsxRuntime.jsx("path",{d:"M2.16675 46.5837H49.8334L26.0001 5.41699L2.16675 46.5837ZM28.1667 40.0837H23.8334V35.7503H28.1667V40.0837ZM28.1667 31.417H23.8334V22.7503H28.1667V31.417Z",fill:"#387085"})});function Error$1({className:e,icon:t=DEFAULT_ICON,title:r,description:s,cancelButton:o="Cancel",submitButton:n=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["Continue ",jsxRuntime.jsx("span",{className:"hidden md:inline",children:"Anyway"})]}),onCancel:a,onSubmit:l}){return jsxRuntime.jsxs("div",{className:e,children:[jsxRuntime.jsxs(coreUi.DialogBody,{className:"py-16 text-center",children:[jsxRuntime.jsx("div",{className:"mb-6 inline-flex h-20 w-20 items-center justify-center bg-primary-contrast text-primary-light",children:t}),jsxRuntime.jsx(coreUi.Heading,{variant:"h4",className:"mb-4 text-accent-primary",children:r}),jsxRuntime.jsx(coreUi.Text,{as:"div",className:"text-accent-secondary",children:s})]}),jsxRuntime.jsxs(coreUi.DialogFooter,{className:"flex gap-4",children:[o&&jsxRuntime.jsx(coreUi.Button,{variant:"outlined",fluid:!0,onClick:a,children:o}),n&&jsxRuntime.jsx(coreUi.Button,{fluid:!0,onClick:l,children:n})]})]})}function ErrorContainer({className:e}){const{screen:t}=useWidgetState(),{icon:r,title:s,description:o,cancelButton:n,submitButton:a,onCancel:l,onSubmit:p}=t.params??{};return jsxRuntime.jsx(Error$1,{className:e,icon:r,title:s,description:o,cancelButton:n,submitButton:a,onCancel:l,onSubmit:p})}function FieldControl({label:e,className:t,children:r}){return jsxRuntime.jsxs("label",{className:tailwindMerge.twMerge("flex cursor-pointer gap-4 rounded border border-secondary-strokeLight text-accent-primary p-4",t),children:[r,e]})}function Inscriptions({className:e,config:t,onSubmit:r}){const[s=!0,o]=react.useState(),[n=!0,a]=react.useState();if(!t)return null;const{coinName:l}=t;return jsxRuntime.jsxs("div",{className:tailwindMerge.twMerge("flex flex-1 flex-col",e),children:[jsxRuntime.jsx(coreUi.DialogHeader,{title:`Manage ${l} Inscriptions`,className:"mb-4 text-accent-primary",onClose:()=>void(r==null?void 0:r(s,n))}),jsxRuntime.jsxs(coreUi.DialogBody,{children:[jsxRuntime.jsxs(coreUi.Text,{className:"mb-8 text-accent-secondary",children:["By default, we will not use ",l," that contains Inscriptions - such as Ordinals, NFTs, or Runes - in your stakeable balance. This helps prevent any accidental loss of your Inscriptions due to staking, unbonding, or withdrawal fees."]}),jsxRuntime.jsxs(coreUi.Text,{className:"mb-10 text-accent-secondary",children:["If you would like to include ",l," with Inscriptions in your stakeable balance, please select the option below."]}),jsxRuntime.jsxs("form",{action:"",children:[jsxRuntime.jsx(FieldControl,{label:jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("strong",{className:"mr-2",children:"Do not use"})," ",l," with Inscriptions for staking. (Recommended)"]}),className:"mb-8",children:jsxRuntime.jsx(coreUi.Radio,{name:"inscriptions",checked:s,onChange:()=>o(!0)})}),jsxRuntime.jsx(FieldControl,{label:jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("strong",{className:"mr-2",children:"Use"})," ",l," with Inscriptions in my stakable balance."]}),className:"mb-8",children:jsxRuntime.jsx(coreUi.Radio,{name:"inscriptions",checked:!s,onChange:()=>o(!1)})})]})]}),jsxRuntime.jsxs(coreUi.DialogFooter,{className:"mt-auto pt-10",children:[jsxRuntime.jsx(coreUi.Checkbox,{checked:!n,label:"Do not show again",labelClassName:"mb-6",onChange:p=>a(!p)}),jsxRuntime.jsx(coreUi.Button,{fluid:!0,onClick:()=>void(r==null?void 0:r(s,n)),children:"Save"})]})]})}function InscriptionsContainer({className:e,onSubmit:t}){var s;const{chains:r}=useWidgetState();return jsxRuntime.jsx(Inscriptions,{className:e,onSubmit:t,config:(s=r.BTC)==null?void 0:s.config})}function LoaderScreen({className:e,title:t}){return jsxRuntime.jsxs("div",{className:tailwindMerge.twMerge("flex flex-col items-center justify-center gap-6",e),children:[jsxRuntime.jsx("div",{className:"flex items-center justify-center bg-primary-contrast p-6",children:jsxRuntime.jsx(coreUi.Loader,{className:"text-primary-light"})}),t&&jsxRuntime.jsx(coreUi.Heading,{variant:"h4",className:"capitalize text-accent-primary",children:t})]})}const defaultState={termsOfUse:!1,inscriptions:!1,staking:!1};function TermsOfService({className:e,onClose:t,onSubmit:r}){const[s,o]=react.useState(defaultState),n=react.useMemo(()=>Object.values(s).every(l=>l),[s]),a=react.useCallback(l=>(p=!1)=>{o(u=>({...u,[l]:p}))},[]);return jsxRuntime.jsxs("div",{className:tailwindMerge.twMerge("flex flex-1 flex-col",e),children:[jsxRuntime.jsx(coreUi.DialogHeader,{className:"mb-10 text-accent-primary",title:"Connect Wallets",onClose:t,children:jsxRuntime.jsx(coreUi.Text,{className:"text-accent-secondary",children:"Please read and accept the following terms"})}),jsxRuntime.jsxs(coreUi.DialogBody,{children:[jsxRuntime.jsx(FieldControl,{label:jsxRuntime.jsxs("div",{className:"block",children:["I certify that I have read and accept the updated"," ",jsxRuntime.jsx("a",{href:"https://babylonlabs.io/terms-of-use",target:"_blank",rel:"noopener noreferrer",className:"underline",children:"Terms of Use"})," ","and"," ",jsxRuntime.jsx("a",{href:"https://babylonlabs.io/privacy-policy",target:"_blank",rel:"noopener noreferrer",className:"underline",children:"Privacy Policy"}),"."]}),className:"mb-8",children:jsxRuntime.jsx(coreUi.Checkbox,{checked:s.termsOfUse,onChange:a("termsOfUse")})}),jsxRuntime.jsx(FieldControl,{label:"I certify that I wish to stake bitcoin and agree that doing so may cause some or all of the bitcoin ordinals, NFTs, Runes, and other inscriptions in the connected bitcoin wallet to be lost. I acknowledge that this interface will not detect all Inscriptions.",className:"mb-8",children:jsxRuntime.jsx(coreUi.Checkbox,{checked:s.inscriptions,onChange:a("inscriptions")})}),jsxRuntime.jsx(FieldControl,{label:"I acknowledge that the following are the only hardware wallets supporting Bitcoin Staking: (1) Keystone -- via QR code and (2) OneKey -- via the OneKey Chrome extension and the hardware devices (a) OneKey Pro and (b) OneKey Classic 1s (experimental, 3.10.1 firmware or higher) using Taproot only. Using any other hardware wallet through any means (such as connection to a software/extension/mobile wallet) can lead to permanent inability to withdraw the stake.",children:jsxRuntime.jsx(coreUi.Checkbox,{checked:s.staking,onChange:a("staking")})})]}),jsxRuntime.jsx(coreUi.DialogFooter,{className:"mt-auto pt-10",children:jsxRuntime.jsx(coreUi.Button,{disabled:!n,fluid:!0,onClick:r,children:"Next"})})]})}function TermsOfServiceContainer(e){var r;const{chains:t}=useWidgetState();return jsxRuntime.jsx(TermsOfService,{...e,config:(r=t.BTC)==null?void 0:r.config})}const Wallets=react.memo(({chain:e,className:t,append:r,onClose:s,onBack:o,onSelectWallet:n})=>{const a=react.useMemo(()=>e.wallets.find(u=>u.id==="injectable"&&u.installed),[e]),l=react.useMemo(()=>e.wallets.filter(u=>u.id!=="injectable"),[e]),p=react.useMemo(()=>e.wallets.filter(u=>u.id!=="injectable"||u.installed).length,[e]);return jsxRuntime.jsxs("div",{className:tailwindMerge.twMerge("flex flex-1 flex-col",t),children:[jsxRuntime.jsx(coreUi.DialogHeader,{className:"text-accent-primary mb-10",title:"Select Wallet",onClose:s,children:jsxRuntime.jsxs(coreUi.Text,{className:"text-accent-secondary",children:["Connect a ",e.name," Wallet"]})}),jsxRuntime.jsxs(coreUi.DialogBody,{children:[jsxRuntime.jsxs("div",{className:tailwindMerge.twMerge("grid gap-6",p>1?"grid-cols-1 md:grid-cols-2":"grid-cols-1"),children:[a&&jsxRuntime.jsx(WalletButton,{installed:!0,name:a.name,logo:a.icon,label:a.label,onClick:()=>n==null?void 0:n(e,a)}),l.map(u=>jsxRuntime.jsx(WalletButton,{installed:u.installed,name:u.name,logo:u.icon,label:u.label,fallbackLink:u.docs,onClick:()=>n==null?void 0:n(e,u)},u.id))]}),r]}),jsxRuntime.jsx(coreUi.DialogFooter,{className:"mt-auto pt-10",children:jsxRuntime.jsx(coreUi.Button,{variant:"outlined",fluid:!0,onClick:o,children:"Back"})})]})});function WalletsContainer({widgets:e={},...t}){var p;const{chains:r,screen:s,displayChains:o}=useWidgetState(),n=((p=s.params)==null?void 0:p.chain)??"",a=r==null?void 0:r[n],l=e==null?void 0:e[n];return jsxRuntime.jsx(Wallets,{append:l,chain:a,onBack:o,...t})}const SCREENS={TERMS_OF_SERVICE:({className:e,onClose:t,onAccepTermsOfService:r})=>jsxRuntime.jsx(TermsOfServiceContainer,{className:e,onClose:t,onSubmit:r}),CHAINS:({className:e,onClose:t,onConfirm:r,onDisconnectWallet:s})=>jsxRuntime.jsx(ChainsContainer,{className:e,onClose:t,onConfirm:r,onDisconnectWallet:s}),WALLETS:({className:e,widgets:t,onClose:r,onSelectWallet:s})=>jsxRuntime.jsx(WalletsContainer,{widgets:t,className:e,onClose:r,onSelectWallet:s}),INSCRIPTIONS:({className:e,onToggleInscriptions:t})=>jsxRuntime.jsx(InscriptionsContainer,{className:e,onSubmit:t}),LOADER:({className:e,current:t})=>{var r;return jsxRuntime.jsx(LoaderScreen,{className:e,title:(r=t==null?void 0:t.params)==null?void 0:r.message})},ERROR:()=>jsxRuntime.jsx(ErrorContainer,{className:"min-h-0 md:w-[600px]"}),EMPTY:({className:e})=>jsxRuntime.jsx("div",{className:e})};function Screen(e){const t=SCREENS[e.current.type]??SCREENS.EMPTY;return jsxRuntime.jsx(t,{...e})}const ANIMATION_DELAY=1e3;function WalletDialog({storage:e,config:t,onError:r}){const{visible:s,screen:o,confirmed:n,close:a,confirm:l,displayChains:p}=useWidgetState(),{toggleShowAgain:u,toggleLockInscriptions:c}=useInscriptionProvider(),v=useChainProviders(),w=useWalletWidgets(v,t),{connect:b,disconnect:E}=useWalletConnectors({accountStorage:e,onError:r}),{disconnect:I}=useWalletConnect(),{acceptTermsOfService:x}=useLifeCycleHooks(),B=react.useCallback(()=>{p==null||p(),x==null||x()},[p,x]),M=react.useCallback((F,j)=>{u==null||u(j),c==null||c(F),p==null||p()},[u,c,p]),q=react.useCallback(()=>{a==null||a(),n||setTimeout(I,ANIMATION_DELAY)},[a,I,n]),U=react.useCallback(()=>{l==null||l(),a==null||a()},[l]);return jsxRuntime.jsx(ResponsiveDialog,{className:"min-h-[80%]",open:s,onClose:q,children:jsxRuntime.jsx(Screen,{current:o,widgets:w,className:"min-h-0 md:size-[600px]",onClose:q,onConfirm:U,onSelectWallet:b,onAccepTermsOfService:B,onToggleInscriptions:M,onDisconnectWallet:E})})}const BBN_TESTNET_RPC_URL="https://rpc-dapp.testnet.babylonlabs.io/",BBN_TESTNET_LCD_URL="https://lcd-dapp.testnet.babylonlabs.io/",bbnTestnet={chainId:"bbn-test-5",chainName:"Babylon Testnet",chainSymbolImageUrl:"https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/bbn-test/chain.png",rpc:BBN_TESTNET_RPC_URL,rest:BBN_TESTNET_LCD_URL,nodeProvider:{name:"Babylonlabs",email:"contact@babylonlabs.io",website:"https://babylonlabs.io/"},bip44:{coinType:118},bech32Config:{bech32PrefixAccAddr:"bbn",bech32PrefixAccPub:"bbnpub",bech32PrefixValAddr:"bbnvaloper",bech32PrefixValPub:"bbnvaloperpub",bech32PrefixConsAddr:"bbnvalcons",bech32PrefixConsPub:"bbnvalconspub"},currencies:[{coinDenom:"BABY",coinMinimalDenom:"ubbn",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/bbn-test/chain.png"}],feeCurrencies:[{coinDenom:"BABY",coinMinimalDenom:"ubbn",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/bbn-test/chain.png",gasPriceStep:{low:.007,average:.007,high:.01}}],stakeCurrency:{coinDenom:"BABY",coinMinimalDenom:"ubbn",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/bbn-test/chain.png"},features:["cosmwasm"]},ONE_HOUR=60*60*1e3;Network.SIGNET,bbnTestnet.currencies[0].coinDenom,bbnTestnet.chainName,bbnTestnet.currencies[0].coinDenom,bbnTestnet.chainId;const storage=createAccountStorage(ONE_HOUR);function WalletProvider({lifecycleHooks:e,children:t,config:r,context:s=window,onError:o}){return jsxRuntime.jsx(LifeCycleHooksProvider,{value:e,children:jsxRuntime.jsxs(ChainProvider,{storage,context:s,config:r,onError:o,children:[t,jsxRuntime.jsx(WalletDialog,{storage,config:r,onError:o})]})})}function useChainConnector(e){const t=useChainProviders();return(t==null?void 0:t[e])??null}exports.Network=Network;exports.StateContext=StateContext;exports.StateProvider=StateProvider;exports.WalletButton=WalletButton;exports.WalletProvider=WalletProvider;exports.createExternalWallet=createExternalWallet;exports.useChainConnector=useChainConnector;exports.useInscriptionProvider=useInscriptionProvider;exports.useWalletConnect=useWalletConnect;exports.useWidgetState=useWidgetState;
|
|
79
|
+
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var lazy$8={};Object.defineProperty(lazy$8,"__esModule",{value:!0});lazy$8.value=lazy$8.prop=void 0;function prop(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){const s=r.call(this);return this[t]=s,s},set(s){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,value:s,writable:!0})}})}lazy$8.prop=prop;function value(e){let t;return()=>(t!==void 0||(t=e()),t)}lazy$8.value=value;Object.defineProperty(embed,"__esModule",{value:!0});embed.p2data=void 0;const networks_1$7=networks,bscript$8=script,types_1$8=types$4,lazy$7=lazy$8,OPS$7=bscript$8.OPS;function stacksEqual$4(e,t){return e.length!==t.length?!1:e.every((r,s)=>r.equals(t[s]))}function p2data(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,types_1$8.typeforce)({network:types_1$8.typeforce.maybe(types_1$8.typeforce.Object),output:types_1$8.typeforce.maybe(types_1$8.typeforce.Buffer),data:types_1$8.typeforce.maybe(types_1$8.typeforce.arrayOf(types_1$8.typeforce.Buffer))},e);const s={name:"embed",network:e.network||networks_1$7.bitcoin};if(lazy$7.prop(s,"output",()=>{if(e.data)return bscript$8.compile([OPS$7.OP_RETURN].concat(e.data))}),lazy$7.prop(s,"data",()=>{if(e.output)return bscript$8.decompile(e.output).slice(1)}),t.validate&&e.output){const o=bscript$8.decompile(e.output);if(o[0]!==OPS$7.OP_RETURN)throw new TypeError("Output is invalid");if(!o.slice(1).every(types_1$8.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!stacksEqual$4(e.data,s.data))throw new TypeError("Data mismatch")}return Object.assign(s,e)}embed.p2data=p2data;var p2ms$1={};Object.defineProperty(p2ms$1,"__esModule",{value:!0});p2ms$1.p2ms=void 0;const networks_1$6=networks,bscript$7=script,types_1$7=types$4,lazy$6=lazy$8,OPS$6=bscript$7.OPS,OP_INT_BASE=OPS$6.OP_RESERVED;function stacksEqual$3(e,t){return e.length!==t.length?!1:e.every((r,s)=>r.equals(t[s]))}function p2ms(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(p){return bscript$7.isCanonicalScriptSignature(p)||(t.allowIncomplete&&p===OPS$6.OP_0)!==void 0}(0,types_1$7.typeforce)({network:types_1$7.typeforce.maybe(types_1$7.typeforce.Object),m:types_1$7.typeforce.maybe(types_1$7.typeforce.Number),n:types_1$7.typeforce.maybe(types_1$7.typeforce.Number),output:types_1$7.typeforce.maybe(types_1$7.typeforce.Buffer),pubkeys:types_1$7.typeforce.maybe(types_1$7.typeforce.arrayOf(types_1$7.isPoint)),signatures:types_1$7.typeforce.maybe(types_1$7.typeforce.arrayOf(r)),input:types_1$7.typeforce.maybe(types_1$7.typeforce.Buffer)},e);const o={network:e.network||networks_1$6.bitcoin};let n=[],a=!1;function l(p){a||(a=!0,n=bscript$7.decompile(p),o.m=n[0]-OP_INT_BASE,o.n=n[n.length-2]-OP_INT_BASE,o.pubkeys=n.slice(1,-2))}if(lazy$6.prop(o,"output",()=>{if(e.m&&o.n&&e.pubkeys)return bscript$7.compile([].concat(OP_INT_BASE+e.m,e.pubkeys,OP_INT_BASE+o.n,OPS$6.OP_CHECKMULTISIG))}),lazy$6.prop(o,"m",()=>{if(o.output)return l(o.output),o.m}),lazy$6.prop(o,"n",()=>{if(o.pubkeys)return o.pubkeys.length}),lazy$6.prop(o,"pubkeys",()=>{if(e.output)return l(e.output),o.pubkeys}),lazy$6.prop(o,"signatures",()=>{if(e.input)return bscript$7.decompile(e.input).slice(1)}),lazy$6.prop(o,"input",()=>{if(e.signatures)return bscript$7.compile([OPS$6.OP_0].concat(e.signatures))}),lazy$6.prop(o,"witness",()=>{if(o.input)return[]}),lazy$6.prop(o,"name",()=>{if(!(!o.m||!o.n))return`p2ms(${o.m} of ${o.n})`}),t.validate){if(e.output){if(l(e.output),!types_1$7.typeforce.Number(n[0]))throw new TypeError("Output is invalid");if(!types_1$7.typeforce.Number(n[n.length-2]))throw new TypeError("Output is invalid");if(n[n.length-1]!==OPS$6.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(o.m<=0||o.n>16||o.m>o.n||o.n!==n.length-3)throw new TypeError("Output is invalid");if(!o.pubkeys.every(p=>(0,types_1$7.isPoint)(p)))throw new TypeError("Output is invalid");if(e.m!==void 0&&e.m!==o.m)throw new TypeError("m mismatch");if(e.n!==void 0&&e.n!==o.n)throw new TypeError("n mismatch");if(e.pubkeys&&!stacksEqual$3(e.pubkeys,o.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(o.n=e.pubkeys.length,o.n<o.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<o.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>o.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==OPS$6.OP_0)throw new TypeError("Input is invalid");if(o.signatures.length===0||!o.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!stacksEqual$3(e.signatures,o.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(o,e)}p2ms$1.p2ms=p2ms;var p2pk$1={};Object.defineProperty(p2pk$1,"__esModule",{value:!0});p2pk$1.p2pk=void 0;const networks_1$5=networks,bscript$6=script,types_1$6=types$4,lazy$5=lazy$8,OPS$5=bscript$6.OPS;function p2pk(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||{}),(0,types_1$6.typeforce)({network:types_1$6.typeforce.maybe(types_1$6.typeforce.Object),output:types_1$6.typeforce.maybe(types_1$6.typeforce.Buffer),pubkey:types_1$6.typeforce.maybe(types_1$6.isPoint),signature:types_1$6.typeforce.maybe(bscript$6.isCanonicalScriptSignature),input:types_1$6.typeforce.maybe(types_1$6.typeforce.Buffer)},e);const r=lazy$5.value(()=>bscript$6.decompile(e.input)),o={name:"p2pk",network:e.network||networks_1$5.bitcoin};if(lazy$5.prop(o,"output",()=>{if(e.pubkey)return bscript$6.compile([e.pubkey,OPS$5.OP_CHECKSIG])}),lazy$5.prop(o,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),lazy$5.prop(o,"signature",()=>{if(e.input)return r()[0]}),lazy$5.prop(o,"input",()=>{if(e.signature)return bscript$6.compile([e.signature])}),lazy$5.prop(o,"witness",()=>{if(o.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==OPS$5.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,types_1$6.isPoint)(o.pubkey))throw new TypeError("Output pubkey is invalid");if(e.pubkey&&!e.pubkey.equals(o.pubkey))throw new TypeError("Pubkey mismatch")}if(e.signature&&e.input&&!e.input.equals(o.input))throw new TypeError("Signature mismatch");if(e.input){if(r().length!==1)throw new TypeError("Input is invalid");if(!bscript$6.isCanonicalScriptSignature(o.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(o,e)}p2pk$1.p2pk=p2pk;var p2pkh$1={};Object.defineProperty(p2pkh$1,"__esModule",{value:!0});p2pkh$1.p2pkh=void 0;const bcrypto$3=crypto$1,networks_1$4=networks,bscript$5=script,types_1$5=types$4,lazy$4=lazy$8,bs58check$1=bs58check$a,OPS$4=bscript$5.OPS;function p2pkh(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||{}),(0,types_1$5.typeforce)({network:types_1$5.typeforce.maybe(types_1$5.typeforce.Object),address:types_1$5.typeforce.maybe(types_1$5.typeforce.String),hash:types_1$5.typeforce.maybe(types_1$5.typeforce.BufferN(20)),output:types_1$5.typeforce.maybe(types_1$5.typeforce.BufferN(25)),pubkey:types_1$5.typeforce.maybe(types_1$5.isPoint),signature:types_1$5.typeforce.maybe(bscript$5.isCanonicalScriptSignature),input:types_1$5.typeforce.maybe(types_1$5.typeforce.Buffer)},e);const r=lazy$4.value(()=>{const a=Buffer$e.from(bs58check$1.decode(e.address)),l=a.readUInt8(0),p=a.slice(1);return{version:l,hash:p}}),s=lazy$4.value(()=>bscript$5.decompile(e.input)),o=e.network||networks_1$4.bitcoin,n={name:"p2pkh",network:o};if(lazy$4.prop(n,"address",()=>{if(!n.hash)return;const a=Buffer$e.allocUnsafe(21);return a.writeUInt8(o.pubKeyHash,0),n.hash.copy(a,1),bs58check$1.encode(a)}),lazy$4.prop(n,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return r().hash;if(e.pubkey||n.pubkey)return bcrypto$3.hash160(e.pubkey||n.pubkey)}),lazy$4.prop(n,"output",()=>{if(n.hash)return bscript$5.compile([OPS$4.OP_DUP,OPS$4.OP_HASH160,n.hash,OPS$4.OP_EQUALVERIFY,OPS$4.OP_CHECKSIG])}),lazy$4.prop(n,"pubkey",()=>{if(e.input)return s()[1]}),lazy$4.prop(n,"signature",()=>{if(e.input)return s()[0]}),lazy$4.prop(n,"input",()=>{if(e.pubkey&&e.signature)return bscript$5.compile([e.signature,e.pubkey])}),lazy$4.prop(n,"witness",()=>{if(n.input)return[]}),t.validate){let a=Buffer$e.from([]);if(e.address){if(r().version!==o.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(r().hash.length!==20)throw new TypeError("Invalid address");a=r().hash}if(e.hash){if(a.length>0&&!a.equals(e.hash))throw new TypeError("Hash mismatch");a=e.hash}if(e.output){if(e.output.length!==25||e.output[0]!==OPS$4.OP_DUP||e.output[1]!==OPS$4.OP_HASH160||e.output[2]!==20||e.output[23]!==OPS$4.OP_EQUALVERIFY||e.output[24]!==OPS$4.OP_CHECKSIG)throw new TypeError("Output is invalid");const l=e.output.slice(3,23);if(a.length>0&&!a.equals(l))throw new TypeError("Hash mismatch");a=l}if(e.pubkey){const l=bcrypto$3.hash160(e.pubkey);if(a.length>0&&!a.equals(l))throw new TypeError("Hash mismatch");a=l}if(e.input){const l=s();if(l.length!==2)throw new TypeError("Input is invalid");if(!bscript$5.isCanonicalScriptSignature(l[0]))throw new TypeError("Input has invalid signature");if(!(0,types_1$5.isPoint)(l[1]))throw new TypeError("Input has invalid pubkey");if(e.signature&&!e.signature.equals(l[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(l[1]))throw new TypeError("Pubkey mismatch");const p=bcrypto$3.hash160(l[1]);if(a.length>0&&!a.equals(p))throw new TypeError("Hash mismatch")}}return Object.assign(n,e)}p2pkh$1.p2pkh=p2pkh;var p2sh$1={};Object.defineProperty(p2sh$1,"__esModule",{value:!0});p2sh$1.p2sh=void 0;const bcrypto$2=crypto$1,networks_1$3=networks,bscript$4=script,types_1$4=types$4,lazy$3=lazy$8,bs58check=bs58check$a,OPS$3=bscript$4.OPS;function stacksEqual$2(e,t){return e.length!==t.length?!1:e.every((r,s)=>r.equals(t[s]))}function p2sh(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||{}),(0,types_1$4.typeforce)({network:types_1$4.typeforce.maybe(types_1$4.typeforce.Object),address:types_1$4.typeforce.maybe(types_1$4.typeforce.String),hash:types_1$4.typeforce.maybe(types_1$4.typeforce.BufferN(20)),output:types_1$4.typeforce.maybe(types_1$4.typeforce.BufferN(23)),redeem:types_1$4.typeforce.maybe({network:types_1$4.typeforce.maybe(types_1$4.typeforce.Object),output:types_1$4.typeforce.maybe(types_1$4.typeforce.Buffer),input:types_1$4.typeforce.maybe(types_1$4.typeforce.Buffer),witness:types_1$4.typeforce.maybe(types_1$4.typeforce.arrayOf(types_1$4.typeforce.Buffer))}),input:types_1$4.typeforce.maybe(types_1$4.typeforce.Buffer),witness:types_1$4.typeforce.maybe(types_1$4.typeforce.arrayOf(types_1$4.typeforce.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||networks_1$3.bitcoin);const s={network:r},o=lazy$3.value(()=>{const l=Buffer$e.from(bs58check.decode(e.address)),p=l.readUInt8(0),u=l.slice(1);return{version:p,hash:u}}),n=lazy$3.value(()=>bscript$4.decompile(e.input)),a=lazy$3.value(()=>{const l=n(),p=l[l.length-1];return{network:r,output:p===OPS$3.OP_FALSE?Buffer$e.from([]):p,input:bscript$4.compile(l.slice(0,-1)),witness:e.witness||[]}});if(lazy$3.prop(s,"address",()=>{if(!s.hash)return;const l=Buffer$e.allocUnsafe(21);return l.writeUInt8(s.network.scriptHash,0),s.hash.copy(l,1),bs58check.encode(l)}),lazy$3.prop(s,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return o().hash;if(s.redeem&&s.redeem.output)return bcrypto$2.hash160(s.redeem.output)}),lazy$3.prop(s,"output",()=>{if(s.hash)return bscript$4.compile([OPS$3.OP_HASH160,s.hash,OPS$3.OP_EQUAL])}),lazy$3.prop(s,"redeem",()=>{if(e.input)return a()}),lazy$3.prop(s,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return bscript$4.compile([].concat(bscript$4.decompile(e.redeem.input),e.redeem.output))}),lazy$3.prop(s,"witness",()=>{if(s.redeem&&s.redeem.witness)return s.redeem.witness;if(s.input)return[]}),lazy$3.prop(s,"name",()=>{const l=["p2sh"];return s.redeem!==void 0&&s.redeem.name!==void 0&&l.push(s.redeem.name),l.join("-")}),t.validate){let l=Buffer$e.from([]);if(e.address){if(o().version!==r.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(o().hash.length!==20)throw new TypeError("Invalid address");l=o().hash}if(e.hash){if(l.length>0&&!l.equals(e.hash))throw new TypeError("Hash mismatch");l=e.hash}if(e.output){if(e.output.length!==23||e.output[0]!==OPS$3.OP_HASH160||e.output[1]!==20||e.output[22]!==OPS$3.OP_EQUAL)throw new TypeError("Output is invalid");const u=e.output.slice(2,22);if(l.length>0&&!l.equals(u))throw new TypeError("Hash mismatch");l=u}const p=u=>{if(u.output){const c=bscript$4.decompile(u.output);if(!c||c.length<1)throw new TypeError("Redeem.output too short");if(u.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(bscript$4.countNonPushOnlyOPs(c)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const v=bcrypto$2.hash160(u.output);if(l.length>0&&!l.equals(v))throw new TypeError("Hash mismatch");l=v}if(u.input){const c=u.input.length>0,v=u.witness&&u.witness.length>0;if(!c&&!v)throw new TypeError("Empty input");if(c&&v)throw new TypeError("Input and witness provided");if(c){const w=bscript$4.decompile(u.input);if(!bscript$4.isPushOnly(w))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const u=n();if(!u||u.length<1)throw new TypeError("Input too short");if(!Buffer$e.isBuffer(a().output))throw new TypeError("Input is invalid");p(a())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==r)throw new TypeError("Network mismatch");if(e.input){const u=a();if(e.redeem.output&&!e.redeem.output.equals(u.output))throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&!e.redeem.input.equals(u.input))throw new TypeError("Redeem.input mismatch")}p(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!stacksEqual$2(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(s,e)}p2sh$1.p2sh=p2sh;var p2wpkh$1={},dist={};Object.defineProperty(dist,"__esModule",{value:!0});dist.bech32m=dist.bech32=void 0;const ALPHABET="qpzry9x8gf2tvdw0s3jn54khce6mua7l",ALPHABET_MAP={};for(let e=0;e<ALPHABET.length;e++){const t=ALPHABET.charAt(e);ALPHABET_MAP[t]=e}function polymodStep(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 prefixChk(e){let t=1;for(let r=0;r<e.length;++r){const s=e.charCodeAt(r);if(s<33||s>126)return"Invalid prefix ("+e+")";t=polymodStep(t)^s>>5}t=polymodStep(t);for(let r=0;r<e.length;++r){const s=e.charCodeAt(r);t=polymodStep(t)^s&31}return t}function convert(e,t,r,s){let o=0,n=0;const a=(1<<r)-1,l=[];for(let p=0;p<e.length;++p)for(o=o<<t|e[p],n+=t;n>=r;)n-=r,l.push(o>>n&a);if(s)n>0&&l.push(o<<r-n&a);else{if(n>=t)return"Excess padding";if(o<<r-n&a)return"Non-zero padding"}return l}function toWords(e){return convert(e,8,5,!0)}function fromWordsUnsafe(e){const t=convert(e,5,8,!1);if(Array.isArray(t))return t}function fromWords(e){const t=convert(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function getLibraryFromEncoding(e){let t;e==="bech32"?t=1:t=734539939;function r(a,l,p){if(p=p||90,a.length+7+l.length>p)throw new TypeError("Exceeds length limit");a=a.toLowerCase();let u=prefixChk(a);if(typeof u=="string")throw new Error(u);let c=a+"1";for(let v=0;v<l.length;++v){const w=l[v];if(w>>5)throw new Error("Non 5-bit word");u=polymodStep(u)^w,c+=ALPHABET.charAt(w)}for(let v=0;v<6;++v)u=polymodStep(u);u^=t;for(let v=0;v<6;++v){const w=u>>(5-v)*5&31;c+=ALPHABET.charAt(w)}return c}function s(a,l){if(l=l||90,a.length<8)return a+" too short";if(a.length>l)return"Exceeds length limit";const p=a.toLowerCase(),u=a.toUpperCase();if(a!==p&&a!==u)return"Mixed-case string "+a;a=p;const c=a.lastIndexOf("1");if(c===-1)return"No separator character for "+a;if(c===0)return"Missing prefix for "+a;const v=a.slice(0,c),w=a.slice(c+1);if(w.length<6)return"Data too short";let b=prefixChk(v);if(typeof b=="string")return b;const E=[];for(let I=0;I<w.length;++I){const x=w.charAt(I),B=ALPHABET_MAP[x];if(B===void 0)return"Unknown character "+x;b=polymodStep(b)^B,!(I+6>=w.length)&&E.push(B)}return b!==t?"Invalid checksum for "+a:{prefix:v,words:E}}function o(a,l){const p=s(a,l);if(typeof p=="object")return p}function n(a,l){const p=s(a,l);if(typeof p=="object")return p;throw new Error(p)}return{decodeUnsafe:o,decode:n,encode:r,toWords,fromWordsUnsafe,fromWords}}dist.bech32=getLibraryFromEncoding("bech32");dist.bech32m=getLibraryFromEncoding("bech32m");Object.defineProperty(p2wpkh$1,"__esModule",{value:!0});p2wpkh$1.p2wpkh=void 0;const bcrypto$1=crypto$1,networks_1$2=networks,bscript$3=script,types_1$3=types$4,lazy$2=lazy$8,bech32_1$2=dist,OPS$2=bscript$3.OPS,EMPTY_BUFFER$1=Buffer$e.alloc(0);function p2wpkh(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||{}),(0,types_1$3.typeforce)({address:types_1$3.typeforce.maybe(types_1$3.typeforce.String),hash:types_1$3.typeforce.maybe(types_1$3.typeforce.BufferN(20)),input:types_1$3.typeforce.maybe(types_1$3.typeforce.BufferN(0)),network:types_1$3.typeforce.maybe(types_1$3.typeforce.Object),output:types_1$3.typeforce.maybe(types_1$3.typeforce.BufferN(22)),pubkey:types_1$3.typeforce.maybe(types_1$3.isPoint),signature:types_1$3.typeforce.maybe(bscript$3.isCanonicalScriptSignature),witness:types_1$3.typeforce.maybe(types_1$3.typeforce.arrayOf(types_1$3.typeforce.Buffer))},e);const r=lazy$2.value(()=>{const n=bech32_1$2.bech32.decode(e.address),a=n.words.shift(),l=bech32_1$2.bech32.fromWords(n.words);return{version:a,prefix:n.prefix,data:Buffer$e.from(l)}}),s=e.network||networks_1$2.bitcoin,o={name:"p2wpkh",network:s};if(lazy$2.prop(o,"address",()=>{if(!o.hash)return;const n=bech32_1$2.bech32.toWords(o.hash);return n.unshift(0),bech32_1$2.bech32.encode(s.bech32,n)}),lazy$2.prop(o,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return r().data;if(e.pubkey||o.pubkey)return bcrypto$1.hash160(e.pubkey||o.pubkey)}),lazy$2.prop(o,"output",()=>{if(o.hash)return bscript$3.compile([OPS$2.OP_0,o.hash])}),lazy$2.prop(o,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),lazy$2.prop(o,"signature",()=>{if(e.witness)return e.witness[0]}),lazy$2.prop(o,"input",()=>{if(o.witness)return EMPTY_BUFFER$1}),lazy$2.prop(o,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let n=Buffer$e.from([]);if(e.address){if(s&&s.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");n=r().data}if(e.hash){if(n.length>0&&!n.equals(e.hash))throw new TypeError("Hash mismatch");n=e.hash}if(e.output){if(e.output.length!==22||e.output[0]!==OPS$2.OP_0||e.output[1]!==20)throw new TypeError("Output is invalid");if(n.length>0&&!n.equals(e.output.slice(2)))throw new TypeError("Hash mismatch");n=e.output.slice(2)}if(e.pubkey){const a=bcrypto$1.hash160(e.pubkey);if(n.length>0&&!n.equals(a))throw new TypeError("Hash mismatch");if(n=a,!(0,types_1$3.isPoint)(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(!bscript$3.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,types_1$3.isPoint)(e.witness[1])||e.witness[1].length!==33)throw new TypeError("Witness has invalid pubkey");if(e.signature&&!e.signature.equals(e.witness[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(e.witness[1]))throw new TypeError("Pubkey mismatch");const a=bcrypto$1.hash160(e.witness[1]);if(n.length>0&&!n.equals(a))throw new TypeError("Hash mismatch")}}return Object.assign(o,e)}p2wpkh$1.p2wpkh=p2wpkh;var p2wsh$1={};Object.defineProperty(p2wsh$1,"__esModule",{value:!0});p2wsh$1.p2wsh=void 0;const bcrypto=crypto$1,networks_1$1=networks,bscript$2=script,types_1$2=types$4,lazy$1=lazy$8,bech32_1$1=dist,OPS$1=bscript$2.OPS,EMPTY_BUFFER=Buffer$e.alloc(0);function stacksEqual$1(e,t){return e.length!==t.length?!1:e.every((r,s)=>r.equals(t[s]))}function chunkHasUncompressedPubkey(e){return!!(Buffer$e.isBuffer(e)&&e.length===65&&e[0]===4&&(0,types_1$2.isPoint)(e))}function p2wsh(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||{}),(0,types_1$2.typeforce)({network:types_1$2.typeforce.maybe(types_1$2.typeforce.Object),address:types_1$2.typeforce.maybe(types_1$2.typeforce.String),hash:types_1$2.typeforce.maybe(types_1$2.typeforce.BufferN(32)),output:types_1$2.typeforce.maybe(types_1$2.typeforce.BufferN(34)),redeem:types_1$2.typeforce.maybe({input:types_1$2.typeforce.maybe(types_1$2.typeforce.Buffer),network:types_1$2.typeforce.maybe(types_1$2.typeforce.Object),output:types_1$2.typeforce.maybe(types_1$2.typeforce.Buffer),witness:types_1$2.typeforce.maybe(types_1$2.typeforce.arrayOf(types_1$2.typeforce.Buffer))}),input:types_1$2.typeforce.maybe(types_1$2.typeforce.BufferN(0)),witness:types_1$2.typeforce.maybe(types_1$2.typeforce.arrayOf(types_1$2.typeforce.Buffer))},e);const r=lazy$1.value(()=>{const a=bech32_1$1.bech32.decode(e.address),l=a.words.shift(),p=bech32_1$1.bech32.fromWords(a.words);return{version:l,prefix:a.prefix,data:Buffer$e.from(p)}}),s=lazy$1.value(()=>bscript$2.decompile(e.redeem.input));let o=e.network;o||(o=e.redeem&&e.redeem.network||networks_1$1.bitcoin);const n={network:o};if(lazy$1.prop(n,"address",()=>{if(!n.hash)return;const a=bech32_1$1.bech32.toWords(n.hash);return a.unshift(0),bech32_1$1.bech32.encode(o.bech32,a)}),lazy$1.prop(n,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return r().data;if(n.redeem&&n.redeem.output)return bcrypto.sha256(n.redeem.output)}),lazy$1.prop(n,"output",()=>{if(n.hash)return bscript$2.compile([OPS$1.OP_0,n.hash])}),lazy$1.prop(n,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:EMPTY_BUFFER,witness:e.witness.slice(0,-1)}}),lazy$1.prop(n,"input",()=>{if(n.witness)return EMPTY_BUFFER}),lazy$1.prop(n,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const a=bscript$2.toStack(s());return n.redeem=Object.assign({witness:a},e.redeem),n.redeem.input=EMPTY_BUFFER,[].concat(a,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),lazy$1.prop(n,"name",()=>{const a=["p2wsh"];return n.redeem!==void 0&&n.redeem.name!==void 0&&a.push(n.redeem.name),a.join("-")}),t.validate){let a=Buffer$e.from([]);if(e.address){if(r().prefix!==o.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");a=r().data}if(e.hash){if(a.length>0&&!a.equals(e.hash))throw new TypeError("Hash mismatch");a=e.hash}if(e.output){if(e.output.length!==34||e.output[0]!==OPS$1.OP_0||e.output[1]!==32)throw new TypeError("Output is invalid");const l=e.output.slice(2);if(a.length>0&&!a.equals(l))throw new TypeError("Hash mismatch");a=l}if(e.redeem){if(e.redeem.network&&e.redeem.network!==o)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 l=bscript$2.decompile(e.redeem.output);if(!l||l.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(bscript$2.countNonPushOnlyOPs(l)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const p=bcrypto.sha256(e.redeem.output);if(a.length>0&&!a.equals(p))throw new TypeError("Hash mismatch");a=p}if(e.redeem.input&&!bscript$2.isPushOnly(s()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!stacksEqual$1(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&s().some(chunkHasUncompressedPubkey)||e.redeem.output&&(bscript$2.decompile(e.redeem.output)||[]).some(chunkHasUncompressedPubkey))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(e.witness&&e.witness.length>0){const l=e.witness[e.witness.length-1];if(e.redeem&&e.redeem.output&&!e.redeem.output.equals(l))throw new TypeError("Witness and redeem.output mismatch");if(e.witness.some(chunkHasUncompressedPubkey)||(bscript$2.decompile(l)||[]).some(chunkHasUncompressedPubkey))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(n,e)}p2wsh$1.p2wsh=p2wsh;var p2tr$1={};Object.defineProperty(p2tr$1,"__esModule",{value:!0});p2tr$1.p2tr=void 0;const buffer_1=require$$0$3,networks_1=networks,bscript$1=script,types_1$1=types$4,ecc_lib_1=ecc_lib,bip341_1$1=bip341,lazy=lazy$8,bech32_1=dist,OPS=bscript$1.OPS,TAPROOT_WITNESS_VERSION=1,ANNEX_PREFIX=80;function p2tr(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||{}),(0,types_1$1.typeforce)({address:types_1$1.typeforce.maybe(types_1$1.typeforce.String),input:types_1$1.typeforce.maybe(types_1$1.typeforce.BufferN(0)),network:types_1$1.typeforce.maybe(types_1$1.typeforce.Object),output:types_1$1.typeforce.maybe(types_1$1.typeforce.BufferN(34)),internalPubkey:types_1$1.typeforce.maybe(types_1$1.typeforce.BufferN(32)),hash:types_1$1.typeforce.maybe(types_1$1.typeforce.BufferN(32)),pubkey:types_1$1.typeforce.maybe(types_1$1.typeforce.BufferN(32)),signature:types_1$1.typeforce.maybe(types_1$1.typeforce.anyOf(types_1$1.typeforce.BufferN(64),types_1$1.typeforce.BufferN(65))),witness:types_1$1.typeforce.maybe(types_1$1.typeforce.arrayOf(types_1$1.typeforce.Buffer)),scriptTree:types_1$1.typeforce.maybe(types_1$1.isTaptree),redeem:types_1$1.typeforce.maybe({output:types_1$1.typeforce.maybe(types_1$1.typeforce.Buffer),redeemVersion:types_1$1.typeforce.maybe(types_1$1.typeforce.Number),witness:types_1$1.typeforce.maybe(types_1$1.typeforce.arrayOf(types_1$1.typeforce.Buffer))}),redeemVersion:types_1$1.typeforce.maybe(types_1$1.typeforce.Number)},e);const r=lazy.value(()=>{const l=bech32_1.bech32m.decode(e.address),p=l.words.shift(),u=bech32_1.bech32m.fromWords(l.words);return{version:p,prefix:l.prefix,data:buffer_1.Buffer.from(u)}}),s=lazy.value(()=>{if(!(!e.witness||!e.witness.length))return e.witness.length>=2&&e.witness[e.witness.length-1][0]===ANNEX_PREFIX?e.witness.slice(0,-1):e.witness.slice()}),o=lazy.value(()=>{if(e.scriptTree)return(0,bip341_1$1.toHashTree)(e.scriptTree);if(e.hash)return{hash:e.hash}}),n=e.network||networks_1.bitcoin,a={name:"p2tr",network:n};if(lazy.prop(a,"address",()=>{if(!a.pubkey)return;const l=bech32_1.bech32m.toWords(a.pubkey);return l.unshift(TAPROOT_WITNESS_VERSION),bech32_1.bech32m.encode(n.bech32,l)}),lazy.prop(a,"hash",()=>{const l=o();if(l)return l.hash;const p=s();if(p&&p.length>1){const u=p[p.length-1],c=u[0]&types_1$1.TAPLEAF_VERSION_MASK,v=p[p.length-2],w=(0,bip341_1$1.tapleafHash)({output:v,version:c});return(0,bip341_1$1.rootHashFromPath)(u,w)}return null}),lazy.prop(a,"output",()=>{if(a.pubkey)return bscript$1.compile([OPS.OP_1,a.pubkey])}),lazy.prop(a,"redeemVersion",()=>e.redeemVersion?e.redeemVersion:e.redeem&&e.redeem.redeemVersion!==void 0&&e.redeem.redeemVersion!==null?e.redeem.redeemVersion:bip341_1$1.LEAF_VERSION_TAPSCRIPT),lazy.prop(a,"redeem",()=>{const l=s();if(!(!l||l.length<2))return{output:l[l.length-2],witness:l.slice(0,-2),redeemVersion:l[l.length-1][0]&types_1$1.TAPLEAF_VERSION_MASK}}),lazy.prop(a,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.output)return e.output.slice(2);if(e.address)return r().data;if(a.internalPubkey){const l=(0,bip341_1$1.tweakKey)(a.internalPubkey,a.hash);if(l)return l.x}}),lazy.prop(a,"internalPubkey",()=>{if(e.internalPubkey)return e.internalPubkey;const l=s();if(l&&l.length>1)return l[l.length-1].slice(1,33)}),lazy.prop(a,"signature",()=>{if(e.signature)return e.signature;const l=s();if(!(!l||l.length!==1))return l[0]}),lazy.prop(a,"witness",()=>{if(e.witness)return e.witness;const l=o();if(l&&e.redeem&&e.redeem.output&&e.internalPubkey){const p=(0,bip341_1$1.tapleafHash)({output:e.redeem.output,version:a.redeemVersion}),u=(0,bip341_1$1.findScriptPath)(l,p);if(!u)return;const c=(0,bip341_1$1.tweakKey)(e.internalPubkey,l.hash);if(!c)return;const v=buffer_1.Buffer.concat([buffer_1.Buffer.from([a.redeemVersion|c.parity]),e.internalPubkey].concat(u));return[e.redeem.output,v]}if(e.signature)return[e.signature]}),t.validate){let l=buffer_1.Buffer.from([]);if(e.address){if(n&&n.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==TAPROOT_WITNESS_VERSION)throw new TypeError("Invalid address version");if(r().data.length!==32)throw new TypeError("Invalid address data");l=r().data}if(e.pubkey){if(l.length>0&&!l.equals(e.pubkey))throw new TypeError("Pubkey mismatch");l=e.pubkey}if(e.output){if(e.output.length!==34||e.output[0]!==OPS.OP_1||e.output[1]!==32)throw new TypeError("Output is invalid");if(l.length>0&&!l.equals(e.output.slice(2)))throw new TypeError("Pubkey mismatch");l=e.output.slice(2)}if(e.internalPubkey){const c=(0,bip341_1$1.tweakKey)(e.internalPubkey,a.hash);if(l.length>0&&!l.equals(c.x))throw new TypeError("Pubkey mismatch");l=c.x}if(l&&l.length&&!(0,ecc_lib_1.getEccLib)().isXOnlyPoint(l))throw new TypeError("Invalid pubkey for p2tr");const p=o();if(e.hash&&p&&!e.hash.equals(p.hash))throw new TypeError("Hash mismatch");if(e.redeem&&e.redeem.output&&p){const c=(0,bip341_1$1.tapleafHash)({output:e.redeem.output,version:a.redeemVersion});if(!(0,bip341_1$1.findScriptPath)(p,c))throw new TypeError("Redeem script not in tree")}const u=s();if(e.redeem&&a.redeem){if(e.redeem.redeemVersion&&e.redeem.redeemVersion!==a.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(e.redeem.output){if(bscript$1.decompile(e.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(a.redeem.output&&!e.redeem.output.equals(a.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(e.redeem.witness&&a.redeem.witness&&!stacksEqual(e.redeem.witness,a.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(u&&u.length)if(u.length===1){if(e.signature&&!e.signature.equals(u[0]))throw new TypeError("Signature mismatch")}else{const c=u[u.length-1];if(c.length<33)throw new TypeError(`The control-block length is too small. Got ${c.length}, expected min 33.`);if((c.length-33)%32!==0)throw new TypeError(`The control-block length of ${c.length} is incorrect!`);const v=(c.length-33)/32;if(v>128)throw new TypeError(`The script path is too long. Got ${v}, expected max 128.`);const w=c.slice(1,33);if(e.internalPubkey&&!e.internalPubkey.equals(w))throw new TypeError("Internal pubkey mismatch");if(!(0,ecc_lib_1.getEccLib)().isXOnlyPoint(w))throw new TypeError("Invalid internalPubkey for p2tr witness");const b=c[0]&types_1$1.TAPLEAF_VERSION_MASK,E=u[u.length-2],I=(0,bip341_1$1.tapleafHash)({output:E,version:b}),x=(0,bip341_1$1.rootHashFromPath)(c,I),B=(0,bip341_1$1.tweakKey)(w,x);if(!B)throw new TypeError("Invalid outputKey for p2tr witness");if(l.length&&!l.equals(B.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(B.parity!==(c[0]&1))throw new Error("Incorrect parity")}}return Object.assign(a,e)}p2tr$1.p2tr=p2tr;function stacksEqual(e,t){return e.length!==t.length?!1:e.every((r,s)=>r.equals(t[s]))}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.p2tr=e.p2wsh=e.p2wpkh=e.p2sh=e.p2pkh=e.p2pk=e.p2ms=e.embed=void 0;const t=embed;Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const r=p2ms$1;Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return r.p2ms}});const s=p2pk$1;Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return s.p2pk}});const o=p2pkh$1;Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return o.p2pkh}});const n=p2sh$1;Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return n.p2sh}});const a=p2wpkh$1;Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return a.p2wpkh}});const l=p2wsh$1;Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return l.p2wsh}});const p=p2tr$1;Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return p.p2tr}})})(payments$1);Object.defineProperty(psbtutils,"__esModule",{value:!0});psbtutils.signatureBlocksAction=psbtutils.checkInputForSig=pubkeyInScript_1=psbtutils.pubkeyInScript=psbtutils.pubkeyPositionInScript=psbtutils.witnessStackToScriptWitness=psbtutils.isP2TR=psbtutils.isP2SHScript=psbtutils.isP2WSHScript=psbtutils.isP2WPKH=psbtutils.isP2PKH=psbtutils.isP2PK=psbtutils.isP2MS=void 0;const varuint=varint,bscript=script,transaction_1$1=transaction,crypto_1=crypto$1,payments=payments$1;function isPaymentFactory(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}psbtutils.isP2MS=isPaymentFactory(payments.p2ms);psbtutils.isP2PK=isPaymentFactory(payments.p2pk);psbtutils.isP2PKH=isPaymentFactory(payments.p2pkh);psbtutils.isP2WPKH=isPaymentFactory(payments.p2wpkh);psbtutils.isP2WSHScript=isPaymentFactory(payments.p2wsh);psbtutils.isP2SHScript=isPaymentFactory(payments.p2sh);psbtutils.isP2TR=isPaymentFactory(payments.p2tr);function witnessStackToScriptWitness(e){let t=Buffer$e.allocUnsafe(0);function r(a){t=Buffer$e.concat([t,Buffer$e.from(a)])}function s(a){const l=t.length,p=varuint.encodingLength(a);t=Buffer$e.concat([t,Buffer$e.allocUnsafe(p)]),varuint.encode(a,t,l)}function o(a){s(a.length),r(a)}function n(a){s(a.length),a.forEach(o)}return n(e),t}psbtutils.witnessStackToScriptWitness=witnessStackToScriptWitness;function pubkeyPositionInScript(e,t){const r=(0,crypto_1.hash160)(e),s=e.slice(1,33),o=bscript.decompile(t);if(o===null)throw new Error("Unknown script error");return o.findIndex(n=>typeof n=="number"?!1:n.equals(e)||n.equals(r)||n.equals(s))}psbtutils.pubkeyPositionInScript=pubkeyPositionInScript;function pubkeyInScript(e,t){return pubkeyPositionInScript(e,t)!==-1}var pubkeyInScript_1=psbtutils.pubkeyInScript=pubkeyInScript;function checkInputForSig(e,t){return extractPartialSigs(e).some(s=>signatureBlocksAction(s,bscript.signature.decode,t))}psbtutils.checkInputForSig=checkInputForSig;function signatureBlocksAction(e,t,r){const{hashType:s}=t(e),o=[];switch(s&transaction_1$1.Transaction.SIGHASH_ANYONECANPAY&&o.push("addInput"),s&31){case transaction_1$1.Transaction.SIGHASH_ALL:break;case transaction_1$1.Transaction.SIGHASH_SINGLE:case transaction_1$1.Transaction.SIGHASH_NONE:o.push("addOutput"),o.push("setInputSequence");break}return o.indexOf(r)===-1}psbtutils.signatureBlocksAction=signatureBlocksAction;function extractPartialSigs(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=getPsigsFromInputFinalScripts(e)}else t=e.partialSig;return t.map(r=>r.signature)}function getPsigsFromInputFinalScripts(e){const t=e.finalScriptSig?bscript.decompile(e.finalScriptSig)||[]:[],r=e.finalScriptWitness?bscript.decompile(e.finalScriptWitness)||[]:[];return t.concat(r).filter(s=>Buffer$e.isBuffer(s)&&bscript.isCanonicalScriptSignature(s)).map(s=>({signature:s}))}Object.defineProperty(bip371,"__esModule",{value:!0});bip371.checkTaprootInputForSigs=bip371.tapTreeFromList=bip371.tapTreeToList=bip371.tweakInternalPubKey=bip371.checkTaprootOutputFields=bip371.checkTaprootInputFields=bip371.isTaprootOutput=bip371.isTaprootInput=bip371.serializeTaprootSignature=bip371.tapScriptFinalizer=toXOnly_1=bip371.toXOnly=void 0;const types_1=types$4,transaction_1=transaction,psbtutils_1=psbtutils,bip341_1=bip341,payments_1=payments$1,psbtutils_2=psbtutils,toXOnly=e=>e.length===32?e:e.slice(1,33);var toXOnly_1=bip371.toXOnly=toXOnly;function tapScriptFinalizer(e,t,r){const s=findTapLeafToFinalize(t,e,r);try{const n=sortSignatures(t,s).concat(s.script).concat(s.controlBlock);return{finalScriptWitness:(0,psbtutils_1.witnessStackToScriptWitness)(n)}}catch(o){throw new Error(`Can not finalize taproot input #${e}: ${o}`)}}bip371.tapScriptFinalizer=tapScriptFinalizer;function serializeTaprootSignature(e,t){const r=t?Buffer$e.from([t]):Buffer$e.from([]);return Buffer$e.concat([e,r])}bip371.serializeTaprootSignature=serializeTaprootSignature;function isTaprootInput(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&(0,psbtutils_1.isP2TR)(e.witnessUtxo.script))}bip371.isTaprootInput=isTaprootInput;function isTaprootOutput(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t&&(0,psbtutils_1.isP2TR)(t))}bip371.isTaprootOutput=isTaprootOutput;function checkTaprootInputFields(e,t,r){checkMixedTaprootAndNonTaprootInputFields(e,t,r),checkIfTapLeafInTree(e,t,r)}bip371.checkTaprootInputFields=checkTaprootInputFields;function checkTaprootOutputFields(e,t,r){checkMixedTaprootAndNonTaprootOutputFields(e,t,r),checkTaprootScriptPubkey(e,t)}bip371.checkTaprootOutputFields=checkTaprootOutputFields;function checkTaprootScriptPubkey(e,t){if(!t.tapTree&&!t.tapInternalKey)return;const r=t.tapInternalKey||e.tapInternalKey,s=t.tapTree||e.tapTree;if(r){const{script:o}=e,n=getTaprootScripPubkey(r,s);if(o&&!o.equals(n))throw new Error("Error adding output. Script or address missmatch.")}}function getTaprootScripPubkey(e,t){const r=t&&tapTreeFromList(t.leaves),{output:s}=(0,payments_1.p2tr)({internalPubkey:e,scriptTree:r});return s}function tweakInternalPubKey(e,t){const r=t.tapInternalKey,s=r&&(0,bip341_1.tweakKey)(r,t.tapMerkleRoot);if(!s)throw new Error(`Cannot tweak tap internal key for input #${e}. Public key: ${r&&r.toString("hex")}`);return s.x}bip371.tweakInternalPubKey=tweakInternalPubKey;function tapTreeToList(e){if(!(0,types_1.isTaptree)(e))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return _tapTreeToList(e)}bip371.tapTreeToList=tapTreeToList;function tapTreeFromList(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:instertLeavesInTree(e)}bip371.tapTreeFromList=tapTreeFromList;function checkTaprootInputForSigs(e,t){return extractTaprootSigs(e).some(s=>(0,psbtutils_2.signatureBlocksAction)(s,decodeSchnorrSignature,t))}bip371.checkTaprootInputForSigs=checkTaprootInputForSigs;function decodeSchnorrSignature(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||transaction_1.Transaction.SIGHASH_DEFAULT}}function extractTaprootSigs(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(r=>r.signature)),!t.length){const r=getTapKeySigFromWithness(e.finalScriptWitness);r&&t.push(r)}return t}function getTapKeySigFromWithness(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function _tapTreeToList(e,t=[],r=0){if(r>bip341_1.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return e?(0,types_1.isTapleaf)(e)?(t.push({depth:r,leafVersion:e.version||bip341_1.LEAF_VERSION_TAPSCRIPT,script:e.output}),t):(e[0]&&_tapTreeToList(e[0],t,r+1),e[1]&&_tapTreeToList(e[1],t,r+1),t):[]}function instertLeavesInTree(e){let t;for(const r of e)if(t=instertLeafInTree(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function instertLeafInTree(e,t,r=0){if(r>bip341_1.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");if(e.depth===r)return t?void 0:{output:e.script,version:e.leafVersion};if((0,types_1.isTapleaf)(t))return;const s=instertLeafInTree(e,t&&t[0],r+1);if(s)return[s,t&&t[1]];const o=instertLeafInTree(e,t&&t[1],r+1);if(o)return[t&&t[0],o]}function checkMixedTaprootAndNonTaprootInputFields(e,t,r){const s=isTaprootInput(e)&&hasNonTaprootFields(t),o=hasNonTaprootFields(e)&&isTaprootInput(t),n=e===t&&isTaprootInput(t)&&hasNonTaprootFields(t);if(s||o||n)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function checkMixedTaprootAndNonTaprootOutputFields(e,t,r){const s=isTaprootOutput(e)&&hasNonTaprootFields(t),o=hasNonTaprootFields(e)&&isTaprootOutput(t),n=e===t&&isTaprootOutput(t)&&hasNonTaprootFields(t);if(s||o||n)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function checkIfTapLeafInTree(e,t,r){if(t.tapMerkleRoot){const s=(t.tapLeafScript||[]).every(n=>isTapLeafInTree(n,t.tapMerkleRoot)),o=(e.tapLeafScript||[]).every(n=>isTapLeafInTree(n,t.tapMerkleRoot));if(!s||!o)throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}else if(e.tapMerkleRoot&&!(t.tapLeafScript||[]).every(o=>isTapLeafInTree(o,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}function isTapLeafInTree(e,t){if(!t)return!0;const r=(0,bip341_1.tapleafHash)({output:e.script,version:e.leafVersion});return(0,bip341_1.rootHashFromPath)(e.controlBlock,r).equals(t)}function sortSignatures(e,t){const r=(0,bip341_1.tapleafHash)({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(s=>s.leafHash.equals(r)).map(s=>addPubkeyPositionInScript(t.script,s)).sort((s,o)=>o.positionInScript-s.positionInScript).map(s=>s.signature)}function addPubkeyPositionInScript(e,t){return Object.assign({positionInScript:(0,psbtutils_1.pubkeyPositionInScript)(t.pubkey,e)},t)}function findTapLeafToFinalize(e,t,r){if(!e.tapScriptSig||!e.tapScriptSig.length)throw new Error(`Can not finalize taproot input #${t}. No tapleaf script signature provided.`);const s=(e.tapLeafScript||[]).sort((o,n)=>o.controlBlock.length-n.controlBlock.length).find(o=>canFinalizeLeaf(o,e.tapScriptSig,r));if(!s)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return s}function canFinalizeLeaf(e,t,r){const s=(0,bip341_1.tapleafHash)({output:e.script,version:e.leafVersion});return(!r||r.equals(s))&&t.find(n=>n.leafHash.equals(s))!==void 0}function hasNonTaprootFields(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const byteToHex=[];for(let e=0;e<256;++e)byteToHex.push((e+256).toString(16).slice(1));function unsafeStringify(e,t=0){return(byteToHex[e[t+0]]+byteToHex[e[t+1]]+byteToHex[e[t+2]]+byteToHex[e[t+3]]+"-"+byteToHex[e[t+4]]+byteToHex[e[t+5]]+"-"+byteToHex[e[t+6]]+byteToHex[e[t+7]]+"-"+byteToHex[e[t+8]]+byteToHex[e[t+9]]+"-"+byteToHex[e[t+10]]+byteToHex[e[t+11]]+byteToHex[e[t+12]]+byteToHex[e[t+13]]+byteToHex[e[t+14]]+byteToHex[e[t+15]]).toLowerCase()}let getRandomValues;const rnds8=new Uint8Array(16);function rng(){if(!getRandomValues){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");getRandomValues=crypto.getRandomValues.bind(crypto)}return getRandomValues(rnds8)}const randomUUID=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),native={randomUUID};function v4(e,t,r){var o;if(native.randomUUID&&!t&&!e)return native.randomUUID();e=e||{};const s=e.random??((o=e.rng)==null?void 0:o.call(e))??rng();if(s.length<16)throw new Error("Random bytes length must be >= 16");return s[6]=s[6]&15|64,s[8]=s[8]&63|128,unsafeStringify(s)}const COMPRESSED_PUBLIC_KEY_HEX_LENGTH=66,NETWORKS={[Network.MAINNET]:{name:"Mainnet",config:bitcoinjsLib.networks.bitcoin,addressPrefix:{common:"bc1",nativeSegWit:"bc1q",taproot:"bc1p"}},[Network.CANARY]:{name:"Canary",config:bitcoinjsLib.networks.bitcoin,addressPrefix:{common:"bc1",nativeSegWit:"bc1q",taproot:"bc1p"}},[Network.TESTNET]:{name:"Testnet",config:bitcoinjsLib.networks.testnet,addressPrefix:{common:"tb1",nativeSegWit:"tb1q",taproot:"tb1p"}},[Network.SIGNET]:{name:"Signet",config:bitcoinjsLib.networks.testnet,addressPrefix:{common:"tb1",nativeSegWit:"tb1q",taproot:"tb1p"}}},getTaprootAddress=(e,t)=>{e.length==COMPRESSED_PUBLIC_KEY_HEX_LENGTH&&(e=e.slice(2));const r=Buffer$e.from(e,"hex"),{address:s,output:o}=bitcoinjsLib.payments.p2tr({internalPubkey:toXOnly_1(r),network:NETWORKS[t].config});if(!s||!o)throw new Error("Failed to generate taproot address or script from public key");return s},getNativeSegwitAddress=(e,t)=>{if(e.length!==COMPRESSED_PUBLIC_KEY_HEX_LENGTH)throw new Error("Invalid public key length for generating native segwit address");const r=Buffer$e.from(e,"hex"),{address:s,output:o}=bitcoinjsLib.payments.p2wpkh({pubkey:r,network:NETWORKS[t].config});if(!s||!o)throw new Error("Failed to generate native segwit address or script from public key");return s};function validateAddressWithPK(e,t,r){return e.startsWith(NETWORKS[r].addressPrefix.taproot)?e===getTaprootAddress(t,r):e.startsWith(NETWORKS[r].addressPrefix.nativeSegWit)?e===getNativeSegwitAddress(t,r):!1}function validateAddress(e,t){const{addressPrefix:r,name:s}=NETWORKS[e];if(!(e in NETWORKS))throw new Error(`Unsupported network: ${e}. Please provide a valid network.`);if(!t.startsWith(r.common))throw new Error(`Incorrect address prefix for ${s}. Expected address to start with '${r}'.`)}const toNetwork=e=>NETWORKS[e].config,WALLET_PROVIDER_NAME$3="Keystone";class KeystoneProvider{constructor(t,r){at(this,"keystoneWaleltInfo");at(this,"viewSDK");at(this,"dataSdk");at(this,"config");at(this,"connectWallet",async()=>{const r=await(await this.viewSDK.getSdk()).read([sdk$1.SupportedResult.UR_CRYPTO_ACCOUNT],{title:"Sync Keystone with Babylon Staking App",description:"Please scan the QR code displayed on your Keystone, Currently only the first Taproot Address will be used",renderInitial:{walletMode:"btc",link:"",description:["1. Turn on your Keystone 3 with BTC only firmware.",'2. Click connect software wallet and use "Sparrow" for connection.','3. Press the "Sync Keystone" button and scan the QR Code displayed on your Keystone hardware wallet',"4. The first Taproot address will be used for staking."]},URTypeErrorMessage:"The scanned QR code is not the sync code from the Keystone hardware wallet. Please verify the code and try again."});if(r.status===sdk$1.ReadStatus.canceled)throw new Error("Connection to Keystone was canceled");if(r.status!==sdk$1.ReadStatus.success)throw new Error("Error reading QR code, Please try again.");const s=this.dataSdk.parseAccount(r.result),o=3,n=s.keys[o].extendedPublicKey;if(this.keystoneWaleltInfo={mfp:s.masterFingerprint,extendedPublicKey:n,path:s.keys[o].path,address:void 0,publicKeyHex:void 0,scriptPubKeyHex:void 0},!this.keystoneWaleltInfo.extendedPublicKey)throw new Error("Could not retrieve the extended public key");const{address:a,pubkeyHex:l,scriptPubKeyHex:p}=generateP2trAddressFromXpub(this.keystoneWaleltInfo.extendedPublicKey,"M/0/0",toNetwork(this.config.network));this.keystoneWaleltInfo.address=a,this.keystoneWaleltInfo.publicKeyHex=l,this.keystoneWaleltInfo.scriptPubKeyHex=p});at(this,"getAddress",async()=>{var t;if(!((t=this.keystoneWaleltInfo)!=null&&t.address))throw new Error("Could not retrieve the address");return this.keystoneWaleltInfo.address});at(this,"getPublicKeyHex",async()=>{var t;if(!((t=this.keystoneWaleltInfo)!=null&&t.publicKeyHex))throw new Error("Could not retrieve the BTC public key");return this.keystoneWaleltInfo.publicKeyHex});at(this,"signPsbt",async t=>{var n,a;if(!((n=this.keystoneWaleltInfo)!=null&&n.address)||!((a=this.keystoneWaleltInfo)!=null&&a.publicKeyHex))throw new Error("Keystone Wallet not connected");if(!t)throw new Error("psbt hex is required");let r=bitcoinjsLib.Psbt.fromHex(t);r=this.enhancePsbt(r);const s=r.toHex();return(await this.sign(s)).toHex()});at(this,"signPsbts",async t=>{var s,o;if(!((s=this.keystoneWaleltInfo)!=null&&s.address)||!((o=this.keystoneWaleltInfo)!=null&&o.publicKeyHex))throw new Error("Keystone Wallet not connected");if(!t&&!Array.isArray(t))throw new Error("psbts hexes are required");const r=[];for(const n of t){const a=await this.signPsbt(n);r.push(a)}return r});at(this,"getNetwork",async()=>this.config.network);at(this,"signMessage",async(t,r)=>{if(r!=="ecdsa")throw new Error("Only ECDSA signature is supported");if(!this.keystoneWaleltInfo)throw new Error("Keystone Wallet not connected");const s=this.dataSdk.btc.generateSignRequest({requestId:v4(),signData:Buffer$1$1.from(t,"utf-8").toString("hex"),dataType:dist$v.KeystoneBitcoinSDK.DataType.message,accounts:[{path:`${this.keystoneWaleltInfo.path}/0/0`,xfp:`${this.keystoneWaleltInfo.mfp}`,address:this.keystoneWaleltInfo.address}],origin:"babylon staking app"}),o=composeQRProcess(sdk$1.SupportedResult.UR_BTC_SIGNATURE),n=await this.viewSDK.getSdk(),a=await o(n,s),l=this.dataSdk.btc.parseSignature(a);return Buffer$1$1.from(l.signature,"hex").toString("base64")});at(this,"getInscriptions",async()=>{throw new Error("Method not implemented.")});at(this,"on",()=>{});at(this,"off",()=>{});at(this,"getWalletProviderName",async()=>WALLET_PROVIDER_NAME$3);at(this,"getWalletProviderIcon",async()=>logo$3);at(this,"sign",async t=>{if(!t)throw new Error("psbt hex is required");const r=this.dataSdk.btc.generatePSBT(Buffer$1$1.from(t,"hex")),s=composeQRProcess(sdk$1.SupportedResult.UR_PSBT),o=await this.viewSDK.getSdk(),n=await s(o,r),a=this.dataSdk.btc.parsePSBT(n),l=bitcoinjsLib.Psbt.fromHex(a);return l.finalizeAllInputs(),l});at(this,"enhancePsbt",t=>{var s,o,n,a;if(!((s=this.keystoneWaleltInfo)!=null&&s.scriptPubKeyHex)||!((o=this.keystoneWaleltInfo)!=null&&o.publicKeyHex)||!((n=this.keystoneWaleltInfo)!=null&&n.mfp)||!((a=this.keystoneWaleltInfo)!=null&&a.path))throw new Error("Keystone Wallet not connected");const r={masterFingerprint:Buffer$1$1.from(this.keystoneWaleltInfo.mfp,"hex"),path:`${this.keystoneWaleltInfo.path}/0/0`,pubkey:Buffer$1$1.from(this.keystoneWaleltInfo.publicKeyHex,"hex")};return t.data.inputs.forEach(l=>{l.tapBip32Derivation=[{...r,pubkey:toXOnly_1(r.pubkey),leafHashes:caculateTapLeafHash(l,r.pubkey)}]}),t});this.config=r,sdk$1.viewSdk.bootstrap(),this.viewSDK=sdk$1.viewSdk,this.dataSdk=new dist$v.KeystoneSDK({origin:"babylon staking app"})}}const composeQRProcess=e=>async(t,r)=>{if(await t.play(r,{title:"Scan the QR Code",description:"Please scan the QR code with your Keystone device."})!==sdk$1.PlayStatus.success)throw new Error("Could not generate the QR code, please try again.");const o=await t.read([e],{title:"Get the Signature from Keystone",description:"Please scan the QR code displayed on your Keystone",URTypeErrorMessage:"The scanned QR code can't be read. please verify and try again."});if(o.status!==sdk$1.ReadStatus.success)throw new Error("Could not extract the signature, please try again.");return o.result},generateP2trAddressFromXpub=(e,t,r)=>{const o=HDKey.fromExtendedKey(e).derive(t),n=Buffer$1$1.from(o.publicKey),a=toXOnly_1(n);let l,p;try{const u=bitcoinjsLib.payments.p2tr({internalPubkey:a,network:r});l=u.address,p=u.output}catch(u){if(u instanceof Error&&u.message.includes("ECC")){btcStakingTs.initBTCCurve();const c=bitcoinjsLib.payments.p2tr({internalPubkey:a,network:r});l=c.address,p=c.output}else throw new Error(u)}return{address:l,pubkeyHex:n.toString("hex"),scriptPubKeyHex:p.toString("hex")}},caculateTapLeafHash=(e,t)=>e.tapInternalKey&&!e.tapLeafScript?[]:(e.tapLeafScript||[]).filter(s=>pubkeyInScript_1(t,s.script)).map(s=>{const o=bip341.tapleafHash({output:s.script,version:s.leafVersion});return Object.assign({hash:o},s)}).map(s=>s.hash),metadata$5={id:"keystone",name:WALLET_PROVIDER_NAME$3,icon:logo$3,docs:"https://www.keyst.one/btc-only",createProvider:(e,t)=>new KeystoneProvider(e,t),networks:[Network.MAINNET,Network.SIGNET],label:"Hardware wallet"},logo$2="data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='UTF-8'?%3e%3csvg%20width='225px'%20height='224px'%20viewBox='0%200%20225%20224'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3ctitle%3eokx%3c/title%3e%3cg%20id='Page-1'%20stroke='none'%20strokeWidth='1'%20fill='none'%20fill-rule='evenodd'%3e%3cg%20id='okx'%20transform='translate(0.401000,%200.006000)'%20fill='%23000000'%20fill-rule='nonzero'%3e%3cpath%20d='M144.382,74.667%20L79.673,74.667%20C76.924,74.667%2074.695,76.895%2074.695,79.644%20L74.695,144.354%20C74.695,147.103%2076.924,149.332%2079.673,149.332%20L144.382,149.332%20C147.131,149.332%20149.36,147.103%20149.36,144.354%20L149.36,79.644%20C149.36,76.895%20147.131,74.667%20144.382,74.667%20Z'%20id='Path'%3e%3c/path%3e%3cpath%20d='M69.687,0%20L4.978,0%20C2.229,0%200,2.228%200,4.978%20L0,69.687%20C0,72.436%202.229,74.665%204.978,74.665%20L69.687,74.665%20C72.437,74.665%2074.665,72.436%2074.665,69.687%20L74.665,4.978%20C74.665,2.228%2072.437,0%2069.687,0%20Z'%20id='Path'%3e%3c/path%3e%3cpath%20d='M219.017,0%20L154.307,0%20C151.558,0%20149.329,2.228%20149.329,4.978%20L149.329,69.687%20C149.329,72.436%20151.558,74.665%20154.307,74.665%20L219.017,74.665%20C221.766,74.665%20223.994,72.436%20223.994,69.687%20L223.994,4.978%20C223.994,2.228%20221.766,0%20219.017,0%20Z'%20id='Path'%3e%3c/path%3e%3cpath%20d='M69.687,149.328%20L4.978,149.328%20C2.229,149.328%200,151.556%200,154.305%20L0,219.015%20C0,221.764%202.229,223.993%204.978,223.993%20L69.687,223.993%20C72.437,223.993%2074.665,221.764%2074.665,219.015%20L74.665,154.305%20C74.665,151.556%2072.437,149.328%2069.687,149.328%20Z'%20id='Path'%3e%3c/path%3e%3cpath%20d='M219.017,149.328%20L154.307,149.328%20C151.558,149.328%20149.329,151.556%20149.329,154.305%20L149.329,219.015%20C149.329,221.764%20151.558,223.993%20154.307,223.993%20L219.017,223.993%20C221.766,223.993%20223.994,221.764%20223.994,219.015%20L223.994,154.305%20C223.994,151.556%20221.766,149.328%20219.017,149.328%20Z'%20id='Path'%3e%3c/path%3e%3c/g%3e%3c/g%3e%3c/svg%3e",PROVIDER_NAMES={[Network.MAINNET]:"bitcoin",[Network.CANARY]:"bitcoin",[Network.TESTNET]:"bitcoinTestnet",[Network.SIGNET]:"bitcoinSignet"},WALLET_PROVIDER_NAME$2="OKX";class OKXProvider{constructor(t,r){at(this,"provider");at(this,"walletInfo");at(this,"config");at(this,"connectWallet",async()=>{var o;try{await this.wallet.enable()}catch(n){throw(o=n==null?void 0:n.message)!=null&&o.includes("rejected")?new Error("Connection to OKX Wallet was rejected"):new Error(n==null?void 0:n.message)}let t;try{t=await this.provider.connect()}catch{throw new Error(`BTC ${this.config.network} is not enabled in OKX Wallet`)}const{address:r,compressedPublicKey:s}=t;if(validateAddress(this.config.network,r),s&&r)this.walletInfo={publicKeyHex:s,address:r};else throw new Error("Could not connect to OKX Wallet")});at(this,"getAddress",async()=>{if(!this.walletInfo)throw new Error("OKX Wallet not connected");return this.walletInfo.address});at(this,"getPublicKeyHex",async()=>{if(!this.walletInfo)throw new Error("OKX Wallet not connected");return this.walletInfo.publicKeyHex});at(this,"signPsbt",async t=>{if(!this.walletInfo)throw new Error("OKX Wallet not connected");return await this.provider.signPsbt(t)});at(this,"signPsbts",async t=>{if(!this.walletInfo)throw new Error("OKX Wallet not connected");return await this.provider.signPsbts(t)});at(this,"getNetwork",async()=>{if(!this.config.network)throw new Error("Network not set");return this.config.network});at(this,"signMessage",async(t,r)=>{if(!this.walletInfo)throw new Error("OKX Wallet not connected");return await this.provider.signMessage(t,r)});at(this,"getInscriptions",async()=>{if(!this.walletInfo)throw new Error("OKX Wallet not connected");if(this.config.network!==Network.MAINNET)throw new Error("Inscriptions are only available on OKX Wallet BTC mainnet");const t=100,r=100,s=[];let o=0,n=0;try{for(;n<t;){const{list:a}=await this.provider.getInscriptions(o,r),l=a.map(p=>{const[u,c]=p.output.split(":");return{txid:u,vout:c}});if(s.push(...l),a.length<r)break;if(o+=r,n++,n>=t)throw new Error("Exceeded maximum iterations when fetching inscriptions")}}catch{throw new Error("Failed to get inscriptions from OKX Wallet")}return s});at(this,"on",(t,r)=>{if(!this.walletInfo)throw new Error("OKX Wallet not connected");if(t==="accountChanged")return this.provider.on(t,r)});at(this,"off",(t,r)=>{if(!this.walletInfo)throw new Error("OKX Wallet not connected");if(t==="accountChanged")return this.provider.off(t,r)});at(this,"getWalletProviderName",async()=>WALLET_PROVIDER_NAME$2);at(this,"getWalletProviderIcon",async()=>logo$2);if(this.wallet=t,this.config=r,!t)throw new Error("OKX Wallet extension not found");const s=PROVIDER_NAMES[r.network];if(!s)throw new Error("Unsupported network");this.provider=t[s]}}const metadata$4={id:"okx",name:WALLET_PROVIDER_NAME$2,icon:logo$2,docs:"https://www.okx.com/web3",wallet:"okxwallet",createProvider:(e,t)=>new OKXProvider(e,t),networks:[Network.MAINNET,Network.SIGNET]},logo$1="data:image/svg+xml,%3csvg%20width='128'%20height='128'%20viewBox='0%200%20128%20128'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20clip-path='url(%23clip0_45922_88)'%3e%3cpath%20d='M127.61%2063.8049C127.61%20107.853%20107.853%20127.61%2063.8049%20127.61C19.7568%20127.61%200%20107.853%200%2063.8049C0%2019.7568%2019.7568%200%2063.8049%200C107.853%200%20127.61%2019.7568%20127.61%2063.8049Z'%20fill='%233BD23D'/%3e%3cpath%20d='M69.5699%2027.0557L51.8197%2027.0557L48.7056%2036.4719H58.5645L58.5645%2056.3063H69.5699V27.0557Z'%20fill='black'/%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M84.0486%2080.3111C84.0486%2091.4912%2074.9854%20100.554%2063.8053%20100.554C52.6253%20100.554%2043.5621%2091.4912%2043.5621%2080.3111C43.5621%2069.1311%2052.6253%2060.0678%2063.8053%2060.0678C74.9854%2060.0678%2084.0486%2069.1311%2084.0486%2080.3111ZM74.8584%2080.3111C74.8584%2086.4155%2069.9097%2091.3641%2063.8053%2091.3641C57.7008%2091.3641%2052.7522%2086.4155%2052.7522%2080.3111C52.7522%2074.2066%2057.7008%2069.258%2063.8053%2069.258C69.9097%2069.258%2074.8584%2074.2066%2074.8584%2080.3111Z'%20fill='black'/%3e%3c/g%3e%3cdefs%3e%3cclipPath%20id='clip0_45922_88'%3e%3crect%20width='128'%20height='128'%20fill='white'/%3e%3c/clipPath%3e%3c/defs%3e%3c/svg%3e",INTERNAL_NETWORK_NAMES={[Network.MAINNET]:"livenet",[Network.TESTNET]:"testnet",[Network.SIGNET]:"signet"},WALLET_PROVIDER_NAME$1="OneKey";class OneKeyProvider{constructor(t,r){at(this,"provider");at(this,"walletInfo");at(this,"config");at(this,"connectWallet",async()=>{var s;try{await this.provider.connectWallet()}catch(o){throw(s=o==null?void 0:o.message)!=null&&s.includes("rejected")?new Error("Connection to OneKey Wallet was rejected"):new Error(o==null?void 0:o.message)}const t=await this.provider.getAddress();validateAddress(this.config.network,t);const r=await this.provider.getPublicKeyHex();if(r&&t)this.walletInfo={publicKeyHex:r,address:t};else throw new Error("Could not connect to OneKey Wallet")});at(this,"getAddress",async()=>{if(!this.walletInfo)throw new Error("OneKey Wallet not connected");return this.walletInfo.address});at(this,"getPublicKeyHex",async()=>{if(!this.walletInfo)throw new Error("OneKey Wallet not connected");return this.walletInfo.publicKeyHex});at(this,"signPsbt",async t=>{if(!this.walletInfo)throw new Error("OneKey Wallet not connected");if(!t)throw new Error("psbt hex is required");return this.provider.signPsbt(t)});at(this,"signPsbts",async t=>{if(!this.walletInfo)throw new Error("OneKey Wallet not connected");if(!t&&!Array.isArray(t))throw new Error("psbts hexes are required");return this.provider.signPsbts(t)});at(this,"getNetwork",async()=>{const t=await this.provider.getNetwork();for(const[r,s]of Object.entries(INTERNAL_NETWORK_NAMES)){if(s==="testnet")return Network.SIGNET;if(s===t)return r}throw new Error("Unsupported network")});at(this,"signMessage",async(t,r)=>{if(!this.walletInfo)throw new Error("OneKey Wallet not connected");return await this.provider.signMessage(t,r)});at(this,"getInscriptions",async()=>{if(!this.walletInfo)throw new Error("OneKey Wallet not connected");if(this.config.network!==Network.MAINNET)throw new Error("Inscriptions are only available on OneKey Wallet BTC Mainnet");const t=100,r=100,s=[];let o=0,n=0;try{for(;n<t;){const{list:a}=await this.provider.getInscriptions(o,r),l=a.map(p=>{const[u,c]=p.output.split(":");return{txid:u,vout:c}});if(s.push(...l),a.length<r)break;if(o+=r,n++,n>=t)throw new Error("Exceeded maximum iterations when fetching inscriptions")}}catch{throw new Error("Failed to get inscriptions from OneKey Wallet")}return s});at(this,"on",(t,r)=>{if(!this.walletInfo)throw new Error("OneKey Wallet not connected");if(t==="accountChanged")return this.provider.on(t,r)});at(this,"off",(t,r)=>{if(!this.walletInfo)throw new Error("OneKey Wallet not connected");if(t==="accountChanged")return this.provider.off(t,r)});at(this,"getWalletProviderName",async()=>WALLET_PROVIDER_NAME$1);at(this,"getWalletProviderIcon",async()=>logo$1);if(this.config=r,!(t!=null&&t.btcwallet))throw new Error("OneKey Wallet extension not found");this.provider=t.btcwallet}}const metadata$3={id:"onekey",name:WALLET_PROVIDER_NAME$1,icon:logo$1,docs:"https://onekey.so/download",wallet:"$onekey",createProvider:(e,t)=>new OneKeyProvider(e,t),networks:[Network.MAINNET,Network.SIGNET]},logo="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='59'%20height='59'%3e%3cdefs%3e%3clinearGradient%20id='a'%20x1='91.9%25'%20x2='5.127%25'%20y1='28.561%25'%20y2='67.452%25'%3e%3cstop%20offset='0%25'%20stop-color='%23070100'/%3e%3cstop%20offset='36%25'%20stop-color='%2377390D'/%3e%3cstop%20offset='67%25'%20stop-color='%23EA8101'/%3e%3cstop%20offset='100%25'%20stop-color='%23F4B852'/%3e%3c/linearGradient%3e%3clinearGradient%20id='b'%20x1='10.514%25'%20x2='111.046%25'%20y1='63.228%25'%20y2='37.55%25'%3e%3cstop%20offset='0%25'%20stop-color='%23070100'/%3e%3cstop%20offset='37%25'%20stop-color='%2377390D'/%3e%3cstop%20offset='67%25'%20stop-color='%23EA8101'/%3e%3cstop%20offset='100%25'%20stop-color='%23F4FB52'/%3e%3c/linearGradient%3e%3cradialGradient%20id='c'%20cx='49.933%25'%20cy='50.067%25'%20r='50%25'%20fx='49.933%25'%20fy='50.067%25'%3e%3cstop%20offset='0%25'%20stop-color='%23F4B852'/%3e%3cstop%20offset='33%25'%20stop-color='%23EA8101'/%3e%3cstop%20offset='64%25'%20stop-color='%2377390D'/%3e%3cstop%20offset='100%25'%20stop-color='%23070100'/%3e%3c/radialGradient%3e%3c/defs%3e%3cg%20fill='none'%20fill-rule='nonzero'%20transform='translate(7%201)'%3e%3cpath%20fill='url(%23a)'%20d='m31.764%205.2%2011.761%2011.745c1%20.997%201.492%202.006%201.475%203.027-.018%201.014-.446%201.947-1.29%202.787-.879.88-1.827%201.33-2.845%201.347-1.017.018-2.023-.478-3.03-1.475L25.81%2010.617c-1.365-1.364-2.683-2.332-3.955-2.898-1.267-.566-2.602-.653-4.002-.268-1.399.385-2.902%201.382-4.51%202.991-2.22%202.217-3.278%204.298-3.168%206.246.11%201.948%201.208%203.96%203.301%206.054L25.6%2034.854c1.012%201.01%201.51%202.018%201.492%203.021-.017%201.003-.45%201.936-1.307%202.788-.855.851-1.792%201.3-2.821%201.335-1.024.035-2.041-.455-3.053-1.464L8.16%2028.79c-1.913-1.913-3.295-3.72-4.145-5.423-.85-1.703-1.168-3.633-.949-5.785.197-1.843.787-3.628%201.758-5.36.977-1.732%202.37-3.499%204.18-5.313%202.157-2.157%204.216-3.808%206.182-4.957C17.153.803%2019.049.161%2020.882.027c1.833-.134%203.643.233%205.435%201.102%201.787.869%203.603%202.222%205.453%204.07h-.006Z'/%3e%3cpath%20fill='url(%23b)'%20d='M13.234%2051.841%201.474%2040.188c-1-.99-1.49-1.99-1.474-3.003.018-1.012.446-1.932%201.29-2.766.878-.873%201.827-1.319%202.844-1.336%201.018-.017%202.024.469%203.03%201.464l12.025%2011.919c1.37%201.354%202.682%202.314%203.954%202.876%201.272.56%202.602.648%204%20.266%201.4-.382%202.903-1.372%204.51-2.968%202.22-2.2%203.278-4.265%203.169-6.197-.11-1.933-1.209-3.935-3.302-6.006l-6.457-6.347c-1.012-1.001-1.51-2.002-1.492-2.998.017-.995.451-1.92%201.307-2.765.855-.845%201.792-1.29%202.82-1.325%201.024-.035%202.042.451%203.053%201.452l6.088%205.983c1.914%201.898%203.296%203.691%204.145%205.38.85%201.69%201.168%203.605.949%205.74-.197%201.829-.787%203.6-1.758%205.318-.977%201.718-2.37%203.471-4.18%205.27-2.156%202.142-4.214%203.78-6.18%204.919-1.966%201.14-3.862%201.776-5.695%201.91-1.832.132-3.642-.232-5.434-1.094-1.787-.862-3.608-2.205-5.452-4.039Z'/%3e%3ccircle%20cx='20'%20cy='18'%20r='4'%20fill='url(%23c)'/%3e%3c/g%3e%3c/svg%3e",WALLET_PROVIDER_NAME="Unisat";class UnisatProvider{constructor(t,r){at(this,"provider");at(this,"walletInfo");at(this,"config");at(this,"connectWallet",async()=>{var o;let t;try{t=await this.provider.requestAccounts()}catch(n){throw(o=n==null?void 0:n.message)!=null&&o.includes("rejected")?new Error("Connection to Unisat Wallet was rejected"):new Error(n==null?void 0:n.message)}const r=t[0];validateAddress(this.config.network,r);const s=await this.provider.getPublicKey();if(s&&r)this.walletInfo={publicKeyHex:s,address:r};else throw new Error("Could not connect to Unisat Wallet")});at(this,"getAddress",async()=>{if(!this.walletInfo)throw new Error("Unisat Wallet not connected");return this.walletInfo.address});at(this,"getPublicKeyHex",async()=>{if(!this.walletInfo)throw new Error("Unisat Wallet not connected");return this.walletInfo.publicKeyHex});at(this,"signPsbt",async t=>{if(!this.walletInfo)throw new Error("Unisat Wallet not connected");if(!t)throw new Error("psbt hex is required");const r=await this.getNetwork();try{return await this.provider.signPsbt(t,this.getSignPsbtDefaultOptions(t,r))}catch(s){throw new Error((s==null?void 0:s.message)||s)}});at(this,"signPsbts",async t=>{if(!this.walletInfo)throw new Error("Unisat Wallet not connected");if(!t&&!Array.isArray(t))throw new Error("psbts hexes are required");const r=await this.getNetwork();try{return await this.provider.signPsbts(t,t.map(s=>this.getSignPsbtDefaultOptions(s,r)))}catch(s){throw new Error((s==null?void 0:s.message)||s)}});at(this,"getNetwork",async()=>{switch((await this.provider.getChain()).enum){case"BITCOIN_MAINNET":return Network.MAINNET;case"BITCOIN_SIGNET":return Network.SIGNET;case"BITCOIN_TESTNET":return Network.SIGNET;default:throw new Error("Unsupported network")}});at(this,"signMessage",async(t,r)=>{if(!this.walletInfo)throw new Error("Unisat Wallet not connected");return await this.provider.signMessage(t,r)});at(this,"getInscriptions",async()=>{if(!this.walletInfo)throw new Error("Unisat Wallet not connected");if(this.config.network!==Network.MAINNET)throw new Error("Inscriptions are only available on Unisat Wallet BTC Mainnet");const t=100,r=100,s=[];let o=0,n=0;try{for(;n<t;){const{list:a}=await this.provider.getInscriptions(o,r),l=a.map(p=>{const[u,c]=p.output.split(":");return{txid:u,vout:c}});if(s.push(...l),a.length<r)break;if(o+=r,n++,n>=t)throw new Error("Exceeded maximum iterations when fetching inscriptions")}}catch{throw new Error("Failed to get inscriptions from Unisat Wallet")}return s});at(this,"on",(t,r)=>{if(!this.walletInfo)throw new Error("Unisat Wallet not connected");if(t==="accountChanged")return this.provider.on("accountsChanged",r)});at(this,"off",(t,r)=>{if(!this.walletInfo)throw new Error("Unisat Wallet not connected");if(t==="accountChanged")return this.provider.removeListener("accountsChanged",r)});at(this,"getWalletProviderName",async()=>WALLET_PROVIDER_NAME);at(this,"getWalletProviderIcon",async()=>logo);if(this.config=r,!t)throw new Error("Unisat Wallet extension not found");this.provider=t}getSignPsbtDefaultOptions(t,r){const s=[];return bitcoinjsLib.Psbt.fromHex(t).data.inputs.forEach((n,a)=>{var u,c;let l=!1;if(n.witnessUtxo&&n.witnessUtxo.script){let v=bitcoinjsLib.networks.bitcoin;(r===Network.TESTNET||r===Network.SIGNET)&&(v=bitcoinjsLib.networks.testnet);let w;try{w=bitcoinjsLib.address.fromOutputScript(n.witnessUtxo.script,v)}catch(I){if(I instanceof Error&&I.message.toLowerCase().includes("has no matching address"))btcStakingTs.initBTCCurve(),w=bitcoinjsLib.address.fromOutputScript(n.witnessUtxo.script,v);else throw new Error(I)}const b=w.indexOf("tb1p")===0||w.indexOf("bc1p")===0,E=w===((u=this.walletInfo)==null?void 0:u.address);b&&E&&(l=!0)}n.finalScriptSig||n.finalScriptWitness||s.push({index:a,publicKey:(c=this.walletInfo)==null?void 0:c.publicKeyHex,sighashTypes:void 0,useTweakedSigner:l})}),{autoFinalized:!0,toSignInputs:s}}}const metadata$2={id:"unisat",name:WALLET_PROVIDER_NAME,icon:logo,docs:"https://unisat.io/download",wallet:"unisat",createProvider:(e,t)=>new UnisatProvider(e,t),networks:[Network.MAINNET,Network.SIGNET]},metadata$1={chain:"BTC",name:"Bitcoin",icon,wallets:[metadata$6,metadata$4,metadata$3,metadata$2,metadata$5]},metadata={BTC:metadata$1,BBN:metadata$7};function usePersistState(e,t,r){function s(){const a=r;if(typeof t>"u")return a;const l=t.getItem(e);return(l?JSON.parse(l):null)??a}const[o,n]=react.useState(s);return react.useEffect(function(){t.setItem(e,JSON.stringify(o??""))},[e,t,o]),[o,n]}const Context$2=react.createContext({lockInscriptions:!0,showAgain:!0});function InscriptionProvider({children:e,context:t}){const[r,s]=usePersistState("bwc-inscription-modal-show-again",t.localStorage,!0),[o,n]=usePersistState("bwc-inscription-modal-lock",t.localStorage,!0),a=react.useMemo(()=>({showAgain:r,lockInscriptions:o,toggleLockInscriptions:n,toggleShowAgain:s}),[r,o,n,s]);return jsxRuntime.jsx(Context$2.Provider,{value:a,children:e})}const useInscriptionProvider=()=>react.useContext(Context$2),defaultState$2={confirmed:!1,visible:!1,screen:{type:"TERMS_OF_SERVICE"},chains:{},selectedWallets:{}},StateContext=react.createContext(defaultState$2);function StateProvider({children:e,chains:t}){const[r,s]=react.useState(defaultState$2);react.useEffect(()=>{s(a=>({...a,chains:t.reduce((l,p)=>({...l,[p.id]:p}),{})}))},[t]);const o=react.useMemo(()=>({open:()=>{s(a=>({...a,visible:!0}))},close:()=>{s(a=>({...a,visible:!1}))},reset:()=>{s(({chains:a})=>({...defaultState$2,chains:a}))},displayLoader:(a="")=>{s(l=>({...l,screen:{type:"LOADER",params:{message:a}}}))},displayTermsOfService:()=>{s(a=>({...a,screen:{type:"TERMS_OF_SERVICE"}}))},displayChains:()=>{s(a=>({...a,screen:{type:"CHAINS"}}))},displayWallets:a=>{s(l=>({...l,screen:{type:"WALLETS",params:{chain:a}}}))},displayInscriptions:()=>{s(a=>({...a,screen:{type:"INSCRIPTIONS"}}))},displayError:a=>{s(l=>({...l,screen:{type:"ERROR",params:a}}))},selectWallet:(a,l)=>{s(p=>({...p,selectedWallets:{...p.selectedWallets,[a]:l}}))},removeWallet:a=>{s(l=>({...l,selectedWallets:{...l.selectedWallets,[a]:void 0}}))},confirm:()=>{s(a=>({...a,confirmed:!0}))}}),[]),n=react.useMemo(()=>({...r,...o}),[r,o]);return jsxRuntime.jsx(StateContext.Provider,{value:n,children:e})}const defaultState$1={BTC:null,BBN:null},Context$1=react.createContext(defaultState$1);function ChainProvider({storage:e,children:t,context:r,config:s,onError:o}){const[n,a]=react.useState(defaultState$1),l=react.useCallback(async()=>{const u=s.filter(v=>metadata[v.chain]).map(({chain:v,config:w})=>createWalletConnector({metadata:metadata[v],context:r,config:w,accountStorage:e}));return(await Promise.all(u)).reduce((v,w)=>({...v,[w.id]:w}),{})},[]);react.useEffect(()=>{l().then(u=>{a(u)}).catch(o)},[a,l,o]);const p=react.useMemo(()=>Object.values(n).filter(Boolean),[n]);return jsxRuntime.jsx(InscriptionProvider,{context:r,children:jsxRuntime.jsx(StateProvider,{chains:p,children:jsxRuntime.jsx(Context$1.Provider,{value:n,children:t})})})}const useChainProviders=()=>react.useContext(Context$1),Context=react.createContext({});function LifeCycleHooksProvider({children:e,value:t}){const r=react.useMemo(()=>t??{},[t]);return jsxRuntime.jsx(Context.Provider,{value:r,children:e})}const useLifeCycleHooks=()=>react.useContext(Context),CONNECTED_ACCOUNTS_KEY="baby-connected-wallet-accounts",createAccountStorage=e=>({get:t=>{const r=localStorage.getItem(CONNECTED_ACCOUNTS_KEY)?JSON.parse(localStorage.getItem(CONNECTED_ACCOUNTS_KEY)||"{}"):{};if(!(r._timestamp&&Date.now()-r._timestamp>e))return r[t]},has:t=>{const r=localStorage.getItem(CONNECTED_ACCOUNTS_KEY)?JSON.parse(localStorage.getItem(CONNECTED_ACCOUNTS_KEY)||"{}"):{};return r._timestamp&&Date.now()-r._timestamp>e?!1:!!r[t]},set:(t,r)=>{const s=localStorage.getItem(CONNECTED_ACCOUNTS_KEY)?JSON.parse(localStorage.getItem(CONNECTED_ACCOUNTS_KEY)||"{}"):{};s[t]=r,s._timestamp=Date.now(),localStorage.setItem(CONNECTED_ACCOUNTS_KEY,JSON.stringify(s))},delete:t=>{const r=localStorage.getItem(CONNECTED_ACCOUNTS_KEY)?JSON.parse(localStorage.getItem(CONNECTED_ACCOUNTS_KEY)||"{}"):{},s=Reflect.deleteProperty(r,t);return localStorage.setItem(CONNECTED_ACCOUNTS_KEY,JSON.stringify(r)),s}});var freeGlobal=typeof commonjsGlobal=="object"&&commonjsGlobal&&commonjsGlobal.Object===Object&&commonjsGlobal,freeSelf=typeof self=="object"&&self&&self.Object===Object&&self;freeGlobal||freeSelf||Function("return this")();var useIsomorphicLayoutEffect=typeof window<"u"?react.useLayoutEffect:react.useEffect,IS_SERVER2=typeof window>"u";function useMediaQuery(e,{defaultValue:t=!1,initializeWithValue:r=!0}={}){const s=l=>IS_SERVER2?t:window.matchMedia(l).matches,[o,n]=react.useState(()=>r?s(e):t);function a(){n(s(e))}return useIsomorphicLayoutEffect(()=>{const l=window.matchMedia(e);return a(),l.addListener?l.addListener(a):l.addEventListener("change",a),()=>{l.removeListener?l.removeListener(a):l.removeEventListener("change",a)}},[e]),o}const useIsMobileView=()=>useMediaQuery("(max-width: 768px)");function ResponsiveDialog(e){const r=useIsMobileView()?coreUi.MobileDialog:coreUi.Dialog;return jsxRuntime.jsx(r,{...e})}const useWidgetState=()=>react.useContext(StateContext);function useWalletConnect(){const{confirmed:e,chains:t,selectedWallets:r,open:s,reset:o}=useWidgetState(),n=useChainProviders(),a=react.useCallback(()=>{o==null||o(),s==null||s()},[s,o]),l=react.useCallback(async()=>{for(const u of Object.values(n))u&&await u.disconnect();o==null||o()},[n,o]),p=react.useMemo(()=>Object.values(t).filter(Boolean).map(v=>r[v.id]).every(Boolean),[t,r]);return{selected:p,connected:p&&e,open:a,disconnect:l}}const ANIMATION_DELAY$1=1e3;function useWalletConnectors({accountStorage:e,onError:t}){const r=useChainProviders(),{selectWallet:s,removeWallet:o,displayLoader:n,displayChains:a,displayInscriptions:l,displayError:p,confirm:u,close:c,reset:v}=useWidgetState(),{showAgain:w}=useInscriptionProvider(),{verifyBTCAddress:b,acceptTermsOfService:E}=useLifeCycleHooks();react.useEffect(()=>{const M=Object.values(r).filter(Boolean).map(q=>q.on("connecting",U=>{n==null||n(U)}));return()=>M.forEach(q=>q())},[n,r]),react.useEffect(()=>{const B=Object.values(r).filter(Boolean),M={BTC:U=>async F=>{var y,T,D;F&&F.account&&(s==null||s("BTC",F),e.set(U.id,F.id),E==null||E({address:F.account.address,public_key:F.account.publicKeyHex}));const j=()=>void(w?l==null?void 0:l():a==null?void 0:a());if(!validateAddressWithPK(((y=F.account)==null?void 0:y.address)??"",((T=F.account)==null?void 0:T.publicKeyHex)??"",U.config.network)){p==null||p({title:"Public Key Mismatch",description:"The Bitcoin address and Public Key for this wallet do not match. Please contact your wallet provider for support.",onSubmit:j,onCancel:()=>{o==null||o(U.id),a==null||a()}});return}if(b&&!await b(((D=F.account)==null?void 0:D.address)??"")){for(const L of B)await L.disconnect();p==null||p({title:"Connection Failed",description:"The wallet cannot be connected.",submitButton:"",cancelButton:"Done",onCancel:async()=>{c==null||c(),setTimeout(()=>void(v==null?void 0:v()),ANIMATION_DELAY$1)}});return}j()},BBN:U=>F=>{F&&(s==null||s(U.id,F),e.set(U.id,F.id)),a==null||a()}},q=B.map(U=>{var F;return U.on("connect",(F=M[U.id])==null?void 0:F.call(M,U))});return B.forEach(U=>{s==null||s(U.id,U.connectedWallet)}),()=>q.forEach(U=>U())},[s,o,l,a,b,v,c,r,w]),react.useEffect(()=>{const M=Object.values(r).filter(Boolean).map(q=>q.on("disconnect",U=>{U&&(o==null||o(q.id),a==null||a(),e.delete(q.id))}));return()=>M.forEach(q=>q())},[o,a,r]),react.useEffect(()=>{const M=Object.values(r).filter(Boolean).map(q=>q.on("error",U=>{t==null||t(U),a==null||a()}));return()=>M.forEach(q=>q())},[t,a,r]),react.useEffect(()=>{const B=Object.values(r).filter(Boolean);B.length&&B.every(M=>e.has(M.id))&&(u==null||u(),a==null||a())},[r,u,a]);const I=react.useCallback(async(B,M)=>{const q=r[B.id];await(q==null?void 0:q.connect(M.id))},[r]),x=react.useCallback(async B=>{const M=r[B];await(M==null?void 0:M.disconnect())},[r]);return{connect:I,disconnect:x}}function useWalletWidgets(e,t){const r=react.useCallback((s,o)=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:o.map(({id:n,widget:a})=>jsxRuntime.jsx(a,{id:n,connector:e[s],createWallet:createExternalWallet},n))}),[e]);return react.useMemo(()=>t.reduce((s,o)=>({...s,[o.chain]:r(o.chain,o.connectors??[])}),{}),[r,t])}function ChainButton({className:e,disabled:t,alt:r,logo:s,title:o,children:n,onClick:a}){const l=typeof s=="string"?jsxRuntime.jsx(coreUi.Avatar,{url:s,alt:r}):jsxRuntime.jsx(coreUi.Avatar,{children:s});return jsxRuntime.jsxs(coreUi.Text,{disabled:t,as:t?"div":"button",className:tailwindMerge.twMerge("flex w-full flex-col gap-2.5 rounded border border-secondary-strokeLight bg-surface p-4 text-accent-primary",t?"pointer-events-none":"pointer-events-auto",t?"cursor-default":"cursor-pointer",e),onClick:a,children:[jsxRuntime.jsxs("div",{className:"flex w-full items-center gap-2.5",children:[jsxRuntime.jsx("div",{className:"flex items-center",children:l}),o,!t&&jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",className:"ml-auto block",children:jsxRuntime.jsx("path",{d:"M8.58984 16.59L13.1698 12L8.58984 7.41L9.99984 6L15.9998 12L9.99984 18L8.58984 16.59Z",fill:"currentColor"})})]}),n&&jsxRuntime.jsx("div",{className:"pointer-events-auto w-full",onClick:p=>p.stopPropagation(),children:n})]})}const formatAddress=(e,t=8)=>e.length<=t?e:t===0?"...":`${e.slice(0,t/2)}...${e.slice(-t/2)}`,ConnectedWallet=react.memo(({className:e,chainId:t,logo:r,name:s,address:o,onDisconnect:n})=>jsxRuntime.jsxs("div",{className:tailwindMerge.twMerge("flex shrink-0 items-center gap-2.5 rounded border border-secondary-main/30 p-2",e),children:[jsxRuntime.jsx(coreUi.Avatar,{variant:"rounded",size:"medium",url:r}),jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col items-start",children:[jsxRuntime.jsx(coreUi.Text,{as:"div",variant:"body2",className:"leading-4 text-accent-primary",children:s}),!!o&&jsxRuntime.jsx(coreUi.Text,{as:"div",variant:"caption",className:"leading-4 text-accent-secondary",children:formatAddress(o)})]}),jsxRuntime.jsx("button",{className:"shrink-0 cursor-pointer",onClick:()=>void(n==null?void 0:n(t)),children:jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",className:"text-secondary-main",fill:"none",children:jsxRuntime.jsx("path",{d:"M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12L19 6.41Z",fill:"currentColor"})})})]})),Chains=react.memo(({disabled:e=!1,chains:t,selectedWallets:r={},className:s,onClose:o,onConfirm:n,onSelectChain:a,onDisconnectWallet:l})=>jsxRuntime.jsxs("div",{className:tailwindMerge.twMerge("flex flex-1 flex-col text-accent-primary",s),children:[jsxRuntime.jsx(coreUi.DialogHeader,{className:"mb-10",title:"Connect Wallets",onClose:o,children:jsxRuntime.jsx(coreUi.Text,{className:"text-accent-secondary",children:"Connect to both Bitcoin and Babylon Chain Wallets"})}),jsxRuntime.jsx(coreUi.DialogBody,{className:"flex flex-col gap-6",children:t.map(p=>{var c;const u=r[p.id];return jsxRuntime.jsx(ChainButton,{disabled:!!u,title:`Select ${p.name} Wallet`,logo:p.icon,alt:p.name,onClick:()=>void(a==null?void 0:a(p)),children:u&&jsxRuntime.jsx(ConnectedWallet,{chainId:p.id,logo:u.icon,name:u.name,address:((c=u.account)==null?void 0:c.address)??"",onDisconnect:l})},p.id)})}),jsxRuntime.jsxs(coreUi.DialogFooter,{className:"mt-auto flex gap-4 pt-10",children:[jsxRuntime.jsx(coreUi.Button,{variant:"outlined",fluid:!0,onClick:o,children:"Cancel"}),jsxRuntime.jsx(coreUi.Button,{disabled:e,fluid:!0,onClick:n,children:"Done"})]})]}));function ChainsContainer(e){const{chains:t,selectedWallets:r,displayWallets:s}=useWidgetState(),{selected:o}=useWalletConnect(),n=react.useMemo(()=>Object.values(t),[t]),a=react.useCallback(l=>{s==null||s(l.id)},[s]);return jsxRuntime.jsx(Chains,{disabled:!o,chains:n,selectedWallets:r,onSelectChain:a,...e})}const DEFAULT_ICON=jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"52",height:"52",viewBox:"0 0 52 52",fill:"none",children:jsxRuntime.jsx("path",{d:"M2.16675 46.5837H49.8334L26.0001 5.41699L2.16675 46.5837ZM28.1667 40.0837H23.8334V35.7503H28.1667V40.0837ZM28.1667 31.417H23.8334V22.7503H28.1667V31.417Z",fill:"#387085"})});function Error$1({className:e,icon:t=DEFAULT_ICON,title:r,description:s,cancelButton:o="Cancel",submitButton:n=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["Continue ",jsxRuntime.jsx("span",{className:"hidden md:inline",children:"Anyway"})]}),onCancel:a,onSubmit:l}){return jsxRuntime.jsxs("div",{className:e,children:[jsxRuntime.jsxs(coreUi.DialogBody,{className:"py-16 text-center",children:[jsxRuntime.jsx("div",{className:"mb-6 inline-flex h-20 w-20 items-center justify-center bg-primary-contrast text-primary-light",children:t}),jsxRuntime.jsx(coreUi.Heading,{variant:"h4",className:"mb-4 text-accent-primary",children:r}),jsxRuntime.jsx(coreUi.Text,{as:"div",className:"text-accent-secondary",children:s})]}),jsxRuntime.jsxs(coreUi.DialogFooter,{className:"flex gap-4",children:[o&&jsxRuntime.jsx(coreUi.Button,{variant:"outlined",fluid:!0,onClick:a,children:o}),n&&jsxRuntime.jsx(coreUi.Button,{fluid:!0,onClick:l,children:n})]})]})}function ErrorContainer({className:e}){const{screen:t}=useWidgetState(),{icon:r,title:s,description:o,cancelButton:n,submitButton:a,onCancel:l,onSubmit:p}=t.params??{};return jsxRuntime.jsx(Error$1,{className:e,icon:r,title:s,description:o,cancelButton:n,submitButton:a,onCancel:l,onSubmit:p})}function FieldControl({label:e,className:t,children:r}){return jsxRuntime.jsxs("label",{className:tailwindMerge.twMerge("flex cursor-pointer gap-4 rounded border border-secondary-strokeLight text-accent-primary p-4",t),children:[r,e]})}function Inscriptions({className:e,config:t,onSubmit:r}){const[s=!0,o]=react.useState(),[n=!0,a]=react.useState();if(!t)return null;const{coinName:l}=t;return jsxRuntime.jsxs("div",{className:tailwindMerge.twMerge("flex flex-1 flex-col",e),children:[jsxRuntime.jsx(coreUi.DialogHeader,{title:`Manage ${l} Inscriptions`,className:"mb-4 text-accent-primary",onClose:()=>void(r==null?void 0:r(s,n))}),jsxRuntime.jsxs(coreUi.DialogBody,{children:[jsxRuntime.jsxs(coreUi.Text,{className:"mb-8 text-accent-secondary",children:["By default, we will not use ",l," that contains Inscriptions - such as Ordinals, NFTs, or Runes - in your stakeable balance. This helps prevent any accidental loss of your Inscriptions due to staking, unbonding, or withdrawal fees."]}),jsxRuntime.jsxs(coreUi.Text,{className:"mb-10 text-accent-secondary",children:["If you would like to include ",l," with Inscriptions in your stakeable balance, please select the option below."]}),jsxRuntime.jsxs("form",{action:"",children:[jsxRuntime.jsx(FieldControl,{label:jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("strong",{className:"mr-2",children:"Do not use"})," ",l," with Inscriptions for staking. (Recommended)"]}),className:"mb-8",children:jsxRuntime.jsx(coreUi.Radio,{name:"inscriptions",checked:s,onChange:()=>o(!0)})}),jsxRuntime.jsx(FieldControl,{label:jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("strong",{className:"mr-2",children:"Use"})," ",l," with Inscriptions in my stakable balance."]}),className:"mb-8",children:jsxRuntime.jsx(coreUi.Radio,{name:"inscriptions",checked:!s,onChange:()=>o(!1)})})]})]}),jsxRuntime.jsxs(coreUi.DialogFooter,{className:"mt-auto pt-10",children:[jsxRuntime.jsx(coreUi.Checkbox,{checked:!n,label:"Do not show again",labelClassName:"mb-6",onChange:p=>a(!p)}),jsxRuntime.jsx(coreUi.Button,{fluid:!0,onClick:()=>void(r==null?void 0:r(s,n)),children:"Save"})]})]})}function InscriptionsContainer({className:e,onSubmit:t}){var s;const{chains:r}=useWidgetState();return jsxRuntime.jsx(Inscriptions,{className:e,onSubmit:t,config:(s=r.BTC)==null?void 0:s.config})}function LoaderScreen({className:e,title:t}){return jsxRuntime.jsxs("div",{className:tailwindMerge.twMerge("flex flex-col items-center justify-center gap-6",e),children:[jsxRuntime.jsx("div",{className:"flex items-center justify-center bg-primary-contrast p-6",children:jsxRuntime.jsx(coreUi.Loader,{className:"text-primary-light"})}),t&&jsxRuntime.jsx(coreUi.Heading,{variant:"h4",className:"capitalize text-accent-primary",children:t})]})}const defaultState={termsOfUse:!1,inscriptions:!1,staking:!1};function TermsOfService({className:e,onClose:t,onSubmit:r}){const[s,o]=react.useState(defaultState),n=react.useMemo(()=>Object.values(s).every(l=>l),[s]),a=react.useCallback(l=>(p=!1)=>{o(u=>({...u,[l]:p}))},[]);return jsxRuntime.jsxs("div",{className:tailwindMerge.twMerge("flex flex-1 flex-col",e),children:[jsxRuntime.jsx(coreUi.DialogHeader,{className:"mb-10 text-accent-primary",title:"Connect Wallets",onClose:t,children:jsxRuntime.jsx(coreUi.Text,{className:"text-accent-secondary",children:"Please read and accept the following terms"})}),jsxRuntime.jsxs(coreUi.DialogBody,{children:[jsxRuntime.jsx(FieldControl,{label:jsxRuntime.jsxs("div",{className:"block",children:["I certify that I have read and accept the updated"," ",jsxRuntime.jsx("a",{href:"https://babylonlabs.io/terms-of-use",target:"_blank",rel:"noopener noreferrer",className:"underline",children:"Terms of Use"})," ","and"," ",jsxRuntime.jsx("a",{href:"https://babylonlabs.io/privacy-policy",target:"_blank",rel:"noopener noreferrer",className:"underline",children:"Privacy Policy"}),"."]}),className:"mb-8",children:jsxRuntime.jsx(coreUi.Checkbox,{checked:s.termsOfUse,onChange:a("termsOfUse")})}),jsxRuntime.jsx(FieldControl,{label:"I certify that I wish to stake bitcoin and agree that doing so may cause some or all of the bitcoin ordinals, NFTs, Runes, and other inscriptions in the connected bitcoin wallet to be lost. I acknowledge that this interface will not detect all Inscriptions.",className:"mb-8",children:jsxRuntime.jsx(coreUi.Checkbox,{checked:s.inscriptions,onChange:a("inscriptions")})}),jsxRuntime.jsx(FieldControl,{label:"I acknowledge that the following are the only hardware wallets supporting Bitcoin Staking: (1) Keystone -- via QR code and (2) OneKey -- via the OneKey Chrome extension and the hardware devices (a) OneKey Pro and (b) OneKey Classic 1s (experimental, 3.10.1 firmware or higher) using Taproot only. Using any other hardware wallet through any means (such as connection to a software/extension/mobile wallet) can lead to permanent inability to withdraw the stake.",children:jsxRuntime.jsx(coreUi.Checkbox,{checked:s.staking,onChange:a("staking")})})]}),jsxRuntime.jsx(coreUi.DialogFooter,{className:"mt-auto pt-10",children:jsxRuntime.jsx(coreUi.Button,{disabled:!n,fluid:!0,onClick:r,children:"Next"})})]})}function TermsOfServiceContainer(e){var r;const{chains:t}=useWidgetState();return jsxRuntime.jsx(TermsOfService,{...e,config:(r=t.BTC)==null?void 0:r.config})}const Wallets=react.memo(({chain:e,className:t,append:r,onClose:s,onBack:o,onSelectWallet:n})=>{const a=react.useMemo(()=>e.wallets.find(u=>u.id==="injectable"&&u.installed),[e]),l=react.useMemo(()=>e.wallets.filter(u=>u.id!=="injectable"),[e]),p=react.useMemo(()=>e.wallets.filter(u=>u.id!=="injectable"||u.installed).length,[e]);return jsxRuntime.jsxs("div",{className:tailwindMerge.twMerge("flex flex-1 flex-col",t),children:[jsxRuntime.jsx(coreUi.DialogHeader,{className:"text-accent-primary mb-10",title:"Select Wallet",onClose:s,children:jsxRuntime.jsxs(coreUi.Text,{className:"text-accent-secondary",children:["Connect a ",e.name," Wallet"]})}),jsxRuntime.jsxs(coreUi.DialogBody,{children:[jsxRuntime.jsxs("div",{className:tailwindMerge.twMerge("grid gap-6",p>1?"grid-cols-1 md:grid-cols-2":"grid-cols-1"),children:[a&&jsxRuntime.jsx(WalletButton,{installed:!0,name:a.name,logo:a.icon,label:a.label,onClick:()=>n==null?void 0:n(e,a)}),l.map(u=>jsxRuntime.jsx(WalletButton,{installed:u.installed,name:u.name,logo:u.icon,label:u.label,fallbackLink:u.docs,onClick:()=>n==null?void 0:n(e,u)},u.id))]}),r]}),jsxRuntime.jsx(coreUi.DialogFooter,{className:"mt-auto pt-10",children:jsxRuntime.jsx(coreUi.Button,{variant:"outlined",fluid:!0,onClick:o,children:"Back"})})]})});function WalletsContainer({widgets:e={},...t}){var p;const{chains:r,screen:s,displayChains:o}=useWidgetState(),n=((p=s.params)==null?void 0:p.chain)??"",a=r==null?void 0:r[n],l=e==null?void 0:e[n];return jsxRuntime.jsx(Wallets,{append:l,chain:a,onBack:o,...t})}const SCREENS={TERMS_OF_SERVICE:({className:e,onClose:t,onAccepTermsOfService:r})=>jsxRuntime.jsx(TermsOfServiceContainer,{className:e,onClose:t,onSubmit:r}),CHAINS:({className:e,onClose:t,onConfirm:r,onDisconnectWallet:s})=>jsxRuntime.jsx(ChainsContainer,{className:e,onClose:t,onConfirm:r,onDisconnectWallet:s}),WALLETS:({className:e,widgets:t,onClose:r,onSelectWallet:s})=>jsxRuntime.jsx(WalletsContainer,{widgets:t,className:e,onClose:r,onSelectWallet:s}),INSCRIPTIONS:({className:e,onToggleInscriptions:t})=>jsxRuntime.jsx(InscriptionsContainer,{className:e,onSubmit:t}),LOADER:({className:e,current:t})=>{var r;return jsxRuntime.jsx(LoaderScreen,{className:e,title:(r=t==null?void 0:t.params)==null?void 0:r.message})},ERROR:()=>jsxRuntime.jsx(ErrorContainer,{className:"min-h-0 md:w-[600px]"}),EMPTY:({className:e})=>jsxRuntime.jsx("div",{className:e})};function Screen(e){const t=SCREENS[e.current.type]??SCREENS.EMPTY;return jsxRuntime.jsx(t,{...e})}const ANIMATION_DELAY=1e3;function WalletDialog({storage:e,config:t,onError:r}){const{visible:s,screen:o,confirmed:n,close:a,confirm:l,displayChains:p}=useWidgetState(),{toggleShowAgain:u,toggleLockInscriptions:c}=useInscriptionProvider(),v=useChainProviders(),w=useWalletWidgets(v,t),{connect:b,disconnect:E}=useWalletConnectors({accountStorage:e,onError:r}),{disconnect:I}=useWalletConnect(),x=react.useCallback(()=>{p==null||p()},[p]),B=react.useCallback((U,F)=>{u==null||u(F),c==null||c(U),p==null||p()},[u,c,p]),M=react.useCallback(()=>{a==null||a(),n||setTimeout(I,ANIMATION_DELAY)},[a,I,n]),q=react.useCallback(()=>{l==null||l(),a==null||a()},[l]);return jsxRuntime.jsx(ResponsiveDialog,{className:"min-h-[80%]",open:s,onClose:M,children:jsxRuntime.jsx(Screen,{current:o,widgets:w,className:"min-h-0 md:size-[600px]",onClose:M,onConfirm:q,onSelectWallet:b,onAccepTermsOfService:x,onToggleInscriptions:B,onDisconnectWallet:E})})}const BBN_TESTNET_RPC_URL="https://rpc-dapp.testnet.babylonlabs.io/",BBN_TESTNET_LCD_URL="https://lcd-dapp.testnet.babylonlabs.io/",bbnTestnet={chainId:"bbn-test-5",chainName:"Babylon Testnet",chainSymbolImageUrl:"https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/bbn-test/chain.png",rpc:BBN_TESTNET_RPC_URL,rest:BBN_TESTNET_LCD_URL,nodeProvider:{name:"Babylonlabs",email:"contact@babylonlabs.io",website:"https://babylonlabs.io/"},bip44:{coinType:118},bech32Config:{bech32PrefixAccAddr:"bbn",bech32PrefixAccPub:"bbnpub",bech32PrefixValAddr:"bbnvaloper",bech32PrefixValPub:"bbnvaloperpub",bech32PrefixConsAddr:"bbnvalcons",bech32PrefixConsPub:"bbnvalconspub"},currencies:[{coinDenom:"BABY",coinMinimalDenom:"ubbn",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/bbn-test/chain.png"}],feeCurrencies:[{coinDenom:"BABY",coinMinimalDenom:"ubbn",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/bbn-test/chain.png",gasPriceStep:{low:.007,average:.007,high:.01}}],stakeCurrency:{coinDenom:"BABY",coinMinimalDenom:"ubbn",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/bbn-test/chain.png"},features:["cosmwasm"]},ONE_HOUR=60*60*1e3;Network.SIGNET,bbnTestnet.currencies[0].coinDenom,bbnTestnet.chainName,bbnTestnet.currencies[0].coinDenom,bbnTestnet.chainId;const storage=createAccountStorage(ONE_HOUR);function WalletProvider({lifecycleHooks:e,children:t,config:r,context:s=window,onError:o}){return jsxRuntime.jsx(LifeCycleHooksProvider,{value:e,children:jsxRuntime.jsxs(ChainProvider,{storage,context:s,config:r,onError:o,children:[t,jsxRuntime.jsx(WalletDialog,{storage,config:r,onError:o})]})})}function useChainConnector(e){const t=useChainProviders();return(t==null?void 0:t[e])??null}exports.Network=Network;exports.StateContext=StateContext;exports.StateProvider=StateProvider;exports.WalletButton=WalletButton;exports.WalletProvider=WalletProvider;exports.createExternalWallet=createExternalWallet;exports.useChainConnector=useChainConnector;exports.useInscriptionProvider=useInscriptionProvider;exports.useWalletConnect=useWalletConnect;exports.useWidgetState=useWidgetState;
|
|
80
80
|
//# sourceMappingURL=index.cjs.js.map
|