signet.js 0.0.1-beta.8 → 0.0.1-beta.9

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.
Files changed (51) hide show
  1. package/browser/index.browser.cjs +12 -0
  2. package/browser/index.browser.cjs.map +1 -0
  3. package/browser/index.browser.js +3927 -0
  4. package/browser/index.browser.js.map +1 -0
  5. package/node/index.node.cjs +19 -0
  6. package/node/index.node.cjs.map +1 -0
  7. package/node/index.node.js +4099 -0
  8. package/node/index.node.js.map +1 -0
  9. package/package.json +17 -11
  10. package/{chains → types/chains}/Bitcoin/Bitcoin.d.ts +2 -29
  11. package/types/chains/Chain.d.ts +21 -0
  12. package/types/chains/ChainSignatureContract.d.ts +18 -0
  13. package/{chains → types/chains}/Cosmos/Cosmos.d.ts +3 -16
  14. package/{chains → types/chains}/EVM/EVM.d.ts +2 -12
  15. package/{chains → types/chains}/index.d.ts +0 -1
  16. package/{chains → types/chains}/types.d.ts +1 -14
  17. package/{utils → types/utils}/chains/near/ChainSignatureContract.d.ts +1 -4
  18. package/types/utils/chains/near/relayer/relayer.d.ts +3 -0
  19. package/{utils → types/utils}/chains/near/signAndSend/keypair.d.ts +1 -2
  20. package/{utils → types/utils}/chains/near/types.d.ts +10 -6
  21. package/types/utils/cryptography.d.ts +3 -0
  22. package/types/utils/index.d.ts +2 -0
  23. package/chains/Chain.d.ts +0 -74
  24. package/chains/ChainSignatureContract.d.ts +0 -41
  25. package/chains/utils.d.ts +0 -12
  26. package/index.cjs +0 -2
  27. package/index.cjs.map +0 -1
  28. package/index.js +0 -2674
  29. package/index.js.map +0 -1
  30. package/utils/chains/near/relayer/relayer.d.ts +0 -8
  31. package/utils/index.d.ts +0 -1
  32. /package/{chains → types/chains}/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.d.ts +0 -0
  33. /package/{chains → types/chains}/Bitcoin/BTCRpcAdapter/Mempool/Mempool.d.ts +0 -0
  34. /package/{chains → types/chains}/Bitcoin/BTCRpcAdapter/Mempool/index.d.ts +0 -0
  35. /package/{chains → types/chains}/Bitcoin/BTCRpcAdapter/Mempool/types.d.ts +0 -0
  36. /package/{chains → types/chains}/Bitcoin/BTCRpcAdapter/index.d.ts +0 -0
  37. /package/{chains → types/chains}/Bitcoin/types.d.ts +0 -0
  38. /package/{chains → types/chains}/Bitcoin/utils.d.ts +0 -0
  39. /package/{chains → types/chains}/Cosmos/types.d.ts +0 -0
  40. /package/{chains → types/chains}/Cosmos/utils.d.ts +0 -0
  41. /package/{chains → types/chains}/EVM/types.d.ts +0 -0
  42. /package/{chains → types/chains}/EVM/utils.d.ts +0 -0
  43. /package/{index.d.ts → types/index.d.ts} +0 -0
  44. /package/{utils → types/utils}/chains/index.d.ts +0 -0
  45. /package/{utils → types/utils}/chains/near/account.d.ts +0 -0
  46. /package/{utils → types/utils}/chains/near/constants.d.ts +0 -0
  47. /package/{utils → types/utils}/chains/near/index.d.ts +0 -0
  48. /package/{utils → types/utils}/chains/near/relayer/index.d.ts +0 -0
  49. /package/{utils → types/utils}/chains/near/relayer/types.d.ts +0 -0
  50. /package/{utils → types/utils}/chains/near/signAndSend/index.d.ts +0 -0
  51. /package/{utils → types/utils}/chains/near/transactionBuilder.d.ts +0 -0
@@ -0,0 +1,12 @@
1
+ "use strict";const sn=require("bn.js"),re=require("@cosmjs/encoding"),W=require("ethers"),cn=require("bitcoinjs-lib"),We=require("@near-js/accounts"),zt=require("@near-js/crypto"),un=require("@near-js/transactions"),dn=require("bs58"),fn=require("@near-js/keystores"),ln=require("coinselect"),pn=require("@cosmjs/amino"),Fe=require("@cosmjs/crypto"),ge=require("@cosmjs/proto-signing"),Te=require("@cosmjs/stargate"),nt=require("bech32"),rt=require("chain-registry");function He(n){return n&&n.__esModule?n:{default:n}}function yn(n){if(n&&n.__esModule)return n;const r=Object.create(null);if(n){for(const d in n)if(d!=="default"){const s=Object.getOwnPropertyDescriptor(n,d);Object.defineProperty(r,d,s.get?s:{enumerable:!0,get:function(){return n[d]}})}}return r.default=n,Object.freeze(r)}const fe=He(sn),ie=yn(cn),Gt=He(dn),hn=He(ln);var it=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},Ue={},H={},te={},me={},ot;function Xe(){return ot||(ot=1,me.__esModule=!0,me.integers=void 0,me.integers=["u8","u16","u32","u64","u128","i8","i16","i32","i64","i128","f32","f64"]),me}var se={},at;function $t(){if(at)return se;at=1,se.__esModule=!0,se.DecodeBuffer=se.EncodeBuffer=void 0;var n=function(){function d(){this.offset=0,this.buffer_size=256,this.buffer=new ArrayBuffer(this.buffer_size),this.view=new DataView(this.buffer)}return d.prototype.resize_if_necessary=function(s){if(this.buffer_size-this.offset<s){this.buffer_size=Math.max(this.buffer_size*2,this.buffer_size+s);var i=new ArrayBuffer(this.buffer_size);new Uint8Array(i).set(new Uint8Array(this.buffer)),this.buffer=i,this.view=new DataView(i)}},d.prototype.get_used_buffer=function(){return new Uint8Array(this.buffer).slice(0,this.offset)},d.prototype.store_value=function(s,i){var a=i.substring(1),c=parseInt(a)/8;this.resize_if_necessary(c);var u=i[0]==="f"?"setFloat".concat(a):i[0]==="i"?"setInt".concat(a):"setUint".concat(a);this.view[u](this.offset,s,!0),this.offset+=c},d.prototype.store_bytes=function(s){this.resize_if_necessary(s.length),new Uint8Array(this.buffer).set(new Uint8Array(s),this.offset),this.offset+=s.length},d}();se.EncodeBuffer=n;var r=function(){function d(s){this.offset=0,this.buffer_size=s.length,this.buffer=new ArrayBuffer(s.length),new Uint8Array(this.buffer).set(s),this.view=new DataView(this.buffer)}return d.prototype.assert_enough_buffer=function(s){if(this.offset+s>this.buffer.byteLength)throw new Error("Error in schema, the buffer is smaller than expected")},d.prototype.consume_value=function(s){var i=s.substring(1),a=parseInt(i)/8;this.assert_enough_buffer(a);var c=s[0]==="f"?"getFloat".concat(i):s[0]==="i"?"getInt".concat(i):"getUint".concat(i),u=this.view[c](this.offset,!0);return this.offset+=a,u},d.prototype.consume_bytes=function(s){this.assert_enough_buffer(s);var i=this.buffer.slice(this.offset,this.offset+s);return this.offset+=s,i},d}();return se.DecodeBuffer=r,se}var K={},st;function Vt(){if(st)return K;st=1;var n=K.__extends||function(){var h=function(m,v){return h=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(N,M){N.__proto__=M}||function(N,M){for(var e in M)Object.prototype.hasOwnProperty.call(M,e)&&(N[e]=M[e])},h(m,v)};return function(m,v){if(typeof v!="function"&&v!==null)throw new TypeError("Class extends value "+String(v)+" is not a constructor or null");h(m,v);function N(){this.constructor=m}m.prototype=v===null?Object.create(v):(N.prototype=v.prototype,new N)}}();K.__esModule=!0,K.validate_schema=K.ErrorSchema=K.expect_enum=K.expect_same_size=K.expect_bigint=K.expect_type=K.isArrayLike=void 0;var r=Xe();function d(h){return Array.isArray(h)||!!h&&typeof h=="object"&&"length"in h&&typeof h.length=="number"&&(h.length===0||h.length>0&&h.length-1 in h)}K.isArrayLike=d;function s(h,m,v){if(typeof h!==m)throw new Error("Expected ".concat(m," not ").concat(typeof h,"(").concat(h,") at ").concat(v.join(".")))}K.expect_type=s;function i(h,m){var v=["number","string","bigint","boolean"].includes(typeof h),N=typeof h=="object"&&h!==null&&"toString"in h;if(!v&&!N)throw new Error("Expected bigint, number, boolean or string not ".concat(typeof h,"(").concat(h,") at ").concat(m.join(".")))}K.expect_bigint=i;function a(h,m,v){if(h!==m)throw new Error("Array length ".concat(h," does not match schema length ").concat(m," at ").concat(v.join(".")))}K.expect_same_size=a;function c(h,m){if(typeof h!="object"||h===null)throw new Error("Expected object not ".concat(typeof h,"(").concat(h,") at ").concat(m.join(".")))}K.expect_enum=c;var u=r.integers.concat(["bool","string"]),f=["option","enum","array","set","map","struct"],y=function(h){n(m,h);function m(v,N){var M="Invalid schema: ".concat(JSON.stringify(v)," expected ").concat(N);return h.call(this,M)||this}return m}(Error);K.ErrorSchema=y;function b(h){if(!(typeof h=="string"&&u.includes(h))){if(h&&typeof h=="object"){var m=Object.keys(h);if(m.length===1&&f.includes(m[0])){var v=m[0];if(v==="option")return b(h[v]);if(v==="enum")return l(h[v]);if(v==="array")return _(h[v]);if(v==="set")return b(h[v]);if(v==="map")return p(h[v]);if(v==="struct")return g(h[v])}}throw new y(h,f.join(", ")+" or "+u.join(", "))}}K.validate_schema=b;function l(h){if(!Array.isArray(h))throw new y(h,"Array");for(var m=0,v=h;m<v.length;m++){var N=v[m];if(typeof N!="object"||!("struct"in N))throw new Error('Missing "struct" key in enum schema');if(typeof N.struct!="object"||Object.keys(N.struct).length!==1)throw new Error('The "struct" in each enum must have a single key');b({struct:N.struct})}}function _(h){if(typeof h!="object")throw new y(h,"{ type, len? }");if(h.len&&typeof h.len!="number")throw new Error("Invalid schema: ".concat(h));if("type"in h)return b(h.type);throw new y(h,"{ type, len? }")}function p(h){if(typeof h=="object"&&"key"in h&&"value"in h)b(h.key),b(h.value);else throw new y(h,"{ key, value }")}function g(h){if(typeof h!="object")throw new y(h,"object");for(var m in h)b(h[m])}return K}var ct;function gn(){if(ct)return te;ct=1;var n=te.__createBinding||(Object.create?function(u,f,y,b){b===void 0&&(b=y);var l=Object.getOwnPropertyDescriptor(f,y);(!l||("get"in l?!f.__esModule:l.writable||l.configurable))&&(l={enumerable:!0,get:function(){return f[y]}}),Object.defineProperty(u,b,l)}:function(u,f,y,b){b===void 0&&(b=y),u[b]=f[y]}),r=te.__setModuleDefault||(Object.create?function(u,f){Object.defineProperty(u,"default",{enumerable:!0,value:f})}:function(u,f){u.default=f}),d=te.__importStar||function(u){if(u&&u.__esModule)return u;var f={};if(u!=null)for(var y in u)y!=="default"&&Object.prototype.hasOwnProperty.call(u,y)&&n(f,u,y);return r(f,u),f};te.__esModule=!0,te.BorshSerializer=void 0;var s=Xe(),i=$t(),a=d(Vt()),c=function(){function u(f){this.encoded=new i.EncodeBuffer,this.fieldPath=["value"],this.checkTypes=f}return u.prototype.encode=function(f,y){return this.encode_value(f,y),this.encoded.get_used_buffer()},u.prototype.encode_value=function(f,y){if(typeof y=="string"){if(s.integers.includes(y))return this.encode_integer(f,y);if(y==="string")return this.encode_string(f);if(y==="bool")return this.encode_boolean(f)}if(typeof y=="object"){if("option"in y)return this.encode_option(f,y);if("enum"in y)return this.encode_enum(f,y);if("array"in y)return this.encode_array(f,y);if("set"in y)return this.encode_set(f,y);if("map"in y)return this.encode_map(f,y);if("struct"in y)return this.encode_struct(f,y)}},u.prototype.encode_integer=function(f,y){var b=parseInt(y.substring(1));b<=32||y=="f64"?(this.checkTypes&&a.expect_type(f,"number",this.fieldPath),this.encoded.store_value(f,y)):(this.checkTypes&&a.expect_bigint(f,this.fieldPath),this.encode_bigint(BigInt(f),b))},u.prototype.encode_bigint=function(f,y){for(var b=y/8,l=new Uint8Array(b),_=0;_<b;_++)l[_]=Number(f&BigInt(255)),f=f>>BigInt(8);this.encoded.store_bytes(new Uint8Array(l))},u.prototype.encode_string=function(f){this.checkTypes&&a.expect_type(f,"string",this.fieldPath);var y=f;this.encoded.store_value(y.length,"u32");for(var b=0;b<y.length;b++)this.encoded.store_value(y.charCodeAt(b),"u8")},u.prototype.encode_boolean=function(f){this.checkTypes&&a.expect_type(f,"boolean",this.fieldPath),this.encoded.store_value(f?1:0,"u8")},u.prototype.encode_option=function(f,y){f==null?this.encoded.store_value(0,"u8"):(this.encoded.store_value(1,"u8"),this.encode_value(f,y.option))},u.prototype.encode_enum=function(f,y){this.checkTypes&&a.expect_enum(f,this.fieldPath);for(var b=Object.keys(f)[0],l=0;l<y.enum.length;l++){var _=y.enum[l];if(b===Object.keys(_.struct)[0])return this.encoded.store_value(l,"u8"),this.encode_struct(f,_)}throw new Error("Enum key (".concat(b,") not found in enum schema: ").concat(JSON.stringify(y)," at ").concat(this.fieldPath.join(".")))},u.prototype.encode_array=function(f,y){if(a.isArrayLike(f))return this.encode_arraylike(f,y);if(f instanceof ArrayBuffer)return this.encode_buffer(f,y);throw new Error("Expected Array-like not ".concat(typeof f,"(").concat(f,") at ").concat(this.fieldPath.join(".")))},u.prototype.encode_arraylike=function(f,y){y.array.len?a.expect_same_size(f.length,y.array.len,this.fieldPath):this.encoded.store_value(f.length,"u32");for(var b=0;b<f.length;b++)this.encode_value(f[b],y.array.type)},u.prototype.encode_buffer=function(f,y){y.array.len?a.expect_same_size(f.byteLength,y.array.len,this.fieldPath):this.encoded.store_value(f.byteLength,"u32"),this.encoded.store_bytes(new Uint8Array(f))},u.prototype.encode_set=function(f,y){this.checkTypes&&a.expect_type(f,"object",this.fieldPath);var b=f instanceof Set,l=b?Array.from(f.values()):Object.values(f);this.encoded.store_value(l.length,"u32");for(var _=0,p=l;_<p.length;_++){var g=p[_];this.encode_value(g,y.set)}},u.prototype.encode_map=function(f,y){this.checkTypes&&a.expect_type(f,"object",this.fieldPath);var b=f instanceof Map,l=b?Array.from(f.keys()):Object.keys(f);this.encoded.store_value(l.length,"u32");for(var _=0,p=l;_<p.length;_++){var g=p[_];this.encode_value(g,y.map.key),this.encode_value(b?f.get(g):f[g],y.map.value)}},u.prototype.encode_struct=function(f,y){this.checkTypes&&a.expect_type(f,"object",this.fieldPath);for(var b=0,l=Object.keys(y.struct);b<l.length;b++){var _=l[b];this.fieldPath.push(_),this.encode_value(f[_],y.struct[_]),this.fieldPath.pop()}},u}();return te.BorshSerializer=c,te}var be={},ut;function mn(){if(ut)return be;ut=1,be.__esModule=!0,be.BorshDeserializer=void 0;var n=Xe(),r=$t(),d=function(){function s(i){this.buffer=new r.DecodeBuffer(i)}return s.prototype.decode=function(i){return this.decode_value(i)},s.prototype.decode_value=function(i){if(typeof i=="string"){if(n.integers.includes(i))return this.decode_integer(i);if(i==="string")return this.decode_string();if(i==="bool")return this.decode_boolean()}if(typeof i=="object"){if("option"in i)return this.decode_option(i);if("enum"in i)return this.decode_enum(i);if("array"in i)return this.decode_array(i);if("set"in i)return this.decode_set(i);if("map"in i)return this.decode_map(i);if("struct"in i)return this.decode_struct(i)}throw new Error("Unsupported type: ".concat(i))},s.prototype.decode_integer=function(i){var a=parseInt(i.substring(1));return a<=32||i=="f64"?this.buffer.consume_value(i):this.decode_bigint(a,i.startsWith("i"))},s.prototype.decode_bigint=function(i,a){a===void 0&&(a=!1);var c=i/8,u=new Uint8Array(this.buffer.consume_bytes(c)),f=u.reduceRight(function(y,b){return y+b.toString(16).padStart(2,"0")},"");return a&&u[c-1]?BigInt.asIntN(i,BigInt("0x".concat(f))):BigInt("0x".concat(f))},s.prototype.decode_string=function(){var i=this.decode_integer("u32"),a=new Uint8Array(this.buffer.consume_bytes(i));return String.fromCharCode.apply(null,a)},s.prototype.decode_boolean=function(){return this.buffer.consume_value("u8")>0},s.prototype.decode_option=function(i){var a=this.buffer.consume_value("u8");if(a===1)return this.decode_value(i.option);if(a!==0)throw new Error("Invalid option ".concat(a));return null},s.prototype.decode_enum=function(i){var a,c=this.buffer.consume_value("u8");if(c>i.enum.length)throw new Error("Enum option ".concat(c," is not available"));var u=i.enum[c].struct,f=Object.keys(u)[0];return a={},a[f]=this.decode_value(u[f]),a},s.prototype.decode_array=function(i){for(var a=[],c=i.array.len?i.array.len:this.decode_integer("u32"),u=0;u<c;++u)a.push(this.decode_value(i.array.type));return a},s.prototype.decode_set=function(i){for(var a=this.decode_integer("u32"),c=new Set,u=0;u<a;++u)c.add(this.decode_value(i.set));return c},s.prototype.decode_map=function(i){for(var a=this.decode_integer("u32"),c=new Map,u=0;u<a;++u){var f=this.decode_value(i.map.key),y=this.decode_value(i.map.value);c.set(f,y)}return c},s.prototype.decode_struct=function(i){var a={};for(var c in i.struct)a[c]=this.decode_value(i.struct[c]);return a},s}();return be.BorshDeserializer=d,be}var dt;function bn(){if(dt)return H;dt=1;var n=H.__createBinding||(Object.create?function(f,y,b,l){l===void 0&&(l=b);var _=Object.getOwnPropertyDescriptor(y,b);(!_||("get"in _?!y.__esModule:_.writable||_.configurable))&&(_={enumerable:!0,get:function(){return y[b]}}),Object.defineProperty(f,l,_)}:function(f,y,b,l){l===void 0&&(l=b),f[l]=y[b]}),r=H.__setModuleDefault||(Object.create?function(f,y){Object.defineProperty(f,"default",{enumerable:!0,value:y})}:function(f,y){f.default=y}),d=H.__importStar||function(f){if(f&&f.__esModule)return f;var y={};if(f!=null)for(var b in f)b!=="default"&&Object.prototype.hasOwnProperty.call(f,b)&&n(y,f,b);return r(y,f),y};H.__esModule=!0,H.deserialize=H.serialize=void 0;var s=gn(),i=mn(),a=d(Vt());function c(f,y,b){b===void 0&&(b=!0),b&&a.validate_schema(f);var l=new s.BorshSerializer(b);return l.encode(y,f)}H.serialize=c;function u(f,y,b){b===void 0&&(b=!0),b&&a.validate_schema(f);var l=new i.BorshDeserializer(y);return l.decode(f)}return H.deserialize=u,H}var _e={},le={},ft;function _n(){if(ft)return le;ft=1;var n=le.__importDefault||function(d){return d&&d.__esModule?d:{default:d}};Object.defineProperty(le,"__esModule",{value:!0}),le.DEFAULT_FUNCTION_CALL_GAS=void 0;const r=n(fe.default);return le.DEFAULT_FUNCTION_CALL_GAS=new r.default("30000000000000"),le}var Le={},ve={},Je={},Se={},Ie={},lt;function vn(){if(lt)return Ie;lt=1,Object.defineProperty(Ie,"__esModule",{value:!0}),Ie.ConsoleLogger=void 0;class n{constructor(d){this.logLevels=d,this.isLevelEnabled=s=>this.logLevels.includes(s)}print(d,s,...i){switch(d){case"error":case"fatal":return console.error(s,...i);case"warn":return console.warn(s,...i);case"log":return console.log(s,...i);case"debug":case"verbose":return console.debug(s,...i)}}verbose(d,...s){this.isLevelEnabled("verbose")&&this.print("verbose",d,...s)}debug(d,...s){this.isLevelEnabled("debug")&&this.print("debug",d,...s)}log(d,...s){this.isLevelEnabled("log")&&this.print("log",d,...s)}warn(d,...s){this.isLevelEnabled("warn")&&this.print("warn",d,...s)}error(d,...s){this.isLevelEnabled("error")&&this.print("error",d,...s)}fatal(d,...s){this.isLevelEnabled("fatal")&&this.print("fatal",d,...s)}}return Ie.ConsoleLogger=n,Ie}var pt;function Sn(){if(pt)return Se;pt=1;var n;Object.defineProperty(Se,"__esModule",{value:!0}),Se.Logger=void 0;const r=vn(),d=["verbose","debug","log","warn","error","fatal"],s=typeof process=="object"&&process.env.NEAR_NO_LOGS?void 0:new r.ConsoleLogger(d);class i{static error(c,...u){var f;(f=this.instanceRef)===null||f===void 0||f.error(c,...u)}static log(c,...u){var f;(f=this.instanceRef)===null||f===void 0||f.log(c,...u)}static warn(c,...u){var f;(f=this.instanceRef)===null||f===void 0||f.warn(c,...u)}static debug(c,...u){var f,y;(y=(f=this.instanceRef)===null||f===void 0?void 0:f.debug)===null||y===void 0||y.call(f,c,...u)}static verbose(c,...u){var f,y;(y=(f=this.instanceRef)===null||f===void 0?void 0:f.verbose)===null||y===void 0||y.call(f,c,...u)}static fatal(c,...u){var f,y;(y=(f=this.instanceRef)===null||f===void 0?void 0:f.fatal)===null||y===void 0||y.call(f,c,...u)}}return Se.Logger=i,n=i,i.instanceRef=s,i.overrideLogger=a=>{n.instanceRef=a},Se}var yt;function je(){return yt||(yt=1,function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.Logger=void 0;var r=Sn();Object.defineProperty(n,"Logger",{enumerable:!0,get:function(){return r.Logger}})}(Je)),Je}var ht;function In(){if(ht)return ve;ht=1,Object.defineProperty(ve,"__esModule",{value:!0}),ve.logWarning=void 0;const n=je();function r(...d){const[s,...i]=d;n.Logger.warn(s,...i)}return ve.logWarning=r,ve}var z={},we={},Ee={},gt;function wn(){if(gt)return Ee;gt=1,Object.defineProperty(Ee,"__esModule",{value:!0}),Ee.Assignable=void 0;class n{constructor(d){Object.keys(d).map(s=>{this[s]=d[s]})}}return Ee.Assignable=n,Ee}var V={},mt;function En(){if(mt)return V;mt=1,Object.defineProperty(V,"__esModule",{value:!0}),V.ErrorContext=V.TypedError=V.ArgumentTypeError=V.PositionalArgsError=void 0;class n extends Error{constructor(){super("Contract method calls expect named arguments wrapped in object, e.g. { argName1: argValue1, argName2: argValue2 }")}}V.PositionalArgsError=n;class r extends Error{constructor(a,c,u){super(`Expected ${c} for '${a}' argument, but got '${JSON.stringify(u)}'`)}}V.ArgumentTypeError=r;class d extends Error{constructor(a,c,u){super(a),this.type=c||"UntypedError",this.context=u}}V.TypedError=d;class s{constructor(a){this.transactionHash=a}}return V.ErrorContext=s,V}var Ke={},qe={},bt;function An(){return bt||(bt=1,function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.IdType=void 0,function(r){r.Transaction="transaction",r.Receipt="receipt"}(n.IdType||(n.IdType={}))}(qe)),qe}var ze={},_t;function Nn(){return _t||(_t=1,function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.FinalExecutionStatusBasic=n.ExecutionStatusBasic=void 0,function(r){r.Unknown="Unknown",r.Pending="Pending",r.Failure="Failure"}(n.ExecutionStatusBasic||(n.ExecutionStatusBasic={})),function(r){r.NotStarted="NotStarted",r.Started="Started",r.Failure="Failure"}(n.FinalExecutionStatusBasic||(n.FinalExecutionStatusBasic={}))}(ze)),ze}var vt;function Bn(){return vt||(vt=1,function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.FinalExecutionStatusBasic=n.ExecutionStatusBasic=n.IdType=void 0;var r=An();Object.defineProperty(n,"IdType",{enumerable:!0,get:function(){return r.IdType}});var d=Nn();Object.defineProperty(n,"ExecutionStatusBasic",{enumerable:!0,get:function(){return d.ExecutionStatusBasic}}),Object.defineProperty(n,"FinalExecutionStatusBasic",{enumerable:!0,get:function(){return d.FinalExecutionStatusBasic}})}(Ke)),Ke}var St;function On(){return St||(St=1,function(n){var r=we.__createBinding||(Object.create?function(s,i,a,c){c===void 0&&(c=a);var u=Object.getOwnPropertyDescriptor(i,a);(!u||("get"in u?!i.__esModule:u.writable||u.configurable))&&(u={enumerable:!0,get:function(){return i[a]}}),Object.defineProperty(s,c,u)}:function(s,i,a,c){c===void 0&&(c=a),s[c]=i[a]}),d=we.__exportStar||function(s,i){for(var a in s)a!=="default"&&!Object.prototype.hasOwnProperty.call(i,a)&&r(i,s,a)};Object.defineProperty(n,"__esModule",{value:!0}),d(wn(),n),d(En(),n),d(Bn(),n)}(we)),we}var xe={exports:{}},Tn=xe.exports,It;function Dn(){return It||(It=1,function(n,r){(function(d,s){n.exports=s()})(Tn,function(){/*!
2
+ * mustache.js - Logic-less {{mustache}} templates with JavaScript
3
+ * http://github.com/janl/mustache.js
4
+ */var d=Object.prototype.toString,s=Array.isArray||function(w){return d.call(w)==="[object Array]"};function i(A){return typeof A=="function"}function a(A){return s(A)?"array":typeof A}function c(A){return A.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function u(A,w){return A!=null&&typeof A=="object"&&w in A}function f(A,w){return A!=null&&typeof A!="object"&&A.hasOwnProperty&&A.hasOwnProperty(w)}var y=RegExp.prototype.test;function b(A,w){return y.call(A,w)}var l=/\S/;function _(A){return!b(l,A)}var p={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"};function g(A){return String(A).replace(/[&<>"'`=\/]/g,function(B){return p[B]})}var h=/\s*/,m=/\s+/,v=/\s*=/,N=/\s*\}/,M=/#|\^|\/|>|\{|&|=|!/;function e(A,w){if(!A)return[];var B=!1,O=[],T=[],D=[],k=!1,x=!1,U="",L=0;function Q(){if(k&&!x)for(;D.length;)delete T[D.pop()];else D=[];k=!1,x=!1}var oe,ye,et;function tt(X){if(typeof X=="string"&&(X=X.split(m,2)),!s(X)||X.length!==2)throw new Error("Invalid tags: "+X);oe=new RegExp(c(X[0])+"\\s*"),ye=new RegExp("\\s*"+c(X[1])),et=new RegExp("\\s*"+c("}"+X[1]))}tt(w||C.tags);for(var J=new I(A),ee,q,$,he,Oe,ae;!J.eos();){if(ee=J.pos,$=J.scanUntil(oe),$)for(var Re=0,an=$.length;Re<an;++Re)he=$.charAt(Re),_(he)?(D.push(T.length),U+=he):(x=!0,B=!0,U+=" "),T.push(["text",he,ee,ee+1]),ee+=1,he===`
5
+ `&&(Q(),U="",L=0,B=!1);if(!J.scan(oe))break;if(k=!0,q=J.scan(M)||"name",J.scan(h),q==="="?($=J.scanUntil(v),J.scan(v),J.scanUntil(ye)):q==="{"?($=J.scanUntil(et),J.scan(N),J.scanUntil(ye),q="&"):$=J.scanUntil(ye),!J.scan(ye))throw new Error("Unclosed tag at "+J.pos);if(q==">"?Oe=[q,$,ee,J.pos,U,L,B]:Oe=[q,$,ee,J.pos],L++,T.push(Oe),q==="#"||q==="^")O.push(Oe);else if(q==="/"){if(ae=O.pop(),!ae)throw new Error('Unopened section "'+$+'" at '+ee);if(ae[1]!==$)throw new Error('Unclosed section "'+ae[1]+'" at '+ee)}else q==="name"||q==="{"||q==="&"?x=!0:q==="="&&tt($)}if(Q(),ae=O.pop(),ae)throw new Error('Unclosed section "'+ae[1]+'" at '+J.pos);return o(t(T))}function t(A){for(var w=[],B,O,T=0,D=A.length;T<D;++T)B=A[T],B&&(B[0]==="text"&&O&&O[0]==="text"?(O[1]+=B[1],O[3]=B[3]):(w.push(B),O=B));return w}function o(A){for(var w=[],B=w,O=[],T,D,k=0,x=A.length;k<x;++k)switch(T=A[k],T[0]){case"#":case"^":B.push(T),O.push(T),B=T[4]=[];break;case"/":D=O.pop(),D[5]=T[2],B=O.length>0?O[O.length-1][4]:w;break;default:B.push(T)}return w}function I(A){this.string=A,this.tail=A,this.pos=0}I.prototype.eos=function(){return this.tail===""},I.prototype.scan=function(w){var B=this.tail.match(w);if(!B||B.index!==0)return"";var O=B[0];return this.tail=this.tail.substring(O.length),this.pos+=O.length,O},I.prototype.scanUntil=function(w){var B=this.tail.search(w),O;switch(B){case-1:O=this.tail,this.tail="";break;case 0:O="";break;default:O=this.tail.substring(0,B),this.tail=this.tail.substring(B)}return this.pos+=O.length,O};function S(A,w){this.view=A,this.cache={".":this.view},this.parent=w}S.prototype.push=function(w){return new S(w,this)},S.prototype.lookup=function(w){var B=this.cache,O;if(B.hasOwnProperty(w))O=B[w];else{for(var T=this,D,k,x,U=!1;T;){if(w.indexOf(".")>0)for(D=T.view,k=w.split("."),x=0;D!=null&&x<k.length;)x===k.length-1&&(U=u(D,k[x])||f(D,k[x])),D=D[k[x++]];else D=T.view[w],U=u(T.view,w);if(U){O=D;break}T=T.parent}B[w]=O}return i(O)&&(O=O.call(this.view)),O};function E(){this.templateCache={_cache:{},set:function(w,B){this._cache[w]=B},get:function(w){return this._cache[w]},clear:function(){this._cache={}}}}E.prototype.clearCache=function(){typeof this.templateCache<"u"&&this.templateCache.clear()},E.prototype.parse=function(w,B){var O=this.templateCache,T=w+":"+(B||C.tags).join(":"),D=typeof O<"u",k=D?O.get(T):void 0;return k==null&&(k=e(w,B),D&&O.set(T,k)),k},E.prototype.render=function(w,B,O,T){var D=this.parse(w,T),k=B instanceof S?B:new S(B,void 0);return this.renderTokens(D,k,O,w,T)},E.prototype.renderTokens=function(w,B,O,T,D){for(var k="",x,U,L,Q=0,oe=w.length;Q<oe;++Q)L=void 0,x=w[Q],U=x[0],U==="#"?L=this.renderSection(x,B,O,T):U==="^"?L=this.renderInverted(x,B,O,T):U===">"?L=this.renderPartial(x,B,O,D):U==="&"?L=this.unescapedValue(x,B):U==="name"?L=this.escapedValue(x,B):U==="text"&&(L=this.rawValue(x)),L!==void 0&&(k+=L);return k},E.prototype.renderSection=function(w,B,O,T){var D=this,k="",x=B.lookup(w[1]);function U(oe){return D.render(oe,B,O)}if(x){if(s(x))for(var L=0,Q=x.length;L<Q;++L)k+=this.renderTokens(w[4],B.push(x[L]),O,T);else if(typeof x=="object"||typeof x=="string"||typeof x=="number")k+=this.renderTokens(w[4],B.push(x),O,T);else if(i(x)){if(typeof T!="string")throw new Error("Cannot use higher-order sections without the original template");x=x.call(B.view,T.slice(w[3],w[5]),U),x!=null&&(k+=x)}else k+=this.renderTokens(w[4],B,O,T);return k}},E.prototype.renderInverted=function(w,B,O,T){var D=B.lookup(w[1]);if(!D||s(D)&&D.length===0)return this.renderTokens(w[4],B,O,T)},E.prototype.indentPartial=function(w,B,O){for(var T=B.replace(/[^ \t]/g,""),D=w.split(`
6
+ `),k=0;k<D.length;k++)D[k].length&&(k>0||!O)&&(D[k]=T+D[k]);return D.join(`
7
+ `)},E.prototype.renderPartial=function(w,B,O,T){if(O){var D=i(O)?O(w[1]):O[w[1]];if(D!=null){var k=w[6],x=w[5],U=w[4],L=D;return x==0&&U&&(L=this.indentPartial(D,U,k)),this.renderTokens(this.parse(L,T),B,O,L)}}},E.prototype.unescapedValue=function(w,B){var O=B.lookup(w[1]);if(O!=null)return O},E.prototype.escapedValue=function(w,B){var O=B.lookup(w[1]);if(O!=null)return C.escape(O)},E.prototype.rawValue=function(w){return w[1]};var C={name:"mustache.js",version:"4.0.0",tags:["{{","}}"],clearCache:void 0,escape:void 0,parse:void 0,render:void 0,Scanner:void 0,Context:void 0,Writer:void 0,set templateCache(A){F.templateCache=A},get templateCache(){return F.templateCache}},F=new E;return C.clearCache=function(){return F.clearCache()},C.parse=function(w,B){return F.parse(w,B)},C.render=function(w,B,O,T){if(typeof w!="string")throw new TypeError('Invalid template! Template should be a "string" but "'+a(w)+'" was given as the first argument for mustache#render(template, view, partials)');return F.render(w,B,O,T)},C.escape=g,C.Scanner=I,C.Context=S,C.Writer=E,C})}(xe)),xe.exports}var De={},wt;function Wt(){return wt||(wt=1,function(n){var r=De.__importDefault||function(g){return g&&g.__esModule?g:{default:g}};Object.defineProperty(n,"__esModule",{value:!0}),n.baseDecode=n.baseEncode=n.parseNearAmount=n.formatNearAmount=n.NEAR_NOMINATION=n.NEAR_NOMINATION_EXP=void 0;const d=r(fe.default),s=r(Gt.default);n.NEAR_NOMINATION_EXP=24,n.NEAR_NOMINATION=new d.default("10",10).pow(new d.default(n.NEAR_NOMINATION_EXP,10));const i=[],a=new d.default(10);for(let g=0,h=new d.default(5);g<n.NEAR_NOMINATION_EXP;g++,h=h.mul(a))i[g]=h;function c(g,h=n.NEAR_NOMINATION_EXP){const m=new d.default(g,10);if(h!==n.NEAR_NOMINATION_EXP){const M=n.NEAR_NOMINATION_EXP-h-1;M>0&&m.iadd(i[M])}g=m.toString();const v=g.substring(0,g.length-n.NEAR_NOMINATION_EXP)||"0",N=g.substring(g.length-n.NEAR_NOMINATION_EXP).padStart(n.NEAR_NOMINATION_EXP,"0").substring(0,h);return y(`${l(v)}.${N}`)}n.formatNearAmount=c;function u(g){if(!g)return null;g=f(g);const h=g.split("."),m=h[0],v=h[1]||"";if(h.length>2||v.length>n.NEAR_NOMINATION_EXP)throw new Error(`Cannot parse '${g}' as NEAR amount`);return b(m+v.padEnd(n.NEAR_NOMINATION_EXP,"0"))}n.parseNearAmount=u;function f(g){return g.replace(/,/g,"").trim()}function y(g){return g.replace(/\.?0*$/,"")}function b(g){return g=g.replace(/^0+/,""),g===""?"0":g}function l(g){const h=/(-?\d+)(\d{3})/;for(;h.test(g);)g=g.replace(h,"$1,$2");return g}function _(g){if(typeof g=="string"){const h=[];for(let m=0;m<g.length;m++)h.push(g.charCodeAt(m));g=new Uint8Array(h)}return s.default.encode(g)}n.baseEncode=_;function p(g){return new Uint8Array(s.default.decode(g))}n.baseDecode=p}(De)),De}const kn="Exceeded the maximum amount of gas allowed to burn per contract",xn="Method name is empty",Pn="Wasmer compilation error: {{msg}}",Cn="Smart contract panicked: {{panic_msg}}",Mn="Error creating Wasm memory",Rn="Exceeded the prepaid gas",Fn="Method name is not valid UTF8 string",Un="String encoding is bad UTF-16 sequence",Ln="WebAssembly trap: {{msg}}",Jn="Gas instrumentation failed or contract has denied instructions.",Kn="{{promise_idx}} does not correspond to existing promises",qn="Accessed invalid promise result index: {{result_idx}}",zn="Error happened while deserializing the module",Gn="Contract method is not found",$n="Accessed invalid register id: {{register_id}}",Vn="VM Logic returned an invalid receipt index: {{receipt_index}}",Wn="Method name is empty in contract call",Hn="Returning joint promise is currently prohibited",Xn="Stack instrumentation failed",jn="Cannot find contract code for account {{account_id}}",Zn="Invalid method signature",Yn="Integer overflow happened during contract execution",Qn="MemoryAccessViolation",er="Iterator index {{iterator_index}} does not exist",tr="Iterator {{iterator_index}} was invalidated after its creation by performing a mutable operation on trie",nr="VM Logic returned an invalid account id",rr="Error happened while serializing the module",ir="Actions can only be appended to non-joint promise.",or="Internal memory declaration has been found in the module",ar="Error happened during instantiation",sr="{{method_name}} is not allowed in view calls",cr="VM Logic returned an invalid method name",ur="String encoding is bad UTF-8 sequence",dr="Exceeded the account balance",fr="Wasm contract link error: {{msg}}",lr="VM Logic provided an invalid public key",pr="Actor {{actor_id}} doesn't have permission to account {{account_id}} to complete the action",yr="The account {{account_id}} wouldn't have enough balance to cover storage, required to have {{amount}} yoctoNEAR more",hr="Wrong AccessKey used for transaction: transaction is sent to receiver_id={{tx_receiver}}, but is signed with function call access key that restricted to only use with receiver_id={{ak_receiver}}. Either change receiver_id in your transaction or switch to use a FullAccessKey.",gr="Transaction gas or balance cost is too high",mr="Transaction is not signed with the given public key",br=`Signer "{{account_id}}" doesn't have access key with the given public_key {{public_key}}`,_r="Sender {{signer_id}} does not have enough balance {{#formatNear}}{{balance}}{{/formatNear}} for operation costing {{#formatNear}}{{cost}}{{/formatNear}}",vr="Access Key {account_id}:{public_key} does not have enough balance {{#formatNear}}{{allowance}}{{/formatNear}} for transaction costing {{#formatNear}}{{cost}}{{/formatNear}}",Sr="Transaction has expired",Ir="Account {{account_id}} is staking and can not be deleted",wr="Signer {{signer_id}} does not exist",Er="Account {{account_id}} tried to stake {{#formatNear}}{{stake}}{{/formatNear}}, but has staked {{#formatNear}}{{locked}}{{/formatNear}} and only has {{#formatNear}}{{balance}}{{/formatNear}}",Ar="The public key {{public_key}} is already used for an existing access key",Nr="Invalid signer account ID {{signer_id}} according to requirements",Br="The new account_id {{account_id}} can't be created by {{predecessor_id}}",Or="The transaction contains more then one action, but it was signed with an access key which allows transaction to apply only one specific action. To apply more then one actions TX must be signed with a full access key",Tr="Account {{account_id}} is not yet staked, but tried to unstake",Dr="Transaction nonce {{tx_nonce}} must be larger than nonce of the used access key {{ak_nonce}}",kr="Can't create a new account {{account_id}}, because it already exists",xr="Transaction parent block hash doesn't belong to the current chain",Pr="Can't complete the action because account {{account_id}} doesn't exist",Cr="Can't complete the action because access key {{public_key}} doesn't exist",Mr="Transaction method name {{method_name}} isn't allowed by the access key",Rr="Account {{account_id}} can't be deleted. It has {{#formatNear}}{{balance}}{{/formatNear}}, which is enough to cover the rent",Fr="Account {{account_id}} can't be deleted. It has {{#formatNear}}{{balance}}{{/formatNear}}, which is enough to cover it's storage",Ur="Invalid receiver account ID {{receiver_id}} according to requirements",Lr="Account {{account_id}} tries to remove an access key that doesn't exist",Jr="Timeout exceeded",Kr="Connection closed",qr={GasLimitExceeded:kn,MethodEmptyName:xn,WasmerCompileError:Pn,GuestPanic:Cn,Memory:Mn,GasExceeded:Rn,MethodUTF8Error:Fn,BadUTF16:Un,WasmTrap:Ln,GasInstrumentation:Jn,InvalidPromiseIndex:Kn,InvalidPromiseResultIndex:qn,Deserialization:zn,MethodNotFound:Gn,InvalidRegisterId:$n,InvalidReceiptIndex:Vn,EmptyMethodName:Wn,CannotReturnJointPromise:Hn,StackHeightInstrumentation:Xn,CodeDoesNotExist:jn,MethodInvalidSignature:Zn,IntegerOverflow:Yn,MemoryAccessViolation:Qn,InvalidIteratorIndex:er,IteratorWasInvalidated:tr,InvalidAccountId:nr,Serialization:rr,CannotAppendActionToJointPromise:ir,InternalMemoryDeclared:or,Instantiate:ar,ProhibitedInView:sr,InvalidMethodName:cr,BadUTF8:ur,BalanceExceeded:dr,LinkError:fr,InvalidPublicKey:lr,ActorNoPermission:pr,LackBalanceForState:yr,ReceiverMismatch:hr,CostOverflow:gr,InvalidSignature:mr,AccessKeyNotFound:br,NotEnoughBalance:_r,NotEnoughAllowance:vr,Expired:Sr,DeleteAccountStaking:Ir,SignerDoesNotExist:wr,TriesToStake:Er,AddKeyAlreadyExists:Ar,InvalidSigner:Nr,CreateAccountNotAllowed:Br,RequiresFullAccess:Or,TriesToUnstake:Tr,InvalidNonce:Dr,AccountAlreadyExists:kr,InvalidChain:xr,AccountDoesNotExist:Pr,AccessKeyDoesNotExist:Cr,MethodNameMismatch:Mr,DeleteAccountHasRent:Rr,DeleteAccountHasEnoughBalance:Fr,InvalidReceiver:Ur,DeleteKeyDoesNotExist:Lr,Timeout:Jr,Closed:Kr},zr=JSON.parse('{"AccessKeyNotFound":{"name":"AccessKeyNotFound","subtypes":[],"props":{"account_id":"","public_key":""}},"AccountAlreadyExists":{"name":"AccountAlreadyExists","subtypes":[],"props":{"account_id":""}},"AccountDoesNotExist":{"name":"AccountDoesNotExist","subtypes":[],"props":{"account_id":""}},"ActionError":{"name":"ActionError","subtypes":["AccountAlreadyExists","AccountDoesNotExist","CreateAccountOnlyByRegistrar","CreateAccountNotAllowed","ActorNoPermission","DeleteKeyDoesNotExist","AddKeyAlreadyExists","DeleteAccountStaking","LackBalanceForState","TriesToUnstake","TriesToStake","InsufficientStake","FunctionCallError","NewReceiptValidationError","OnlyImplicitAccountCreationAllowed","DeleteAccountWithLargeState","DelegateActionInvalidSignature","DelegateActionSenderDoesNotMatchTxReceiver","DelegateActionExpired","DelegateActionAccessKeyError","DelegateActionInvalidNonce","DelegateActionNonceTooLarge"],"props":{"index":""}},"ActionsValidationError":{"name":"ActionsValidationError","subtypes":["DeleteActionMustBeFinal","TotalPrepaidGasExceeded","TotalNumberOfActionsExceeded","AddKeyMethodNamesNumberOfBytesExceeded","AddKeyMethodNameLengthExceeded","IntegerOverflow","InvalidAccountId","ContractSizeExceeded","FunctionCallMethodNameLengthExceeded","FunctionCallArgumentsLengthExceeded","UnsuitableStakingKey","FunctionCallZeroAttachedGas","DelegateActionMustBeOnlyOne","UnsupportedProtocolFeature"],"props":{}},"ActorNoPermission":{"name":"ActorNoPermission","subtypes":[],"props":{"account_id":"","actor_id":""}},"AddKeyAlreadyExists":{"name":"AddKeyAlreadyExists","subtypes":[],"props":{"account_id":"","public_key":""}},"AddKeyMethodNameLengthExceeded":{"name":"AddKeyMethodNameLengthExceeded","subtypes":[],"props":{"length":"","limit":""}},"AddKeyMethodNamesNumberOfBytesExceeded":{"name":"AddKeyMethodNamesNumberOfBytesExceeded","subtypes":[],"props":{"limit":"","total_number_of_bytes":""}},"AltBn128InvalidInput":{"name":"AltBn128InvalidInput","subtypes":[],"props":{"msg":""}},"BadUTF16":{"name":"BadUTF16","subtypes":[],"props":{}},"BadUTF8":{"name":"BadUTF8","subtypes":[],"props":{}},"BalanceExceeded":{"name":"BalanceExceeded","subtypes":[],"props":{}},"BalanceMismatchError":{"name":"BalanceMismatchError","subtypes":[],"props":{"final_accounts_balance":"","final_postponed_receipts_balance":"","incoming_receipts_balance":"","incoming_validator_rewards":"","initial_accounts_balance":"","initial_postponed_receipts_balance":"","new_delayed_receipts_balance":"","other_burnt_amount":"","outgoing_receipts_balance":"","processed_delayed_receipts_balance":"","slashed_burnt_amount":"","tx_burnt_amount":""}},"CallIndirectOOB":{"name":"CallIndirectOOB","subtypes":[],"props":{}},"CannotAppendActionToJointPromise":{"name":"CannotAppendActionToJointPromise","subtypes":[],"props":{}},"CannotReturnJointPromise":{"name":"CannotReturnJointPromise","subtypes":[],"props":{}},"CodeDoesNotExist":{"name":"CodeDoesNotExist","subtypes":[],"props":{"account_id":""}},"CompilationError":{"name":"CompilationError","subtypes":["CodeDoesNotExist","PrepareError","WasmerCompileError"],"props":{}},"ContractSizeExceeded":{"name":"ContractSizeExceeded","subtypes":[],"props":{"limit":"","size":""}},"CostOverflow":{"name":"CostOverflow","subtypes":[],"props":{}},"CreateAccountNotAllowed":{"name":"CreateAccountNotAllowed","subtypes":[],"props":{"account_id":"","predecessor_id":""}},"CreateAccountOnlyByRegistrar":{"name":"CreateAccountOnlyByRegistrar","subtypes":[],"props":{"account_id":"","predecessor_id":"","registrar_account_id":""}},"DelegateActionExpired":{"name":"DelegateActionExpired","subtypes":[],"props":{}},"DelegateActionInvalidNonce":{"name":"DelegateActionInvalidNonce","subtypes":[],"props":{"ak_nonce":"","delegate_nonce":""}},"DelegateActionInvalidSignature":{"name":"DelegateActionInvalidSignature","subtypes":[],"props":{}},"DelegateActionMustBeOnlyOne":{"name":"DelegateActionMustBeOnlyOne","subtypes":[],"props":{}},"DelegateActionNonceTooLarge":{"name":"DelegateActionNonceTooLarge","subtypes":[],"props":{"delegate_nonce":"","upper_bound":""}},"DelegateActionSenderDoesNotMatchTxReceiver":{"name":"DelegateActionSenderDoesNotMatchTxReceiver","subtypes":[],"props":{"receiver_id":"","sender_id":""}},"DeleteAccountStaking":{"name":"DeleteAccountStaking","subtypes":[],"props":{"account_id":""}},"DeleteAccountWithLargeState":{"name":"DeleteAccountWithLargeState","subtypes":[],"props":{"account_id":""}},"DeleteActionMustBeFinal":{"name":"DeleteActionMustBeFinal","subtypes":[],"props":{}},"DeleteKeyDoesNotExist":{"name":"DeleteKeyDoesNotExist","subtypes":[],"props":{"account_id":"","public_key":""}},"DepositWithFunctionCall":{"name":"DepositWithFunctionCall","subtypes":[],"props":{}},"Deprecated":{"name":"Deprecated","subtypes":[],"props":{"method_name":""}},"Deserialization":{"name":"Deserialization","subtypes":[],"props":{}},"ECRecoverError":{"name":"ECRecoverError","subtypes":[],"props":{"msg":""}},"Ed25519VerifyInvalidInput":{"name":"Ed25519VerifyInvalidInput","subtypes":[],"props":{"msg":""}},"EmptyMethodName":{"name":"EmptyMethodName","subtypes":[],"props":{}},"Expired":{"name":"Expired","subtypes":[],"props":{}},"FunctionCallArgumentsLengthExceeded":{"name":"FunctionCallArgumentsLengthExceeded","subtypes":[],"props":{"length":"","limit":""}},"FunctionCallMethodNameLengthExceeded":{"name":"FunctionCallMethodNameLengthExceeded","subtypes":[],"props":{"length":"","limit":""}},"FunctionCallZeroAttachedGas":{"name":"FunctionCallZeroAttachedGas","subtypes":[],"props":{}},"GasExceeded":{"name":"GasExceeded","subtypes":[],"props":{}},"GasInstrumentation":{"name":"GasInstrumentation","subtypes":[],"props":{}},"GasLimitExceeded":{"name":"GasLimitExceeded","subtypes":[],"props":{}},"GenericTrap":{"name":"GenericTrap","subtypes":[],"props":{}},"GuestPanic":{"name":"GuestPanic","subtypes":[],"props":{"panic_msg":""}},"HostError":{"name":"HostError","subtypes":["BadUTF16","BadUTF8","GasExceeded","GasLimitExceeded","BalanceExceeded","EmptyMethodName","GuestPanic","IntegerOverflow","InvalidPromiseIndex","CannotAppendActionToJointPromise","CannotReturnJointPromise","InvalidPromiseResultIndex","InvalidRegisterId","IteratorWasInvalidated","MemoryAccessViolation","InvalidReceiptIndex","InvalidIteratorIndex","InvalidAccountId","InvalidMethodName","InvalidPublicKey","ProhibitedInView","NumberOfLogsExceeded","KeyLengthExceeded","ValueLengthExceeded","TotalLogLengthExceeded","NumberPromisesExceeded","NumberInputDataDependenciesExceeded","ReturnedValueLengthExceeded","ContractSizeExceeded","Deprecated","ECRecoverError","AltBn128InvalidInput","Ed25519VerifyInvalidInput"],"props":{}},"IllegalArithmetic":{"name":"IllegalArithmetic","subtypes":[],"props":{}},"IncorrectCallIndirectSignature":{"name":"IncorrectCallIndirectSignature","subtypes":[],"props":{}},"IndirectCallToNull":{"name":"IndirectCallToNull","subtypes":[],"props":{}},"Instantiate":{"name":"Instantiate","subtypes":[],"props":{}},"InsufficientStake":{"name":"InsufficientStake","subtypes":[],"props":{"account_id":"","minimum_stake":"","stake":""}},"IntegerOverflow":{"name":"IntegerOverflow","subtypes":[],"props":{}},"InternalMemoryDeclared":{"name":"InternalMemoryDeclared","subtypes":[],"props":{}},"InvalidAccessKeyError":{"name":"InvalidAccessKeyError","subtypes":["AccessKeyNotFound","ReceiverMismatch","MethodNameMismatch","RequiresFullAccess","NotEnoughAllowance","DepositWithFunctionCall"],"props":{}},"InvalidAccountId":{"name":"InvalidAccountId","subtypes":[],"props":{}},"InvalidChain":{"name":"InvalidChain","subtypes":[],"props":{}},"InvalidDataReceiverId":{"name":"InvalidDataReceiverId","subtypes":[],"props":{"account_id":""}},"InvalidIteratorIndex":{"name":"InvalidIteratorIndex","subtypes":[],"props":{"iterator_index":""}},"InvalidMethodName":{"name":"InvalidMethodName","subtypes":[],"props":{}},"InvalidNonce":{"name":"InvalidNonce","subtypes":[],"props":{"ak_nonce":"","tx_nonce":""}},"InvalidPredecessorId":{"name":"InvalidPredecessorId","subtypes":[],"props":{"account_id":""}},"InvalidPromiseIndex":{"name":"InvalidPromiseIndex","subtypes":[],"props":{"promise_idx":""}},"InvalidPromiseResultIndex":{"name":"InvalidPromiseResultIndex","subtypes":[],"props":{"result_idx":""}},"InvalidPublicKey":{"name":"InvalidPublicKey","subtypes":[],"props":{}},"InvalidReceiptIndex":{"name":"InvalidReceiptIndex","subtypes":[],"props":{"receipt_index":""}},"InvalidReceiverId":{"name":"InvalidReceiverId","subtypes":[],"props":{"account_id":""}},"InvalidRegisterId":{"name":"InvalidRegisterId","subtypes":[],"props":{"register_id":""}},"InvalidSignature":{"name":"InvalidSignature","subtypes":[],"props":{}},"InvalidSignerId":{"name":"InvalidSignerId","subtypes":[],"props":{"account_id":""}},"InvalidTxError":{"name":"InvalidTxError","subtypes":["InvalidAccessKeyError","InvalidSignerId","SignerDoesNotExist","InvalidNonce","NonceTooLarge","InvalidReceiverId","InvalidSignature","NotEnoughBalance","LackBalanceForState","CostOverflow","InvalidChain","Expired","ActionsValidation","TransactionSizeExceeded"],"props":{}},"IteratorWasInvalidated":{"name":"IteratorWasInvalidated","subtypes":[],"props":{"iterator_index":""}},"KeyLengthExceeded":{"name":"KeyLengthExceeded","subtypes":[],"props":{"length":"","limit":""}},"LackBalanceForState":{"name":"LackBalanceForState","subtypes":[],"props":{"account_id":"","amount":""}},"Memory":{"name":"Memory","subtypes":[],"props":{}},"MemoryAccessViolation":{"name":"MemoryAccessViolation","subtypes":[],"props":{}},"MemoryOutOfBounds":{"name":"MemoryOutOfBounds","subtypes":[],"props":{}},"MethodEmptyName":{"name":"MethodEmptyName","subtypes":[],"props":{}},"MethodInvalidSignature":{"name":"MethodInvalidSignature","subtypes":[],"props":{}},"MethodNameMismatch":{"name":"MethodNameMismatch","subtypes":[],"props":{"method_name":""}},"MethodNotFound":{"name":"MethodNotFound","subtypes":[],"props":{}},"MethodResolveError":{"name":"MethodResolveError","subtypes":["MethodEmptyName","MethodNotFound","MethodInvalidSignature"],"props":{}},"MisalignedAtomicAccess":{"name":"MisalignedAtomicAccess","subtypes":[],"props":{}},"NonceTooLarge":{"name":"NonceTooLarge","subtypes":[],"props":{"tx_nonce":"","upper_bound":""}},"NotEnoughAllowance":{"name":"NotEnoughAllowance","subtypes":[],"props":{"account_id":"","allowance":"","cost":"","public_key":""}},"NotEnoughBalance":{"name":"NotEnoughBalance","subtypes":[],"props":{"balance":"","cost":"","signer_id":""}},"NumberInputDataDependenciesExceeded":{"name":"NumberInputDataDependenciesExceeded","subtypes":[],"props":{"limit":"","number_of_input_data_dependencies":""}},"NumberOfLogsExceeded":{"name":"NumberOfLogsExceeded","subtypes":[],"props":{"limit":""}},"NumberPromisesExceeded":{"name":"NumberPromisesExceeded","subtypes":[],"props":{"limit":"","number_of_promises":""}},"OnlyImplicitAccountCreationAllowed":{"name":"OnlyImplicitAccountCreationAllowed","subtypes":[],"props":{"account_id":""}},"PrepareError":{"name":"PrepareError","subtypes":["Serialization","Deserialization","InternalMemoryDeclared","GasInstrumentation","StackHeightInstrumentation","Instantiate","Memory","TooManyFunctions","TooManyLocals"],"props":{}},"ProhibitedInView":{"name":"ProhibitedInView","subtypes":[],"props":{"method_name":""}},"ReceiptValidationError":{"name":"ReceiptValidationError","subtypes":["InvalidPredecessorId","InvalidReceiverId","InvalidSignerId","InvalidDataReceiverId","ReturnedValueLengthExceeded","NumberInputDataDependenciesExceeded","ActionsValidation"],"props":{}},"ReceiverMismatch":{"name":"ReceiverMismatch","subtypes":[],"props":{"ak_receiver":"","tx_receiver":""}},"RequiresFullAccess":{"name":"RequiresFullAccess","subtypes":[],"props":{}},"ReturnedValueLengthExceeded":{"name":"ReturnedValueLengthExceeded","subtypes":[],"props":{"length":"","limit":""}},"Serialization":{"name":"Serialization","subtypes":[],"props":{}},"SignerDoesNotExist":{"name":"SignerDoesNotExist","subtypes":[],"props":{"signer_id":""}},"StackHeightInstrumentation":{"name":"StackHeightInstrumentation","subtypes":[],"props":{}},"StackOverflow":{"name":"StackOverflow","subtypes":[],"props":{}},"TooManyFunctions":{"name":"TooManyFunctions","subtypes":[],"props":{}},"TooManyLocals":{"name":"TooManyLocals","subtypes":[],"props":{}},"TotalLogLengthExceeded":{"name":"TotalLogLengthExceeded","subtypes":[],"props":{"length":"","limit":""}},"TotalNumberOfActionsExceeded":{"name":"TotalNumberOfActionsExceeded","subtypes":[],"props":{"limit":"","total_number_of_actions":""}},"TotalPrepaidGasExceeded":{"name":"TotalPrepaidGasExceeded","subtypes":[],"props":{"limit":"","total_prepaid_gas":""}},"TransactionSizeExceeded":{"name":"TransactionSizeExceeded","subtypes":[],"props":{"limit":"","size":""}},"TriesToStake":{"name":"TriesToStake","subtypes":[],"props":{"account_id":"","balance":"","locked":"","stake":""}},"TriesToUnstake":{"name":"TriesToUnstake","subtypes":[],"props":{"account_id":""}},"TxExecutionError":{"name":"TxExecutionError","subtypes":["ActionError","InvalidTxError"],"props":{}},"Unreachable":{"name":"Unreachable","subtypes":[],"props":{}},"UnsuitableStakingKey":{"name":"UnsuitableStakingKey","subtypes":[],"props":{"public_key":""}},"UnsupportedProtocolFeature":{"name":"UnsupportedProtocolFeature","subtypes":[],"props":{"protocol_feature":"","version":""}},"ValueLengthExceeded":{"name":"ValueLengthExceeded","subtypes":[],"props":{"length":"","limit":""}},"WasmTrap":{"name":"WasmTrap","subtypes":["Unreachable","IncorrectCallIndirectSignature","MemoryOutOfBounds","CallIndirectOOB","IllegalArithmetic","MisalignedAtomicAccess","IndirectCallToNull","StackOverflow","GenericTrap"],"props":{}},"WasmerCompileError":{"name":"WasmerCompileError","subtypes":[],"props":{"msg":""}},"Closed":{"name":"Closed","subtypes":[],"props":{}},"ServerError":{"name":"ServerError","subtypes":["TxExecutionError","Timeout","Closed"],"props":{}},"Timeout":{"name":"Timeout","subtypes":[],"props":{}}}'),Gr={schema:zr};var Et;function $r(){if(Et)return z;Et=1;var n=z.__importDefault||function(m){return m&&m.__esModule?m:{default:m}};Object.defineProperty(z,"__esModule",{value:!0}),z.getErrorTypeFromErrorMessage=z.formatError=z.parseResultError=z.parseRpcError=z.ServerError=void 0;const r=On(),d=n(Dn()),s=Wt(),i=n(qr),a=n(Gr),c={formatNear:()=>(m,v)=>(0,s.formatNearAmount)(v(m))};class u extends r.TypedError{}z.ServerError=u;class f extends u{}function y(m){const v={},N=_(m,a.default.schema,v,""),M=new u(l(N,v),N);return Object.assign(M,v),M}z.parseRpcError=y;function b(m){const v=y(m.status.Failure),N=new f;return Object.assign(N,v),N.type=v.type,N.message=v.message,N.transaction_outcome=m.transaction_outcome,N}z.parseResultError=b;function l(m,v){return typeof i.default[m]=="string"?d.default.render(i.default[m],Object.assign(Object.assign({},v),c)):JSON.stringify(v)}z.formatError=l;function _(m,v,N,M){let e,t,o;for(const I in v){if(h(m[I]))return m[I];if(g(m[I]))e=m[I],t=v[I],o=I;else if(g(m.kind)&&g(m.kind[I]))e=m.kind[I],t=v[I],o=I;else continue}if(e&&t){for(const I of Object.keys(t.props))N[I]=e[I];return _(e,v,N,o)}else return N.kind=m,M}function p(m,v){switch(!0){case/^account .*? does not exist while viewing$/.test(m):return"AccountDoesNotExist";case/^Account .*? doesn't exist$/.test(m):return"AccountDoesNotExist";case/^access key .*? does not exist while viewing$/.test(m):return"AccessKeyDoesNotExist";case/wasm execution failed with error: FunctionCallError\(CompilationError\(CodeDoesNotExist/.test(m):return"CodeDoesNotExist";case/wasm execution failed with error: CompilationError\(CodeDoesNotExist/.test(m):return"CodeDoesNotExist";case/wasm execution failed with error: FunctionCallError\(MethodResolveError\(MethodNotFound/.test(m):return"MethodNotFound";case/wasm execution failed with error: MethodResolveError\(MethodNotFound/.test(m):return"MethodNotFound";case/Transaction nonce \d+ must be larger than nonce of the used access key \d+/.test(m):return"InvalidNonce";default:return v}}z.getErrorTypeFromErrorMessage=p;function g(m){return Object.prototype.toString.call(m)==="[object Object]"}function h(m){return Object.prototype.toString.call(m)==="[object String]"}return z}var At;function Ht(){return At||(At=1,function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.parseRpcError=n.parseResultError=n.getErrorTypeFromErrorMessage=n.formatError=n.ServerError=n.logWarning=void 0;var r=In();Object.defineProperty(n,"logWarning",{enumerable:!0,get:function(){return r.logWarning}});var d=$r();Object.defineProperty(n,"ServerError",{enumerable:!0,get:function(){return d.ServerError}}),Object.defineProperty(n,"formatError",{enumerable:!0,get:function(){return d.formatError}}),Object.defineProperty(n,"getErrorTypeFromErrorMessage",{enumerable:!0,get:function(){return d.getErrorTypeFromErrorMessage}}),Object.defineProperty(n,"parseResultError",{enumerable:!0,get:function(){return d.parseResultError}}),Object.defineProperty(n,"parseRpcError",{enumerable:!0,get:function(){return d.parseRpcError}})}(Le)),Le}var ce={},Nt;function Vr(){if(Nt)return ce;Nt=1,Object.defineProperty(ce,"__esModule",{value:!0}),ce.printTxOutcomeLogs=ce.printTxOutcomeLogsAndFailures=void 0;const n=Ht(),r=je();function d({contractId:i,outcome:a}){const c=[a.transaction_outcome,...a.receipts_outcome].reduce((u,f)=>{const y=typeof f.outcome.status=="object"&&typeof f.outcome.status.Failure=="object";return f.outcome.logs.length||y?u.concat({receiptIds:f.outcome.receipt_ids,logs:f.outcome.logs,failure:typeof f.outcome.status=="object"&&f.outcome.status.Failure!==void 0?(0,n.parseRpcError)(f.outcome.status.Failure):null}):u},[]);for(const u of c)r.Logger.log(`Receipt${u.receiptIds.length>1?"s":""}: ${u.receiptIds.join(", ")}`),s({contractId:i,logs:u.logs,prefix:" "}),u.failure&&r.Logger.warn(` Failure [${i}]: ${u.failure}`)}ce.printTxOutcomeLogsAndFailures=d;function s({contractId:i,logs:a,prefix:c=""}){for(const u of a)r.Logger.log(`${c}Log [${i}]: ${u}`)}return ce.printTxOutcomeLogs=s,ce}var Ae={},Bt;function Wr(){if(Bt)return Ae;Bt=1,Object.defineProperty(Ae,"__esModule",{value:!0}),Ae.getTransactionLastResult=void 0;function n(r){if(typeof r.status=="object"&&typeof r.status.SuccessValue=="string"){const d=Buffer.from(r.status.SuccessValue,"base64").toString();try{return JSON.parse(d)}catch{return d}}return null}return Ae.getTransactionLastResult=n,Ae}var ne={};/*!
8
+ * depd
9
+ * Copyright(c) 2015 Douglas Christopher Wilson
10
+ * MIT Licensed
11
+ */var Ge,Ot;function Hr(){if(Ot)return Ge;Ot=1,Ge=n;function n(s){if(!s)throw new TypeError("argument namespace is required");function i(a){}return i._file=void 0,i._ignored=!0,i._namespace=s,i._traced=!1,i._warned=Object.create(null),i.function=r,i.property=d,i}function r(s,i){if(typeof s!="function")throw new TypeError("argument fn must be a function");return s}function d(s,i,a){if(!s||typeof s!="object"&&typeof s!="function")throw new TypeError("argument obj must be object");var c=Object.getOwnPropertyDescriptor(s,i);if(!c)throw new TypeError("must call property on owner object");if(!c.configurable)throw new TypeError("property must be configurable")}return Ge}var Tt;function Xr(){if(Tt)return ne;Tt=1;var n=ne.__importDefault||function(u){return u&&u.__esModule?u:{default:u}};Object.defineProperty(ne,"__esModule",{value:!0}),ne.diffEpochValidators=ne.findSeatPrice=void 0;const r=n(fe.default),d=n(Hr());function s(u,f,y,b){return b&&b<49?i(u,f):(y||((0,d.default)("findSeatPrice(validators, maxNumberOfSeats)")("`use `findSeatPrice(validators, maxNumberOfSeats, minimumStakeRatio)` instead"),y=[1,6250]),a(u,f,y))}ne.findSeatPrice=s;function i(u,f){const y=u.map(g=>new r.default(g.stake,10)).sort((g,h)=>g.cmp(h)),b=new r.default(f),l=y.reduce((g,h)=>g.add(h));if(l.lt(b))throw new Error("Stakes are below seats");let _=new r.default(1),p=l.add(new r.default(1));for(;!_.eq(p.sub(new r.default(1)));){const g=_.add(p).div(new r.default(2));let h=!1,m=new r.default(0);for(let v=0;v<y.length;++v)if(m=m.add(y[v].div(g)),m.gte(b)){_=g,h=!0;break}h||(p=g)}return _}function a(u,f,y){if(y.length!=2)throw Error("minimumStakeRatio should have 2 elements");const b=u.map(_=>new r.default(_.stake,10)).sort((_,p)=>_.cmp(p)),l=b.reduce((_,p)=>_.add(p));return u.length<f?l.mul(new r.default(y[0])).div(new r.default(y[1])):b[0].add(new r.default(1))}function c(u,f){const y=new Map;u.forEach(l=>y.set(l.account_id,l));const b=new Set(f.map(l=>l.account_id));return{newValidators:f.filter(l=>!y.has(l.account_id)),removedValidators:u.filter(l=>!b.has(l.account_id)),changedValidators:f.filter(l=>y.has(l.account_id)&&y.get(l.account_id).stake!=l.stake).map(l=>({current:y.get(l.account_id),next:l}))}}return ne.diffEpochValidators=c,ne}var Dt;function jr(){return Dt||(Dt=1,function(n){var r=_e.__createBinding||(Object.create?function(s,i,a,c){c===void 0&&(c=a);var u=Object.getOwnPropertyDescriptor(i,a);(!u||("get"in u?!i.__esModule:u.writable||u.configurable))&&(u={enumerable:!0,get:function(){return i[a]}}),Object.defineProperty(s,c,u)}:function(s,i,a,c){c===void 0&&(c=a),s[c]=i[a]}),d=_e.__exportStar||function(s,i){for(var a in s)a!=="default"&&!Object.prototype.hasOwnProperty.call(i,a)&&r(i,s,a)};Object.defineProperty(n,"__esModule",{value:!0}),d(_n(),n),d(Ht(),n),d(Wt(),n),d(Vr(),n),d(Wr(),n),d(Xr(),n),d(je(),n)}(_e)),_e}var kt;function Zr(){return kt||(kt=1,function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.base_decode=n.base_encode=n.deserialize=n.serialize=void 0;var r=bn();Object.defineProperty(n,"serialize",{enumerable:!0,get:function(){return r.serialize}}),Object.defineProperty(n,"deserialize",{enumerable:!0,get:function(){return r.deserialize}});var d=jr();Object.defineProperty(n,"base_encode",{enumerable:!0,get:function(){return d.baseEncode}}),Object.defineProperty(n,"base_decode",{enumerable:!0,get:function(){return d.baseDecode}})}(Ue)),Ue}var Yr=Zr();class Qr{}let Xt=class extends Qr{};const Pe=new fe.default("300000000000000"),Ze="dontcare",Ce=async({networkId:n,accountId:r=Ze,keypair:d=zt.KeyPair.fromRandom("ed25519")})=>{const s=new fn.InMemoryKeyStore;await s.setKey(n,r,d);const i=We.Connection.fromConfig({networkId:n,provider:{type:"JsonRpcProvider",args:{url:{testnet:"https://rpc.testnet.near.org",mainnet:"https://rpc.mainnet.near.org"}[n]}},signer:{type:"InMemorySigner",keyStore:s}});return new We.Account(i,r)};function ei(n){return{delegate_action:{actions:n.delegateAction.actions.map(r=>{if(r.functionCall)return{FunctionCall:{method_name:r.functionCall.methodName,args:Buffer.from(r.functionCall.args).toString("base64"),gas:Number(r.functionCall.gas),deposit:r.functionCall.deposit.toString()}}}).flatMap(r=>r?[r]:[]),nonce:Number(n.delegateAction.nonce),max_block_height:Number(n.delegateAction.maxBlockHeight),public_key:n.delegateAction.publicKey.toString(),receiver_id:n.delegateAction.receiverId,sender_id:n.delegateAction.senderId},signature:`ed25519:${Gt.default.encode(n.signature.data)}`}}const xt=n=>`04${Buffer.from(Yr.base_decode(n.split(":")[1])).toString("hex")}`,ti=n=>{if(n===Ze)throw new Error("A valid account ID and keypair are required for change methods. Please instantiate a new contract with valid credentials.")};class pe extends Xt{constructor({networkId:r,contractId:d,accountId:s=Ze,keypair:i=zt.KeyPair.fromRandom("ed25519")}){super(),this.networkId=r,this.contractId=d,this.accountId=s,this.keypair=i}async getContract(){const r=await Ce({networkId:this.networkId,accountId:this.accountId,keypair:this.keypair});return new We.Contract(r,this.contractId,{viewMethods:["public_key","experimental_signature_deposit","derived_public_key"],changeMethods:["sign"],useLocalViewExecution:!1})}async getCurrentSignatureDeposit(){const r=await this.getContract();return new fe.default((await r.experimental_signature_deposit()).toLocaleString("fullwide",{useGrouping:!1}))}async getDerivedPublicKey(r){const s=await(await this.getContract()).derived_public_key(r);return xt(s)}async getPublicKey(){const d=await(await this.getContract()).public_key();return xt(d)}async sign(r){ti(this.accountId);const d=await this.getContract(),s=await this.getCurrentSignatureDeposit(),i=await d.sign({args:{request:r},gas:Pe,amount:s});return Ye(i)}static async signWithRelayer({account:r,contract:d,signArgs:s,deposit:i,relayerUrl:a}){const c=un.actionCreators.functionCall("sign",{request:s},BigInt(Pe.toString()),BigInt(i.toString())),u=await r.signedDelegate({receiverId:d,actions:[c],blockHeightTtl:60});delete r.accessKeyByPublicKeyCache[u.delegateAction.publicKey.toString()];const y=await(await fetch(`${a}/send_meta_tx_async`,{method:"POST",mode:"cors",body:JSON.stringify(ei(u)),headers:new Headers({"Content-Type":"application/json"})})).text(),b=await r.connection.provider.txStatus(y,r.accountId,"FINAL"),l=jt({response:b});if(!l)throw new Error("Signature error, please retry");return l}}const ni=async({networkId:n,contractId:r,mpcPayloads:d,path:s})=>{const a=await new pe({networkId:n,contractId:r}).getCurrentSignatureDeposit();return{receiverId:r,actions:d.map(c=>({type:"FunctionCall",params:{methodName:"sign",args:{request:{payload:Array.from(c),path:s,key_version:0}},gas:Pe.div(new fe.default(d.length)).toString(),deposit:a?.toString()||"1"}}))}},ri=async({networkId:n,chainSigContract:r,nftKeysContract:d,mpcPayloads:s,path:i,tokenId:a})=>{const u=await new pe({networkId:n,contractId:r}).getCurrentSignatureDeposit();return{receiverId:d,actions:s.map(f=>({type:"FunctionCall",params:{methodName:"ckt_sign_hash",args:{token_id:a,path:i,payload:Array.from(f)},gas:Pe.div(new fe.default(s.length)).toString(),deposit:u?.toString()||"1"}}))}},jt=({response:n})=>{const r=n.receipts_outcome.reduce((d,s)=>{if(d)return d;const{status:i}=s.outcome;return typeof i=="object"&&i.SuccessValue&&i.SuccessValue!==""&&Buffer.from(i.SuccessValue,"base64").toString("utf-8")||""},"");if(r){const d=JSON.parse(r);return Ye(d.Ok)}else return},ii=Object.freeze({__proto__:null,mpcPayloadsToChainSigTransaction:ni,mpcPayloadsToNFTKeysTransaction:ri,responseToMpcSignature:jt});class Me{}async function Zt(n,r){const d=new W.ethers.JsonRpcProvider(n),s=await d.estimateGas(r),i=await d.getFeeData(),a=i.maxFeePerGas??W.ethers.parseUnits("10","gwei"),c=i.maxPriorityFeePerGas??W.ethers.parseUnits("10","gwei");return{gasLimit:s,maxFeePerGas:a,maxPriorityFeePerGas:c,maxFee:a*s}}class Yt extends Me{constructor({rpcUrl:r,contract:d}){super(),this.contract=d,this.provider=new W.ethers.JsonRpcProvider(r)}async attachGasAndNonce(r){const d=await Zt(this.provider._getConnection().url,r),s=await this.provider.getTransactionCount(r.from,"latest"),{from:i,...a}=r;return{...d,chainId:this.provider._network.chainId,nonce:s,type:2,...a}}parseSignature(r){return W.ethers.Signature.from({r:`0x${r.r}`,s:`0x${r.s}`,v:r.v})}async deriveAddressAndPublicKey(r,d){const s=await this.contract.getDerivedPublicKey({path:d,predecessor:r});if(!s)throw new Error("Failed to get derived public key");const i=s.startsWith("04")?s.substring(2):s,a=W.ethers.keccak256(re.fromHex(i));return{address:`0x${a.substring(a.length-40)}`,publicKey:s}}async getBalance(r){try{const d=await this.provider.getBalance(r);return W.ethers.formatEther(d)}catch(d){throw console.error(`Failed to fetch balance for address ${r}:`,d),new Error("Failed to fetch balance.")}}setTransaction(r,d){const s=JSON.stringify(r,(i,a)=>typeof a=="bigint"?a.toString():a);window.localStorage.setItem(d,s)}getTransaction(r,d){const s=window.localStorage.getItem(r);return d?.remove&&window.localStorage.removeItem(r),s?JSON.parse(s):void 0}async getMPCPayloadAndTransaction(r){const d=await this.attachGasAndNonce(r),s=W.ethers.Transaction.from(d).unsignedSerialized,i=W.keccak256(s),a=Array.from(W.ethers.getBytes(i));return{transaction:d,mpcPayloads:[a]}}addSignature({transaction:r,mpcSignatures:d}){return W.ethers.Transaction.from({...r,signature:this.parseSignature(d[0])}).serialized}async broadcastTx(r){try{return(await this.provider.broadcastTransaction(r)).hash}catch(d){throw console.error("Transaction broadcast failed:",d),new Error("Failed to broadcast transaction.")}}}function Pt(n){switch(n.toLowerCase()){case"mainnet":return ie.networks.bitcoin;case"testnet":return ie.networks.testnet;case"regtest":return ie.networks.regtest;default:throw new Error(`Unknown Bitcoin network: ${n}`)}}class de extends Me{static{this.SATOSHIS_PER_BTC=1e8}constructor({network:r,contract:d,btcRpcAdapter:s}){super(),this.network=r,this.btcRpcAdapter=s,this.contract=d}static toBTC(r){return r/de.SATOSHIS_PER_BTC}static toSatoshi(r){return Math.round(r*de.SATOSHIS_PER_BTC)}async fetchTransaction(r){const d=await this.btcRpcAdapter.getTransaction(r),s=new ie.Transaction;return d.vout.forEach(i=>{const a=Buffer.from(i.scriptpubkey,"hex");s.addOutput(a,Number(i.value))}),s}static parseRSVSignature(r){const d=r.r.padStart(64,"0"),s=r.s.padStart(64,"0"),i=Buffer.from(d+s,"hex");if(i.length!==64)throw new Error("Invalid signature length.");return i}async createPSBT({transactionRequest:r}){const{inputs:d,outputs:s}=r.inputs&&r.outputs?r:await this.btcRpcAdapter.selectUTXOs(r.from,[{address:r.to,value:parseFloat(r.value)}]),i=new ie.Psbt({network:Pt(this.network)});return await Promise.all(d.map(async a=>{if(!a.scriptPubKey){const u=(await this.fetchTransaction(a.txid)).outs[a.vout];a.scriptPubKey=u.script}i.addInput({hash:a.txid,index:a.vout,witnessUtxo:{script:a.scriptPubKey,value:a.value}})})),s.forEach(a=>{a.address?i.addOutput({address:a.address,value:a.value}):a.script&&i.addOutput({script:a.script,value:a.value})}),i}async getBalance(r){const d=await this.btcRpcAdapter.getBalance(r);return de.toBTC(d).toString()}async deriveAddressAndPublicKey(r,d){const s=await this.contract.getDerivedPublicKey({path:d,predecessor:r});if(!s)throw new Error("Failed to get derived public key");const i=Qe(s),a=Buffer.from(i,"hex"),c=Pt(this.network),u=ie.payments.p2wpkh({pubkey:a,network:c}),{address:f}=u;if(!f)throw new Error("Failed to generate Bitcoin address");return{address:f,publicKey:i}}setTransaction(r,d){window.localStorage.setItem(d,JSON.stringify({psbt:r.psbt.toHex(),publicKey:r.publicKey}))}getTransaction(r,d){const s=window.localStorage.getItem(r);if(!s)return;d?.remove&&window.localStorage.removeItem(r);const i=JSON.parse(s);return{psbt:ie.Psbt.fromHex(i.psbt),publicKey:i.publicKey}}async getMPCPayloadAndTransaction(r){const d=Buffer.from(r.publicKey,"hex"),s=await this.createPSBT({transactionRequest:r}),i=s.toHex(),a=[],c=u=>({publicKey:d,sign:f=>(a[u]=Array.from(f),Buffer.alloc(64))});for(let u=0;u<s.inputCount;u++)s.signInput(u,c(u));return{transaction:{psbt:ie.Psbt.fromHex(i),publicKey:r.publicKey},mpcPayloads:a}}addSignature({transaction:{psbt:r,publicKey:d},mpcSignatures:s}){const i=Buffer.from(d,"hex"),a=c=>({publicKey:i,sign:()=>{const u=s[c];return de.parseRSVSignature(u)}});for(let c=0;c<r.inputCount;c++)r.signInput(c,a(c));return r.finalizeAllInputs(),r.extractTransaction().toHex()}async broadcastTx(r){return await this.btcRpcAdapter.broadcastTransaction(r)}}class Qt{}class oi extends Qt{constructor(r){super(),this.providerUrl=r}async fetchFeeRate(r=6){const s=await(await fetch(`${this.providerUrl}/v1/fees/recommended`)).json();return r<=1?s.fastestFee:r<=3?s.halfHourFee:r<=6?s.hourFee:s.economyFee}async fetchUTXOs(r){try{return await(await fetch(`${this.providerUrl}/address/${r}/utxo`)).json()}catch(d){return console.error("Failed to fetch UTXOs:",d),[]}}async selectUTXOs(r,d,s=6){const i=await this.fetchUTXOs(r),a=await this.fetchFeeRate(s),c=hn.default(i,d,Math.ceil(a+1));if(!c.inputs||!c.outputs)throw new Error("Invalid transaction: coinselect failed to find a suitable set of inputs and outputs. This could be due to insufficient funds, or no inputs being available that meet the criteria.");return{inputs:c.inputs,outputs:c.outputs}}async broadcastTransaction(r){const d=await fetch(`${this.providerUrl}/tx`,{method:"POST",body:r});if(d.ok)return await d.text();throw new Error(`Failed to broadcast transaction: ${await d.text()}`)}async getBalance(r){const s=await(await fetch(`${this.providerUrl}/address/${r}`)).json();return s.chain_stats.funded_txo_sum-s.chain_stats.spent_txo_sum}async getTransaction(r){return await(await fetch(`${this.providerUrl}/tx/${r}`)).json()}}const en={Mempool:oi};var $e={},j={},Z={},Y={},Ct;function ai(){if(Ct)return Y;Ct=1,Object.defineProperty(Y,"__esModule",{value:!0}),Y.utf8Write=Y.utf8Read=Y.utf8Length=void 0;function n(s){let i=0,a=0;for(let c=0;c<s.length;++c)a=s.charCodeAt(c),a<128?i+=1:a<2048?i+=2:(a&64512)===55296&&(s.charCodeAt(c+1)&64512)===56320?(++c,i+=4):i+=3;return i}Y.utf8Length=n;function r(s,i,a){if(a-i<1)return"";const u=[];let f=[],y=0,b;for(;i<a;)b=s[i++],b<128?u[y++]=b:b>191&&b<224?u[y++]=(b&31)<<6|s[i++]&63:b>239&&b<365?(b=((b&7)<<18|(s[i++]&63)<<12|(s[i++]&63)<<6|s[i++]&63)-65536,u[y++]=55296+(b>>10),u[y++]=56320+(b&1023)):u[y++]=(b&15)<<12|(s[i++]&63)<<6|s[i++]&63,y>8191&&(f.push(String.fromCharCode(...u)),y=0);return y&&f.push(String.fromCharCode(...u.slice(0,y))),f.join("")}Y.utf8Read=r;function d(s,i,a){const c=a;let u,f;for(let y=0;y<s.length;++y)u=s.charCodeAt(y),u<128?i[a++]=u:u<2048?(i[a++]=u>>6|192,i[a++]=u&63|128):(u&64512)===55296&&((f=s.charCodeAt(y+1))&64512)===56320?(u=65536+((u&1023)<<10)+(f&1023),++y,i[a++]=u>>18|240,i[a++]=u>>12&63|128,i[a++]=u>>6&63|128,i[a++]=u&63|128):(i[a++]=u>>12|224,i[a++]=u>>6&63|128,i[a++]=u&63|128);return a-c}return Y.utf8Write=d,Y}var P={},Mt;function si(){if(Mt)return P;Mt=1,Object.defineProperty(P,"__esModule",{value:!0}),P.writeByte=P.writeFixed32=P.int64Length=P.writeVarint64=P.writeVarint32=P.readInt32=P.readUInt32=P.zzDecode=P.zzEncode=P.varint32read=P.varint32write=P.uInt64ToString=P.int64ToString=P.int64FromString=P.varint64write=P.varint64read=void 0;function n(){let t=0,o=0;for(let S=0;S<28;S+=7){let E=this.buf[this.pos++];if(t|=(E&127)<<S,!(E&128))return this.assertBounds(),[t,o]}let I=this.buf[this.pos++];if(t|=(I&15)<<28,o=(I&112)>>4,!(I&128))return this.assertBounds(),[t,o];for(let S=3;S<=31;S+=7){let E=this.buf[this.pos++];if(o|=(E&127)<<S,!(E&128))return this.assertBounds(),[t,o]}throw new Error("invalid varint")}P.varint64read=n;function r(t,o,I){for(let C=0;C<28;C=C+7){const F=t>>>C,A=!(!(F>>>7)&&o==0),w=(A?F|128:F)&255;if(I.push(w),!A)return}const S=t>>>28&15|(o&7)<<4,E=!!(o>>3);if(I.push((E?S|128:S)&255),!!E){for(let C=3;C<31;C=C+7){const F=o>>>C,A=!!(F>>>7),w=(A?F|128:F)&255;if(I.push(w),!A)return}I.push(o>>>31&1)}}P.varint64write=r;const d=4294967296;function s(t){const o=t[0]==="-";o&&(t=t.slice(1));const I=1e6;let S=0,E=0;function C(F,A){const w=Number(t.slice(F,A));E*=I,S=S*I+w,S>=d&&(E=E+(S/d|0),S=S%d)}return C(-24,-18),C(-18,-12),C(-12,-6),C(-6),o?f(S,E):u(S,E)}P.int64FromString=s;function i(t,o){let I=u(t,o);const S=I.hi&2147483648;S&&(I=f(I.lo,I.hi));const E=a(I.lo,I.hi);return S?"-"+E:E}P.int64ToString=i;function a(t,o){if({lo:t,hi:o}=c(t,o),o<=2097151)return String(d*o+t);const I=t&16777215,S=(t>>>24|o<<8)&16777215,E=o>>16&65535;let C=I+S*6777216+E*6710656,F=S+E*8147497,A=E*2;const w=1e7;return C>=w&&(F+=Math.floor(C/w),C%=w),F>=w&&(A+=Math.floor(F/w),F%=w),A.toString()+y(F)+y(C)}P.uInt64ToString=a;function c(t,o){return{lo:t>>>0,hi:o>>>0}}function u(t,o){return{lo:t|0,hi:o|0}}function f(t,o){return o=~o,t?t=~t+1:o+=1,u(t,o)}const y=t=>{const o=String(t);return"0000000".slice(o.length)+o};function b(t,o){if(t>=0){for(;t>127;)o.push(t&127|128),t=t>>>7;o.push(t)}else{for(let I=0;I<9;I++)o.push(t&127|128),t=t>>7;o.push(1)}}P.varint32write=b;function l(){let t=this.buf[this.pos++],o=t&127;if(!(t&128))return this.assertBounds(),o;if(t=this.buf[this.pos++],o|=(t&127)<<7,!(t&128))return this.assertBounds(),o;if(t=this.buf[this.pos++],o|=(t&127)<<14,!(t&128))return this.assertBounds(),o;if(t=this.buf[this.pos++],o|=(t&127)<<21,!(t&128))return this.assertBounds(),o;t=this.buf[this.pos++],o|=(t&15)<<28;for(let I=5;t&128&&I<10;I++)t=this.buf[this.pos++];if(t&128)throw new Error("invalid varint");return this.assertBounds(),o>>>0}P.varint32read=l;function _(t,o){let I=o>>31;return o=((o<<1|t>>>31)^I)>>>0,t=(t<<1^I)>>>0,[t,o]}P.zzEncode=_;function p(t,o){let I=-(t&1);return t=((t>>>1|o<<31)^I)>>>0,o=(o>>>1^I)>>>0,[t,o]}P.zzDecode=p;function g(t,o){return(t[o]|t[o+1]<<8|t[o+2]<<16)+t[o+3]*16777216}P.readUInt32=g;function h(t,o){return(t[o]|t[o+1]<<8|t[o+2]<<16)+(t[o+3]<<24)}P.readInt32=h;function m(t,o,I){for(;t>127;)o[I++]=t&127|128,t>>>=7;o[I]=t}P.writeVarint32=m;function v(t,o,I){for(;t.hi;)o[I++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)o[I++]=t.lo&127|128,t.lo=t.lo>>>7;o[I++]=t.lo}P.writeVarint64=v;function N(t,o){let I=t,S=(t>>>28|o<<4)>>>0,E=o>>>24;return E===0?S===0?I<16384?I<128?1:2:I<2097152?3:4:S<16384?S<128?5:6:S<2097152?7:8:E<128?9:10}P.int64Length=N;function M(t,o,I){o[I]=t&255,o[I+1]=t>>>8&255,o[I+2]=t>>>16&255,o[I+3]=t>>>24}P.writeFixed32=M;function e(t,o,I){o[I]=t&255}return P.writeByte=e,P}var Rt;function Ne(){if(Rt)return Z;Rt=1,Object.defineProperty(Z,"__esModule",{value:!0}),Z.BinaryWriter=Z.BinaryReader=Z.WireType=void 0;const n=ai(),r=si();var d;(function(b){b[b.Varint=0]="Varint",b[b.Fixed64=1]="Fixed64",b[b.Bytes=2]="Bytes",b[b.Fixed32=5]="Fixed32"})(d||(Z.WireType=d={}));class s{assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}constructor(l){this.buf=l?new Uint8Array(l):new Uint8Array(0),this.pos=0,this.type=0,this.len=this.buf.length}tag(){const l=this.uint32(),_=l>>>3,p=l&7;if(_<=0||p<0||p>5)throw new Error("illegal tag: field no "+_+" wire type "+p);return[_,p,l]}skip(l){if(typeof l=="number"){if(this.pos+l>this.len)throw y(this,l);this.pos+=l}else do if(this.pos>=this.len)throw y(this);while(this.buf[this.pos++]&128);return this}skipType(l){switch(l){case d.Varint:this.skip();break;case d.Fixed64:this.skip(8);break;case d.Bytes:this.skip(this.uint32());break;case 3:for(;(l=this.uint32()&7)!==4;)this.skipType(l);break;case d.Fixed32:this.skip(4);break;default:throw Error("invalid wire type "+l+" at offset "+this.pos)}return this}uint32(){return r.varint32read.bind(this)()}int32(){return this.uint32()|0}sint32(){const l=this.uint32();return l%2===1?(l+1)/-2:l/2}fixed32(){const l=(0,r.readUInt32)(this.buf,this.pos);return this.pos+=4,l}sfixed32(){const l=(0,r.readInt32)(this.buf,this.pos);return this.pos+=4,l}int64(){const[l,_]=r.varint64read.bind(this)();return BigInt((0,r.int64ToString)(l,_))}uint64(){const[l,_]=r.varint64read.bind(this)();return BigInt((0,r.uInt64ToString)(l,_))}sint64(){let[l,_]=r.varint64read.bind(this)();return[l,_]=(0,r.zzDecode)(l,_),BigInt((0,r.int64ToString)(l,_))}fixed64(){const l=this.sfixed32(),_=this.sfixed32();return BigInt((0,r.uInt64ToString)(l,_))}sfixed64(){const l=this.sfixed32(),_=this.sfixed32();return BigInt((0,r.int64ToString)(l,_))}float(){throw new Error("float not supported")}double(){throw new Error("double not supported")}bool(){const[l,_]=r.varint64read.bind(this)();return l!==0||_!==0}bytes(){const l=this.uint32(),_=this.pos;return this.pos+=l,this.assertBounds(),this.buf.subarray(_,_+l)}string(){const l=this.bytes();return(0,n.utf8Read)(l,0,l.length)}}Z.BinaryReader=s;class i{constructor(l,_,p){this.fn=l,this.len=_,this.val=p}proceed(l,_){this.fn&&this.fn(this.val,l,_)}}class a{constructor(l){this.head=l.head,this.tail=l.tail,this.len=l.len,this.next=l.states}}class c{constructor(){this.len=0,this.uint64=c.prototype.int64,this.sfixed64=c.prototype.fixed64,this.sfixed32=c.prototype.fixed32,this.head=new i(null,0,0),this.tail=this.head,this.states=null}static create(){return new c}static alloc(l){return typeof Uint8Array<"u"?f(_=>new Uint8Array(_),Uint8Array.prototype.subarray)(l):new Array(l)}_push(l,_,p){return this.tail=this.tail.next=new i(l,_,p),this.len+=_,this}finish(){let l=this.head.next,_=0;const p=c.alloc(this.len);for(;l;)l.proceed(p,_),_+=l.len,l=l.next;return p}fork(){return this.states=new a(this),this.head=this.tail=new i(null,0,0),this.len=0,this}reset(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new i(null,0,0),this.len=0),this}ldelim(){const l=this.head,_=this.tail,p=this.len;return this.reset().uint32(p),p&&(this.tail.next=l.next,this.tail=_,this.len+=p),this}tag(l,_){return this.uint32((l<<3|_)>>>0)}uint32(l){return this.len+=(this.tail=this.tail.next=new i(r.writeVarint32,(l=l>>>0)<128?1:l<16384?2:l<2097152?3:l<268435456?4:5,l)).len,this}int32(l){return l<0?this._push(r.writeVarint64,10,(0,r.int64FromString)(l.toString())):this.uint32(l)}sint32(l){return this.uint32((l<<1^l>>31)>>>0)}int64(l){const{lo:_,hi:p}=(0,r.int64FromString)(l.toString());return this._push(r.writeVarint64,(0,r.int64Length)(_,p),{lo:_,hi:p})}sint64(l){let{lo:_,hi:p}=(0,r.int64FromString)(l.toString());return[_,p]=(0,r.zzEncode)(_,p),this._push(r.writeVarint64,(0,r.int64Length)(_,p),{lo:_,hi:p})}fixed64(l){const{lo:_,hi:p}=(0,r.int64FromString)(l.toString());return this._push(r.writeFixed32,4,_)._push(r.writeFixed32,4,p)}bool(l){return this._push(r.writeByte,1,l?1:0)}fixed32(l){return this._push(r.writeFixed32,4,l>>>0)}float(l){throw new Error("float not supported"+l)}double(l){throw new Error("double not supported"+l)}bytes(l){const _=l.length>>>0;return _?this.uint32(_)._push(u,_,l):this._push(r.writeByte,1,0)}string(l){const _=(0,n.utf8Length)(l);return _?this.uint32(_)._push(n.utf8Write,_,l):this._push(r.writeByte,1,0)}}Z.BinaryWriter=c;function u(b,l,_){if(typeof Uint8Array<"u")l.set(b,_);else for(let p=0;p<b.length;++p)l[_+p]=b[p]}function f(b,l,_){let h=null,m=8192;return function(N){if(N<1||N>4096)return b(N);m+N>8192&&(h=b(8192),m=0);const M=l.call(h,m,m+=N);return m&7&&(m=(m|7)+1),M}}function y(b,l){return RangeError("index out of range: "+b.pos+" + "+(l||1)+" > "+b.len)}return Z}var R={},Ft;function Be(){if(Ft)return R;Ft=1,Object.defineProperty(R,"__esModule",{value:!0}),R.fromJsonTimestamp=R.fromTimestamp=R.toTimestamp=R.setPaginationParams=R.isObject=R.isSet=R.fromDuration=R.toDuration=R.omitDefault=R.base64FromBytes=R.bytesFromBase64=void 0;var n=(()=>{if(typeof n<"u")return n;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof it<"u")return it;throw"Unable to locate global object"})();const r=n.atob||(m=>n.Buffer.from(m,"base64").toString("binary"));function d(m){const v=r(m),N=new Uint8Array(v.length);for(let M=0;M<v.length;++M)N[M]=v.charCodeAt(M);return N}R.bytesFromBase64=d;const s=n.btoa||(m=>n.Buffer.from(m,"binary").toString("base64"));function i(m){const v=[];return m.forEach(N=>{v.push(String.fromCharCode(N))}),s(v.join(""))}R.base64FromBytes=i;function a(m){if(typeof m=="string")return m===""?void 0:m;if(typeof m=="number")return m===0?void 0:m;if(typeof m=="bigint")return m===BigInt(0)?void 0:m;throw new Error(`Got unsupported type ${typeof m}`)}R.omitDefault=a;function c(m){return{seconds:BigInt(Math.floor(parseInt(m)/1e9)),nanos:parseInt(m)%1e9}}R.toDuration=c;function u(m){return(parseInt(m.seconds.toString())*1e9+m.nanos).toString()}R.fromDuration=u;function f(m){return m!=null}R.isSet=f;function y(m){return typeof m=="object"&&m!==null}R.isObject=y;const b=(m,v)=>(v&&(typeof v?.countTotal<"u"&&(m.params["pagination.count_total"]=v.countTotal),typeof v?.key<"u"&&(m.params["pagination.key"]=Buffer.from(v.key).toString("base64")),typeof v?.limit<"u"&&(m.params["pagination.limit"]=v.limit.toString()),typeof v?.offset<"u"&&(m.params["pagination.offset"]=v.offset.toString()),typeof v?.reverse<"u"&&(m.params["pagination.reverse"]=v.reverse)),m);R.setPaginationParams=b;function l(m){const v=h(m.getTime()/1e3),N=m.getTime()%1e3*1e6;return{seconds:v,nanos:N}}R.toTimestamp=l;function _(m){let v=Number(m.seconds)*1e3;return v+=m.nanos/1e6,new Date(v)}R.fromTimestamp=_;const p=m=>({seconds:f(m.seconds)?BigInt(m.seconds.toString()):BigInt(0),nanos:f(m.nanos)?Number(m.nanos):0});function g(m){return m instanceof Date?l(m):typeof m=="string"?l(new Date(m)):p(m)}R.fromJsonTimestamp=g;function h(m){return BigInt(Math.trunc(m))}return R}var Ut;function tn(){if(Ut)return j;Ut=1,Object.defineProperty(j,"__esModule",{value:!0}),j.CompactBitArray=j.MultiSignature=j.protobufPackage=void 0;const n=Ne(),r=Be();j.protobufPackage="cosmos.crypto.multisig.v1beta1";function d(){return{signatures:[]}}j.MultiSignature={typeUrl:"/cosmos.crypto.multisig.v1beta1.MultiSignature",encode(i,a=n.BinaryWriter.create()){for(const c of i.signatures)a.uint32(10).bytes(c);return a},decode(i,a){const c=i instanceof n.BinaryReader?i:new n.BinaryReader(i);let u=a===void 0?c.len:c.pos+a;const f=d();for(;c.pos<u;){const y=c.uint32();switch(y>>>3){case 1:f.signatures.push(c.bytes());break;default:c.skipType(y&7);break}}return f},fromJSON(i){const a=d();return Array.isArray(i?.signatures)&&(a.signatures=i.signatures.map(c=>(0,r.bytesFromBase64)(c))),a},toJSON(i){const a={};return i.signatures?a.signatures=i.signatures.map(c=>(0,r.base64FromBytes)(c!==void 0?c:new Uint8Array)):a.signatures=[],a},fromPartial(i){const a=d();return a.signatures=i.signatures?.map(c=>c)||[],a}};function s(){return{extraBitsStored:0,elems:new Uint8Array}}return j.CompactBitArray={typeUrl:"/cosmos.crypto.multisig.v1beta1.CompactBitArray",encode(i,a=n.BinaryWriter.create()){return i.extraBitsStored!==0&&a.uint32(8).uint32(i.extraBitsStored),i.elems.length!==0&&a.uint32(18).bytes(i.elems),a},decode(i,a){const c=i instanceof n.BinaryReader?i:new n.BinaryReader(i);let u=a===void 0?c.len:c.pos+a;const f=s();for(;c.pos<u;){const y=c.uint32();switch(y>>>3){case 1:f.extraBitsStored=c.uint32();break;case 2:f.elems=c.bytes();break;default:c.skipType(y&7);break}}return f},fromJSON(i){const a=s();return(0,r.isSet)(i.extraBitsStored)&&(a.extraBitsStored=Number(i.extraBitsStored)),(0,r.isSet)(i.elems)&&(a.elems=(0,r.bytesFromBase64)(i.elems)),a},toJSON(i){const a={};return i.extraBitsStored!==void 0&&(a.extraBitsStored=Math.round(i.extraBitsStored)),i.elems!==void 0&&(a.elems=(0,r.base64FromBytes)(i.elems!==void 0?i.elems:new Uint8Array)),a},fromPartial(i){const a=s();return a.extraBitsStored=i.extraBitsStored??0,a.elems=i.elems??new Uint8Array,a}},j}var ue={},Lt;function nn(){if(Lt)return ue;Lt=1,Object.defineProperty(ue,"__esModule",{value:!0}),ue.Any=ue.protobufPackage=void 0;const n=Ne(),r=Be();ue.protobufPackage="google.protobuf";function d(){return{typeUrl:"",value:new Uint8Array}}return ue.Any={typeUrl:"/google.protobuf.Any",encode(s,i=n.BinaryWriter.create()){return s.typeUrl!==""&&i.uint32(10).string(s.typeUrl),s.value.length!==0&&i.uint32(18).bytes(s.value),i},decode(s,i){const a=s instanceof n.BinaryReader?s:new n.BinaryReader(s);let c=i===void 0?a.len:a.pos+i;const u=d();for(;a.pos<c;){const f=a.uint32();switch(f>>>3){case 1:u.typeUrl=a.string();break;case 2:u.value=a.bytes();break;default:a.skipType(f&7);break}}return u},fromJSON(s){const i=d();return(0,r.isSet)(s.typeUrl)&&(i.typeUrl=String(s.typeUrl)),(0,r.isSet)(s.value)&&(i.value=(0,r.bytesFromBase64)(s.value)),i},toJSON(s){const i={};return s.typeUrl!==void 0&&(i.typeUrl=s.typeUrl),s.value!==void 0&&(i.value=(0,r.base64FromBytes)(s.value!==void 0?s.value:new Uint8Array)),i},fromPartial(s){const i=d();return i.typeUrl=s.typeUrl??"",i.value=s.value??new Uint8Array,i}},ue}var Jt;function rn(){return Jt||(Jt=1,function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.SignatureDescriptor_Data_Multi=n.SignatureDescriptor_Data_Single=n.SignatureDescriptor_Data=n.SignatureDescriptor=n.SignatureDescriptors=n.signModeToJSON=n.signModeFromJSON=n.SignMode=n.protobufPackage=void 0;const r=tn(),d=nn(),s=Ne(),i=Be();n.protobufPackage="cosmos.tx.signing.v1beta1";var a;(function(p){p[p.SIGN_MODE_UNSPECIFIED=0]="SIGN_MODE_UNSPECIFIED",p[p.SIGN_MODE_DIRECT=1]="SIGN_MODE_DIRECT",p[p.SIGN_MODE_TEXTUAL=2]="SIGN_MODE_TEXTUAL",p[p.SIGN_MODE_DIRECT_AUX=3]="SIGN_MODE_DIRECT_AUX",p[p.SIGN_MODE_LEGACY_AMINO_JSON=127]="SIGN_MODE_LEGACY_AMINO_JSON",p[p.SIGN_MODE_EIP_191=191]="SIGN_MODE_EIP_191",p[p.UNRECOGNIZED=-1]="UNRECOGNIZED"})(a||(n.SignMode=a={}));function c(p){switch(p){case 0:case"SIGN_MODE_UNSPECIFIED":return a.SIGN_MODE_UNSPECIFIED;case 1:case"SIGN_MODE_DIRECT":return a.SIGN_MODE_DIRECT;case 2:case"SIGN_MODE_TEXTUAL":return a.SIGN_MODE_TEXTUAL;case 3:case"SIGN_MODE_DIRECT_AUX":return a.SIGN_MODE_DIRECT_AUX;case 127:case"SIGN_MODE_LEGACY_AMINO_JSON":return a.SIGN_MODE_LEGACY_AMINO_JSON;case 191:case"SIGN_MODE_EIP_191":return a.SIGN_MODE_EIP_191;case-1:case"UNRECOGNIZED":default:return a.UNRECOGNIZED}}n.signModeFromJSON=c;function u(p){switch(p){case a.SIGN_MODE_UNSPECIFIED:return"SIGN_MODE_UNSPECIFIED";case a.SIGN_MODE_DIRECT:return"SIGN_MODE_DIRECT";case a.SIGN_MODE_TEXTUAL:return"SIGN_MODE_TEXTUAL";case a.SIGN_MODE_DIRECT_AUX:return"SIGN_MODE_DIRECT_AUX";case a.SIGN_MODE_LEGACY_AMINO_JSON:return"SIGN_MODE_LEGACY_AMINO_JSON";case a.SIGN_MODE_EIP_191:return"SIGN_MODE_EIP_191";case a.UNRECOGNIZED:default:return"UNRECOGNIZED"}}n.signModeToJSON=u;function f(){return{signatures:[]}}n.SignatureDescriptors={typeUrl:"/cosmos.tx.signing.v1beta1.SignatureDescriptors",encode(p,g=s.BinaryWriter.create()){for(const h of p.signatures)n.SignatureDescriptor.encode(h,g.uint32(10).fork()).ldelim();return g},decode(p,g){const h=p instanceof s.BinaryReader?p:new s.BinaryReader(p);let m=g===void 0?h.len:h.pos+g;const v=f();for(;h.pos<m;){const N=h.uint32();switch(N>>>3){case 1:v.signatures.push(n.SignatureDescriptor.decode(h,h.uint32()));break;default:h.skipType(N&7);break}}return v},fromJSON(p){const g=f();return Array.isArray(p?.signatures)&&(g.signatures=p.signatures.map(h=>n.SignatureDescriptor.fromJSON(h))),g},toJSON(p){const g={};return p.signatures?g.signatures=p.signatures.map(h=>h?n.SignatureDescriptor.toJSON(h):void 0):g.signatures=[],g},fromPartial(p){const g=f();return g.signatures=p.signatures?.map(h=>n.SignatureDescriptor.fromPartial(h))||[],g}};function y(){return{publicKey:void 0,data:void 0,sequence:BigInt(0)}}n.SignatureDescriptor={typeUrl:"/cosmos.tx.signing.v1beta1.SignatureDescriptor",encode(p,g=s.BinaryWriter.create()){return p.publicKey!==void 0&&d.Any.encode(p.publicKey,g.uint32(10).fork()).ldelim(),p.data!==void 0&&n.SignatureDescriptor_Data.encode(p.data,g.uint32(18).fork()).ldelim(),p.sequence!==BigInt(0)&&g.uint32(24).uint64(p.sequence),g},decode(p,g){const h=p instanceof s.BinaryReader?p:new s.BinaryReader(p);let m=g===void 0?h.len:h.pos+g;const v=y();for(;h.pos<m;){const N=h.uint32();switch(N>>>3){case 1:v.publicKey=d.Any.decode(h,h.uint32());break;case 2:v.data=n.SignatureDescriptor_Data.decode(h,h.uint32());break;case 3:v.sequence=h.uint64();break;default:h.skipType(N&7);break}}return v},fromJSON(p){const g=y();return(0,i.isSet)(p.publicKey)&&(g.publicKey=d.Any.fromJSON(p.publicKey)),(0,i.isSet)(p.data)&&(g.data=n.SignatureDescriptor_Data.fromJSON(p.data)),(0,i.isSet)(p.sequence)&&(g.sequence=BigInt(p.sequence.toString())),g},toJSON(p){const g={};return p.publicKey!==void 0&&(g.publicKey=p.publicKey?d.Any.toJSON(p.publicKey):void 0),p.data!==void 0&&(g.data=p.data?n.SignatureDescriptor_Data.toJSON(p.data):void 0),p.sequence!==void 0&&(g.sequence=(p.sequence||BigInt(0)).toString()),g},fromPartial(p){const g=y();return p.publicKey!==void 0&&p.publicKey!==null&&(g.publicKey=d.Any.fromPartial(p.publicKey)),p.data!==void 0&&p.data!==null&&(g.data=n.SignatureDescriptor_Data.fromPartial(p.data)),p.sequence!==void 0&&p.sequence!==null&&(g.sequence=BigInt(p.sequence.toString())),g}};function b(){return{single:void 0,multi:void 0}}n.SignatureDescriptor_Data={typeUrl:"/cosmos.tx.signing.v1beta1.Data",encode(p,g=s.BinaryWriter.create()){return p.single!==void 0&&n.SignatureDescriptor_Data_Single.encode(p.single,g.uint32(10).fork()).ldelim(),p.multi!==void 0&&n.SignatureDescriptor_Data_Multi.encode(p.multi,g.uint32(18).fork()).ldelim(),g},decode(p,g){const h=p instanceof s.BinaryReader?p:new s.BinaryReader(p);let m=g===void 0?h.len:h.pos+g;const v=b();for(;h.pos<m;){const N=h.uint32();switch(N>>>3){case 1:v.single=n.SignatureDescriptor_Data_Single.decode(h,h.uint32());break;case 2:v.multi=n.SignatureDescriptor_Data_Multi.decode(h,h.uint32());break;default:h.skipType(N&7);break}}return v},fromJSON(p){const g=b();return(0,i.isSet)(p.single)&&(g.single=n.SignatureDescriptor_Data_Single.fromJSON(p.single)),(0,i.isSet)(p.multi)&&(g.multi=n.SignatureDescriptor_Data_Multi.fromJSON(p.multi)),g},toJSON(p){const g={};return p.single!==void 0&&(g.single=p.single?n.SignatureDescriptor_Data_Single.toJSON(p.single):void 0),p.multi!==void 0&&(g.multi=p.multi?n.SignatureDescriptor_Data_Multi.toJSON(p.multi):void 0),g},fromPartial(p){const g=b();return p.single!==void 0&&p.single!==null&&(g.single=n.SignatureDescriptor_Data_Single.fromPartial(p.single)),p.multi!==void 0&&p.multi!==null&&(g.multi=n.SignatureDescriptor_Data_Multi.fromPartial(p.multi)),g}};function l(){return{mode:0,signature:new Uint8Array}}n.SignatureDescriptor_Data_Single={typeUrl:"/cosmos.tx.signing.v1beta1.Single",encode(p,g=s.BinaryWriter.create()){return p.mode!==0&&g.uint32(8).int32(p.mode),p.signature.length!==0&&g.uint32(18).bytes(p.signature),g},decode(p,g){const h=p instanceof s.BinaryReader?p:new s.BinaryReader(p);let m=g===void 0?h.len:h.pos+g;const v=l();for(;h.pos<m;){const N=h.uint32();switch(N>>>3){case 1:v.mode=h.int32();break;case 2:v.signature=h.bytes();break;default:h.skipType(N&7);break}}return v},fromJSON(p){const g=l();return(0,i.isSet)(p.mode)&&(g.mode=c(p.mode)),(0,i.isSet)(p.signature)&&(g.signature=(0,i.bytesFromBase64)(p.signature)),g},toJSON(p){const g={};return p.mode!==void 0&&(g.mode=u(p.mode)),p.signature!==void 0&&(g.signature=(0,i.base64FromBytes)(p.signature!==void 0?p.signature:new Uint8Array)),g},fromPartial(p){const g=l();return g.mode=p.mode??0,g.signature=p.signature??new Uint8Array,g}};function _(){return{bitarray:void 0,signatures:[]}}n.SignatureDescriptor_Data_Multi={typeUrl:"/cosmos.tx.signing.v1beta1.Multi",encode(p,g=s.BinaryWriter.create()){p.bitarray!==void 0&&r.CompactBitArray.encode(p.bitarray,g.uint32(10).fork()).ldelim();for(const h of p.signatures)n.SignatureDescriptor_Data.encode(h,g.uint32(18).fork()).ldelim();return g},decode(p,g){const h=p instanceof s.BinaryReader?p:new s.BinaryReader(p);let m=g===void 0?h.len:h.pos+g;const v=_();for(;h.pos<m;){const N=h.uint32();switch(N>>>3){case 1:v.bitarray=r.CompactBitArray.decode(h,h.uint32());break;case 2:v.signatures.push(n.SignatureDescriptor_Data.decode(h,h.uint32()));break;default:h.skipType(N&7);break}}return v},fromJSON(p){const g=_();return(0,i.isSet)(p.bitarray)&&(g.bitarray=r.CompactBitArray.fromJSON(p.bitarray)),Array.isArray(p?.signatures)&&(g.signatures=p.signatures.map(h=>n.SignatureDescriptor_Data.fromJSON(h))),g},toJSON(p){const g={};return p.bitarray!==void 0&&(g.bitarray=p.bitarray?r.CompactBitArray.toJSON(p.bitarray):void 0),p.signatures?g.signatures=p.signatures.map(h=>h?n.SignatureDescriptor_Data.toJSON(h):void 0):g.signatures=[],g},fromPartial(p){const g=_();return p.bitarray!==void 0&&p.bitarray!==null&&(g.bitarray=r.CompactBitArray.fromPartial(p.bitarray)),g.signatures=p.signatures?.map(h=>n.SignatureDescriptor_Data.fromPartial(h))||[],g}}}($e)),$e}var ci=rn(),Ve={},G={},Kt;function ui(){if(Kt)return G;Kt=1,Object.defineProperty(G,"__esModule",{value:!0}),G.DecProto=G.IntProto=G.DecCoin=G.Coin=G.protobufPackage=void 0;const n=Ne(),r=Be();G.protobufPackage="cosmos.base.v1beta1";function d(){return{denom:"",amount:""}}G.Coin={typeUrl:"/cosmos.base.v1beta1.Coin",encode(c,u=n.BinaryWriter.create()){return c.denom!==""&&u.uint32(10).string(c.denom),c.amount!==""&&u.uint32(18).string(c.amount),u},decode(c,u){const f=c instanceof n.BinaryReader?c:new n.BinaryReader(c);let y=u===void 0?f.len:f.pos+u;const b=d();for(;f.pos<y;){const l=f.uint32();switch(l>>>3){case 1:b.denom=f.string();break;case 2:b.amount=f.string();break;default:f.skipType(l&7);break}}return b},fromJSON(c){const u=d();return(0,r.isSet)(c.denom)&&(u.denom=String(c.denom)),(0,r.isSet)(c.amount)&&(u.amount=String(c.amount)),u},toJSON(c){const u={};return c.denom!==void 0&&(u.denom=c.denom),c.amount!==void 0&&(u.amount=c.amount),u},fromPartial(c){const u=d();return u.denom=c.denom??"",u.amount=c.amount??"",u}};function s(){return{denom:"",amount:""}}G.DecCoin={typeUrl:"/cosmos.base.v1beta1.DecCoin",encode(c,u=n.BinaryWriter.create()){return c.denom!==""&&u.uint32(10).string(c.denom),c.amount!==""&&u.uint32(18).string(c.amount),u},decode(c,u){const f=c instanceof n.BinaryReader?c:new n.BinaryReader(c);let y=u===void 0?f.len:f.pos+u;const b=s();for(;f.pos<y;){const l=f.uint32();switch(l>>>3){case 1:b.denom=f.string();break;case 2:b.amount=f.string();break;default:f.skipType(l&7);break}}return b},fromJSON(c){const u=s();return(0,r.isSet)(c.denom)&&(u.denom=String(c.denom)),(0,r.isSet)(c.amount)&&(u.amount=String(c.amount)),u},toJSON(c){const u={};return c.denom!==void 0&&(u.denom=c.denom),c.amount!==void 0&&(u.amount=c.amount),u},fromPartial(c){const u=s();return u.denom=c.denom??"",u.amount=c.amount??"",u}};function i(){return{int:""}}G.IntProto={typeUrl:"/cosmos.base.v1beta1.IntProto",encode(c,u=n.BinaryWriter.create()){return c.int!==""&&u.uint32(10).string(c.int),u},decode(c,u){const f=c instanceof n.BinaryReader?c:new n.BinaryReader(c);let y=u===void 0?f.len:f.pos+u;const b=i();for(;f.pos<y;){const l=f.uint32();switch(l>>>3){case 1:b.int=f.string();break;default:f.skipType(l&7);break}}return b},fromJSON(c){const u=i();return(0,r.isSet)(c.int)&&(u.int=String(c.int)),u},toJSON(c){const u={};return c.int!==void 0&&(u.int=c.int),u},fromPartial(c){const u=i();return u.int=c.int??"",u}};function a(){return{dec:""}}return G.DecProto={typeUrl:"/cosmos.base.v1beta1.DecProto",encode(c,u=n.BinaryWriter.create()){return c.dec!==""&&u.uint32(10).string(c.dec),u},decode(c,u){const f=c instanceof n.BinaryReader?c:new n.BinaryReader(c);let y=u===void 0?f.len:f.pos+u;const b=a();for(;f.pos<y;){const l=f.uint32();switch(l>>>3){case 1:b.dec=f.string();break;default:f.skipType(l&7);break}}return b},fromJSON(c){const u=a();return(0,r.isSet)(c.dec)&&(u.dec=String(c.dec)),u},toJSON(c){const u={};return c.dec!==void 0&&(u.dec=c.dec),u},fromPartial(c){const u=a();return u.dec=c.dec??"",u}},G}var qt;function di(){return qt||(qt=1,function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.AuxSignerData=n.Tip=n.Fee=n.ModeInfo_Multi=n.ModeInfo_Single=n.ModeInfo=n.SignerInfo=n.AuthInfo=n.TxBody=n.SignDocDirectAux=n.SignDoc=n.TxRaw=n.Tx=n.protobufPackage=void 0;const r=nn(),d=rn(),s=tn(),i=ui(),a=Ne(),c=Be();n.protobufPackage="cosmos.tx.v1beta1";function u(){return{body:void 0,authInfo:void 0,signatures:[]}}n.Tx={typeUrl:"/cosmos.tx.v1beta1.Tx",encode(e,t=a.BinaryWriter.create()){e.body!==void 0&&n.TxBody.encode(e.body,t.uint32(10).fork()).ldelim(),e.authInfo!==void 0&&n.AuthInfo.encode(e.authInfo,t.uint32(18).fork()).ldelim();for(const o of e.signatures)t.uint32(26).bytes(o);return t},decode(e,t){const o=e instanceof a.BinaryReader?e:new a.BinaryReader(e);let I=t===void 0?o.len:o.pos+t;const S=u();for(;o.pos<I;){const E=o.uint32();switch(E>>>3){case 1:S.body=n.TxBody.decode(o,o.uint32());break;case 2:S.authInfo=n.AuthInfo.decode(o,o.uint32());break;case 3:S.signatures.push(o.bytes());break;default:o.skipType(E&7);break}}return S},fromJSON(e){const t=u();return(0,c.isSet)(e.body)&&(t.body=n.TxBody.fromJSON(e.body)),(0,c.isSet)(e.authInfo)&&(t.authInfo=n.AuthInfo.fromJSON(e.authInfo)),Array.isArray(e?.signatures)&&(t.signatures=e.signatures.map(o=>(0,c.bytesFromBase64)(o))),t},toJSON(e){const t={};return e.body!==void 0&&(t.body=e.body?n.TxBody.toJSON(e.body):void 0),e.authInfo!==void 0&&(t.authInfo=e.authInfo?n.AuthInfo.toJSON(e.authInfo):void 0),e.signatures?t.signatures=e.signatures.map(o=>(0,c.base64FromBytes)(o!==void 0?o:new Uint8Array)):t.signatures=[],t},fromPartial(e){const t=u();return e.body!==void 0&&e.body!==null&&(t.body=n.TxBody.fromPartial(e.body)),e.authInfo!==void 0&&e.authInfo!==null&&(t.authInfo=n.AuthInfo.fromPartial(e.authInfo)),t.signatures=e.signatures?.map(o=>o)||[],t}};function f(){return{bodyBytes:new Uint8Array,authInfoBytes:new Uint8Array,signatures:[]}}n.TxRaw={typeUrl:"/cosmos.tx.v1beta1.TxRaw",encode(e,t=a.BinaryWriter.create()){e.bodyBytes.length!==0&&t.uint32(10).bytes(e.bodyBytes),e.authInfoBytes.length!==0&&t.uint32(18).bytes(e.authInfoBytes);for(const o of e.signatures)t.uint32(26).bytes(o);return t},decode(e,t){const o=e instanceof a.BinaryReader?e:new a.BinaryReader(e);let I=t===void 0?o.len:o.pos+t;const S=f();for(;o.pos<I;){const E=o.uint32();switch(E>>>3){case 1:S.bodyBytes=o.bytes();break;case 2:S.authInfoBytes=o.bytes();break;case 3:S.signatures.push(o.bytes());break;default:o.skipType(E&7);break}}return S},fromJSON(e){const t=f();return(0,c.isSet)(e.bodyBytes)&&(t.bodyBytes=(0,c.bytesFromBase64)(e.bodyBytes)),(0,c.isSet)(e.authInfoBytes)&&(t.authInfoBytes=(0,c.bytesFromBase64)(e.authInfoBytes)),Array.isArray(e?.signatures)&&(t.signatures=e.signatures.map(o=>(0,c.bytesFromBase64)(o))),t},toJSON(e){const t={};return e.bodyBytes!==void 0&&(t.bodyBytes=(0,c.base64FromBytes)(e.bodyBytes!==void 0?e.bodyBytes:new Uint8Array)),e.authInfoBytes!==void 0&&(t.authInfoBytes=(0,c.base64FromBytes)(e.authInfoBytes!==void 0?e.authInfoBytes:new Uint8Array)),e.signatures?t.signatures=e.signatures.map(o=>(0,c.base64FromBytes)(o!==void 0?o:new Uint8Array)):t.signatures=[],t},fromPartial(e){const t=f();return t.bodyBytes=e.bodyBytes??new Uint8Array,t.authInfoBytes=e.authInfoBytes??new Uint8Array,t.signatures=e.signatures?.map(o=>o)||[],t}};function y(){return{bodyBytes:new Uint8Array,authInfoBytes:new Uint8Array,chainId:"",accountNumber:BigInt(0)}}n.SignDoc={typeUrl:"/cosmos.tx.v1beta1.SignDoc",encode(e,t=a.BinaryWriter.create()){return e.bodyBytes.length!==0&&t.uint32(10).bytes(e.bodyBytes),e.authInfoBytes.length!==0&&t.uint32(18).bytes(e.authInfoBytes),e.chainId!==""&&t.uint32(26).string(e.chainId),e.accountNumber!==BigInt(0)&&t.uint32(32).uint64(e.accountNumber),t},decode(e,t){const o=e instanceof a.BinaryReader?e:new a.BinaryReader(e);let I=t===void 0?o.len:o.pos+t;const S=y();for(;o.pos<I;){const E=o.uint32();switch(E>>>3){case 1:S.bodyBytes=o.bytes();break;case 2:S.authInfoBytes=o.bytes();break;case 3:S.chainId=o.string();break;case 4:S.accountNumber=o.uint64();break;default:o.skipType(E&7);break}}return S},fromJSON(e){const t=y();return(0,c.isSet)(e.bodyBytes)&&(t.bodyBytes=(0,c.bytesFromBase64)(e.bodyBytes)),(0,c.isSet)(e.authInfoBytes)&&(t.authInfoBytes=(0,c.bytesFromBase64)(e.authInfoBytes)),(0,c.isSet)(e.chainId)&&(t.chainId=String(e.chainId)),(0,c.isSet)(e.accountNumber)&&(t.accountNumber=BigInt(e.accountNumber.toString())),t},toJSON(e){const t={};return e.bodyBytes!==void 0&&(t.bodyBytes=(0,c.base64FromBytes)(e.bodyBytes!==void 0?e.bodyBytes:new Uint8Array)),e.authInfoBytes!==void 0&&(t.authInfoBytes=(0,c.base64FromBytes)(e.authInfoBytes!==void 0?e.authInfoBytes:new Uint8Array)),e.chainId!==void 0&&(t.chainId=e.chainId),e.accountNumber!==void 0&&(t.accountNumber=(e.accountNumber||BigInt(0)).toString()),t},fromPartial(e){const t=y();return t.bodyBytes=e.bodyBytes??new Uint8Array,t.authInfoBytes=e.authInfoBytes??new Uint8Array,t.chainId=e.chainId??"",e.accountNumber!==void 0&&e.accountNumber!==null&&(t.accountNumber=BigInt(e.accountNumber.toString())),t}};function b(){return{bodyBytes:new Uint8Array,publicKey:void 0,chainId:"",accountNumber:BigInt(0),sequence:BigInt(0),tip:void 0}}n.SignDocDirectAux={typeUrl:"/cosmos.tx.v1beta1.SignDocDirectAux",encode(e,t=a.BinaryWriter.create()){return e.bodyBytes.length!==0&&t.uint32(10).bytes(e.bodyBytes),e.publicKey!==void 0&&r.Any.encode(e.publicKey,t.uint32(18).fork()).ldelim(),e.chainId!==""&&t.uint32(26).string(e.chainId),e.accountNumber!==BigInt(0)&&t.uint32(32).uint64(e.accountNumber),e.sequence!==BigInt(0)&&t.uint32(40).uint64(e.sequence),e.tip!==void 0&&n.Tip.encode(e.tip,t.uint32(50).fork()).ldelim(),t},decode(e,t){const o=e instanceof a.BinaryReader?e:new a.BinaryReader(e);let I=t===void 0?o.len:o.pos+t;const S=b();for(;o.pos<I;){const E=o.uint32();switch(E>>>3){case 1:S.bodyBytes=o.bytes();break;case 2:S.publicKey=r.Any.decode(o,o.uint32());break;case 3:S.chainId=o.string();break;case 4:S.accountNumber=o.uint64();break;case 5:S.sequence=o.uint64();break;case 6:S.tip=n.Tip.decode(o,o.uint32());break;default:o.skipType(E&7);break}}return S},fromJSON(e){const t=b();return(0,c.isSet)(e.bodyBytes)&&(t.bodyBytes=(0,c.bytesFromBase64)(e.bodyBytes)),(0,c.isSet)(e.publicKey)&&(t.publicKey=r.Any.fromJSON(e.publicKey)),(0,c.isSet)(e.chainId)&&(t.chainId=String(e.chainId)),(0,c.isSet)(e.accountNumber)&&(t.accountNumber=BigInt(e.accountNumber.toString())),(0,c.isSet)(e.sequence)&&(t.sequence=BigInt(e.sequence.toString())),(0,c.isSet)(e.tip)&&(t.tip=n.Tip.fromJSON(e.tip)),t},toJSON(e){const t={};return e.bodyBytes!==void 0&&(t.bodyBytes=(0,c.base64FromBytes)(e.bodyBytes!==void 0?e.bodyBytes:new Uint8Array)),e.publicKey!==void 0&&(t.publicKey=e.publicKey?r.Any.toJSON(e.publicKey):void 0),e.chainId!==void 0&&(t.chainId=e.chainId),e.accountNumber!==void 0&&(t.accountNumber=(e.accountNumber||BigInt(0)).toString()),e.sequence!==void 0&&(t.sequence=(e.sequence||BigInt(0)).toString()),e.tip!==void 0&&(t.tip=e.tip?n.Tip.toJSON(e.tip):void 0),t},fromPartial(e){const t=b();return t.bodyBytes=e.bodyBytes??new Uint8Array,e.publicKey!==void 0&&e.publicKey!==null&&(t.publicKey=r.Any.fromPartial(e.publicKey)),t.chainId=e.chainId??"",e.accountNumber!==void 0&&e.accountNumber!==null&&(t.accountNumber=BigInt(e.accountNumber.toString())),e.sequence!==void 0&&e.sequence!==null&&(t.sequence=BigInt(e.sequence.toString())),e.tip!==void 0&&e.tip!==null&&(t.tip=n.Tip.fromPartial(e.tip)),t}};function l(){return{messages:[],memo:"",timeoutHeight:BigInt(0),extensionOptions:[],nonCriticalExtensionOptions:[]}}n.TxBody={typeUrl:"/cosmos.tx.v1beta1.TxBody",encode(e,t=a.BinaryWriter.create()){for(const o of e.messages)r.Any.encode(o,t.uint32(10).fork()).ldelim();e.memo!==""&&t.uint32(18).string(e.memo),e.timeoutHeight!==BigInt(0)&&t.uint32(24).uint64(e.timeoutHeight);for(const o of e.extensionOptions)r.Any.encode(o,t.uint32(8186).fork()).ldelim();for(const o of e.nonCriticalExtensionOptions)r.Any.encode(o,t.uint32(16378).fork()).ldelim();return t},decode(e,t){const o=e instanceof a.BinaryReader?e:new a.BinaryReader(e);let I=t===void 0?o.len:o.pos+t;const S=l();for(;o.pos<I;){const E=o.uint32();switch(E>>>3){case 1:S.messages.push(r.Any.decode(o,o.uint32()));break;case 2:S.memo=o.string();break;case 3:S.timeoutHeight=o.uint64();break;case 1023:S.extensionOptions.push(r.Any.decode(o,o.uint32()));break;case 2047:S.nonCriticalExtensionOptions.push(r.Any.decode(o,o.uint32()));break;default:o.skipType(E&7);break}}return S},fromJSON(e){const t=l();return Array.isArray(e?.messages)&&(t.messages=e.messages.map(o=>r.Any.fromJSON(o))),(0,c.isSet)(e.memo)&&(t.memo=String(e.memo)),(0,c.isSet)(e.timeoutHeight)&&(t.timeoutHeight=BigInt(e.timeoutHeight.toString())),Array.isArray(e?.extensionOptions)&&(t.extensionOptions=e.extensionOptions.map(o=>r.Any.fromJSON(o))),Array.isArray(e?.nonCriticalExtensionOptions)&&(t.nonCriticalExtensionOptions=e.nonCriticalExtensionOptions.map(o=>r.Any.fromJSON(o))),t},toJSON(e){const t={};return e.messages?t.messages=e.messages.map(o=>o?r.Any.toJSON(o):void 0):t.messages=[],e.memo!==void 0&&(t.memo=e.memo),e.timeoutHeight!==void 0&&(t.timeoutHeight=(e.timeoutHeight||BigInt(0)).toString()),e.extensionOptions?t.extensionOptions=e.extensionOptions.map(o=>o?r.Any.toJSON(o):void 0):t.extensionOptions=[],e.nonCriticalExtensionOptions?t.nonCriticalExtensionOptions=e.nonCriticalExtensionOptions.map(o=>o?r.Any.toJSON(o):void 0):t.nonCriticalExtensionOptions=[],t},fromPartial(e){const t=l();return t.messages=e.messages?.map(o=>r.Any.fromPartial(o))||[],t.memo=e.memo??"",e.timeoutHeight!==void 0&&e.timeoutHeight!==null&&(t.timeoutHeight=BigInt(e.timeoutHeight.toString())),t.extensionOptions=e.extensionOptions?.map(o=>r.Any.fromPartial(o))||[],t.nonCriticalExtensionOptions=e.nonCriticalExtensionOptions?.map(o=>r.Any.fromPartial(o))||[],t}};function _(){return{signerInfos:[],fee:void 0,tip:void 0}}n.AuthInfo={typeUrl:"/cosmos.tx.v1beta1.AuthInfo",encode(e,t=a.BinaryWriter.create()){for(const o of e.signerInfos)n.SignerInfo.encode(o,t.uint32(10).fork()).ldelim();return e.fee!==void 0&&n.Fee.encode(e.fee,t.uint32(18).fork()).ldelim(),e.tip!==void 0&&n.Tip.encode(e.tip,t.uint32(26).fork()).ldelim(),t},decode(e,t){const o=e instanceof a.BinaryReader?e:new a.BinaryReader(e);let I=t===void 0?o.len:o.pos+t;const S=_();for(;o.pos<I;){const E=o.uint32();switch(E>>>3){case 1:S.signerInfos.push(n.SignerInfo.decode(o,o.uint32()));break;case 2:S.fee=n.Fee.decode(o,o.uint32());break;case 3:S.tip=n.Tip.decode(o,o.uint32());break;default:o.skipType(E&7);break}}return S},fromJSON(e){const t=_();return Array.isArray(e?.signerInfos)&&(t.signerInfos=e.signerInfos.map(o=>n.SignerInfo.fromJSON(o))),(0,c.isSet)(e.fee)&&(t.fee=n.Fee.fromJSON(e.fee)),(0,c.isSet)(e.tip)&&(t.tip=n.Tip.fromJSON(e.tip)),t},toJSON(e){const t={};return e.signerInfos?t.signerInfos=e.signerInfos.map(o=>o?n.SignerInfo.toJSON(o):void 0):t.signerInfos=[],e.fee!==void 0&&(t.fee=e.fee?n.Fee.toJSON(e.fee):void 0),e.tip!==void 0&&(t.tip=e.tip?n.Tip.toJSON(e.tip):void 0),t},fromPartial(e){const t=_();return t.signerInfos=e.signerInfos?.map(o=>n.SignerInfo.fromPartial(o))||[],e.fee!==void 0&&e.fee!==null&&(t.fee=n.Fee.fromPartial(e.fee)),e.tip!==void 0&&e.tip!==null&&(t.tip=n.Tip.fromPartial(e.tip)),t}};function p(){return{publicKey:void 0,modeInfo:void 0,sequence:BigInt(0)}}n.SignerInfo={typeUrl:"/cosmos.tx.v1beta1.SignerInfo",encode(e,t=a.BinaryWriter.create()){return e.publicKey!==void 0&&r.Any.encode(e.publicKey,t.uint32(10).fork()).ldelim(),e.modeInfo!==void 0&&n.ModeInfo.encode(e.modeInfo,t.uint32(18).fork()).ldelim(),e.sequence!==BigInt(0)&&t.uint32(24).uint64(e.sequence),t},decode(e,t){const o=e instanceof a.BinaryReader?e:new a.BinaryReader(e);let I=t===void 0?o.len:o.pos+t;const S=p();for(;o.pos<I;){const E=o.uint32();switch(E>>>3){case 1:S.publicKey=r.Any.decode(o,o.uint32());break;case 2:S.modeInfo=n.ModeInfo.decode(o,o.uint32());break;case 3:S.sequence=o.uint64();break;default:o.skipType(E&7);break}}return S},fromJSON(e){const t=p();return(0,c.isSet)(e.publicKey)&&(t.publicKey=r.Any.fromJSON(e.publicKey)),(0,c.isSet)(e.modeInfo)&&(t.modeInfo=n.ModeInfo.fromJSON(e.modeInfo)),(0,c.isSet)(e.sequence)&&(t.sequence=BigInt(e.sequence.toString())),t},toJSON(e){const t={};return e.publicKey!==void 0&&(t.publicKey=e.publicKey?r.Any.toJSON(e.publicKey):void 0),e.modeInfo!==void 0&&(t.modeInfo=e.modeInfo?n.ModeInfo.toJSON(e.modeInfo):void 0),e.sequence!==void 0&&(t.sequence=(e.sequence||BigInt(0)).toString()),t},fromPartial(e){const t=p();return e.publicKey!==void 0&&e.publicKey!==null&&(t.publicKey=r.Any.fromPartial(e.publicKey)),e.modeInfo!==void 0&&e.modeInfo!==null&&(t.modeInfo=n.ModeInfo.fromPartial(e.modeInfo)),e.sequence!==void 0&&e.sequence!==null&&(t.sequence=BigInt(e.sequence.toString())),t}};function g(){return{single:void 0,multi:void 0}}n.ModeInfo={typeUrl:"/cosmos.tx.v1beta1.ModeInfo",encode(e,t=a.BinaryWriter.create()){return e.single!==void 0&&n.ModeInfo_Single.encode(e.single,t.uint32(10).fork()).ldelim(),e.multi!==void 0&&n.ModeInfo_Multi.encode(e.multi,t.uint32(18).fork()).ldelim(),t},decode(e,t){const o=e instanceof a.BinaryReader?e:new a.BinaryReader(e);let I=t===void 0?o.len:o.pos+t;const S=g();for(;o.pos<I;){const E=o.uint32();switch(E>>>3){case 1:S.single=n.ModeInfo_Single.decode(o,o.uint32());break;case 2:S.multi=n.ModeInfo_Multi.decode(o,o.uint32());break;default:o.skipType(E&7);break}}return S},fromJSON(e){const t=g();return(0,c.isSet)(e.single)&&(t.single=n.ModeInfo_Single.fromJSON(e.single)),(0,c.isSet)(e.multi)&&(t.multi=n.ModeInfo_Multi.fromJSON(e.multi)),t},toJSON(e){const t={};return e.single!==void 0&&(t.single=e.single?n.ModeInfo_Single.toJSON(e.single):void 0),e.multi!==void 0&&(t.multi=e.multi?n.ModeInfo_Multi.toJSON(e.multi):void 0),t},fromPartial(e){const t=g();return e.single!==void 0&&e.single!==null&&(t.single=n.ModeInfo_Single.fromPartial(e.single)),e.multi!==void 0&&e.multi!==null&&(t.multi=n.ModeInfo_Multi.fromPartial(e.multi)),t}};function h(){return{mode:0}}n.ModeInfo_Single={typeUrl:"/cosmos.tx.v1beta1.Single",encode(e,t=a.BinaryWriter.create()){return e.mode!==0&&t.uint32(8).int32(e.mode),t},decode(e,t){const o=e instanceof a.BinaryReader?e:new a.BinaryReader(e);let I=t===void 0?o.len:o.pos+t;const S=h();for(;o.pos<I;){const E=o.uint32();switch(E>>>3){case 1:S.mode=o.int32();break;default:o.skipType(E&7);break}}return S},fromJSON(e){const t=h();return(0,c.isSet)(e.mode)&&(t.mode=(0,d.signModeFromJSON)(e.mode)),t},toJSON(e){const t={};return e.mode!==void 0&&(t.mode=(0,d.signModeToJSON)(e.mode)),t},fromPartial(e){const t=h();return t.mode=e.mode??0,t}};function m(){return{bitarray:void 0,modeInfos:[]}}n.ModeInfo_Multi={typeUrl:"/cosmos.tx.v1beta1.Multi",encode(e,t=a.BinaryWriter.create()){e.bitarray!==void 0&&s.CompactBitArray.encode(e.bitarray,t.uint32(10).fork()).ldelim();for(const o of e.modeInfos)n.ModeInfo.encode(o,t.uint32(18).fork()).ldelim();return t},decode(e,t){const o=e instanceof a.BinaryReader?e:new a.BinaryReader(e);let I=t===void 0?o.len:o.pos+t;const S=m();for(;o.pos<I;){const E=o.uint32();switch(E>>>3){case 1:S.bitarray=s.CompactBitArray.decode(o,o.uint32());break;case 2:S.modeInfos.push(n.ModeInfo.decode(o,o.uint32()));break;default:o.skipType(E&7);break}}return S},fromJSON(e){const t=m();return(0,c.isSet)(e.bitarray)&&(t.bitarray=s.CompactBitArray.fromJSON(e.bitarray)),Array.isArray(e?.modeInfos)&&(t.modeInfos=e.modeInfos.map(o=>n.ModeInfo.fromJSON(o))),t},toJSON(e){const t={};return e.bitarray!==void 0&&(t.bitarray=e.bitarray?s.CompactBitArray.toJSON(e.bitarray):void 0),e.modeInfos?t.modeInfos=e.modeInfos.map(o=>o?n.ModeInfo.toJSON(o):void 0):t.modeInfos=[],t},fromPartial(e){const t=m();return e.bitarray!==void 0&&e.bitarray!==null&&(t.bitarray=s.CompactBitArray.fromPartial(e.bitarray)),t.modeInfos=e.modeInfos?.map(o=>n.ModeInfo.fromPartial(o))||[],t}};function v(){return{amount:[],gasLimit:BigInt(0),payer:"",granter:""}}n.Fee={typeUrl:"/cosmos.tx.v1beta1.Fee",encode(e,t=a.BinaryWriter.create()){for(const o of e.amount)i.Coin.encode(o,t.uint32(10).fork()).ldelim();return e.gasLimit!==BigInt(0)&&t.uint32(16).uint64(e.gasLimit),e.payer!==""&&t.uint32(26).string(e.payer),e.granter!==""&&t.uint32(34).string(e.granter),t},decode(e,t){const o=e instanceof a.BinaryReader?e:new a.BinaryReader(e);let I=t===void 0?o.len:o.pos+t;const S=v();for(;o.pos<I;){const E=o.uint32();switch(E>>>3){case 1:S.amount.push(i.Coin.decode(o,o.uint32()));break;case 2:S.gasLimit=o.uint64();break;case 3:S.payer=o.string();break;case 4:S.granter=o.string();break;default:o.skipType(E&7);break}}return S},fromJSON(e){const t=v();return Array.isArray(e?.amount)&&(t.amount=e.amount.map(o=>i.Coin.fromJSON(o))),(0,c.isSet)(e.gasLimit)&&(t.gasLimit=BigInt(e.gasLimit.toString())),(0,c.isSet)(e.payer)&&(t.payer=String(e.payer)),(0,c.isSet)(e.granter)&&(t.granter=String(e.granter)),t},toJSON(e){const t={};return e.amount?t.amount=e.amount.map(o=>o?i.Coin.toJSON(o):void 0):t.amount=[],e.gasLimit!==void 0&&(t.gasLimit=(e.gasLimit||BigInt(0)).toString()),e.payer!==void 0&&(t.payer=e.payer),e.granter!==void 0&&(t.granter=e.granter),t},fromPartial(e){const t=v();return t.amount=e.amount?.map(o=>i.Coin.fromPartial(o))||[],e.gasLimit!==void 0&&e.gasLimit!==null&&(t.gasLimit=BigInt(e.gasLimit.toString())),t.payer=e.payer??"",t.granter=e.granter??"",t}};function N(){return{amount:[],tipper:""}}n.Tip={typeUrl:"/cosmos.tx.v1beta1.Tip",encode(e,t=a.BinaryWriter.create()){for(const o of e.amount)i.Coin.encode(o,t.uint32(10).fork()).ldelim();return e.tipper!==""&&t.uint32(18).string(e.tipper),t},decode(e,t){const o=e instanceof a.BinaryReader?e:new a.BinaryReader(e);let I=t===void 0?o.len:o.pos+t;const S=N();for(;o.pos<I;){const E=o.uint32();switch(E>>>3){case 1:S.amount.push(i.Coin.decode(o,o.uint32()));break;case 2:S.tipper=o.string();break;default:o.skipType(E&7);break}}return S},fromJSON(e){const t=N();return Array.isArray(e?.amount)&&(t.amount=e.amount.map(o=>i.Coin.fromJSON(o))),(0,c.isSet)(e.tipper)&&(t.tipper=String(e.tipper)),t},toJSON(e){const t={};return e.amount?t.amount=e.amount.map(o=>o?i.Coin.toJSON(o):void 0):t.amount=[],e.tipper!==void 0&&(t.tipper=e.tipper),t},fromPartial(e){const t=N();return t.amount=e.amount?.map(o=>i.Coin.fromPartial(o))||[],t.tipper=e.tipper??"",t}};function M(){return{address:"",signDoc:void 0,mode:0,sig:new Uint8Array}}n.AuxSignerData={typeUrl:"/cosmos.tx.v1beta1.AuxSignerData",encode(e,t=a.BinaryWriter.create()){return e.address!==""&&t.uint32(10).string(e.address),e.signDoc!==void 0&&n.SignDocDirectAux.encode(e.signDoc,t.uint32(18).fork()).ldelim(),e.mode!==0&&t.uint32(24).int32(e.mode),e.sig.length!==0&&t.uint32(34).bytes(e.sig),t},decode(e,t){const o=e instanceof a.BinaryReader?e:new a.BinaryReader(e);let I=t===void 0?o.len:o.pos+t;const S=M();for(;o.pos<I;){const E=o.uint32();switch(E>>>3){case 1:S.address=o.string();break;case 2:S.signDoc=n.SignDocDirectAux.decode(o,o.uint32());break;case 3:S.mode=o.int32();break;case 4:S.sig=o.bytes();break;default:o.skipType(E&7);break}}return S},fromJSON(e){const t=M();return(0,c.isSet)(e.address)&&(t.address=String(e.address)),(0,c.isSet)(e.signDoc)&&(t.signDoc=n.SignDocDirectAux.fromJSON(e.signDoc)),(0,c.isSet)(e.mode)&&(t.mode=(0,d.signModeFromJSON)(e.mode)),(0,c.isSet)(e.sig)&&(t.sig=(0,c.bytesFromBase64)(e.sig)),t},toJSON(e){const t={};return e.address!==void 0&&(t.address=e.address),e.signDoc!==void 0&&(t.signDoc=e.signDoc?n.SignDocDirectAux.toJSON(e.signDoc):void 0),e.mode!==void 0&&(t.mode=(0,d.signModeToJSON)(e.mode)),e.sig!==void 0&&(t.sig=(0,c.base64FromBytes)(e.sig!==void 0?e.sig:new Uint8Array)),t},fromPartial(e){const t=M();return t.address=e.address??"",e.signDoc!==void 0&&e.signDoc!==null&&(t.signDoc=n.SignDocDirectAux.fromPartial(e.signDoc)),t.mode=e.mode??0,t.sig=e.sig??new Uint8Array,t}}}(Ve)),Ve}var ke=di();const fi=async n=>{const r=rt.chains.find(l=>l.chain_id===n);if(!r)throw new Error(`Chain info not found for chainId: ${n}`);const{bech32_prefix:d,chain_id:s}=r,i=r.staking?.staking_tokens?.[0]?.denom,a=r.apis?.rpc?.[0]?.address,c=r.apis?.rest?.[0]?.address,u=r.fees?.fee_tokens?.[0]?.average_gas_price;if(!d||!i||!a||!c||!s||u===void 0)throw new Error(`Missing required chain information for ${r.chain_name}`);const y=rt.assets.find(l=>l.chain_name===r.chain_name)?.assets.find(l=>l.base===i),b=y?.denom_units.find(l=>l.denom===y.display)?.exponent;if(b===void 0)throw new Error(`Could not find decimals for ${i} on chain ${r.chain_name}`);return{prefix:d,denom:i,rpcUrl:a,restUrl:c,expectedChainId:s,gasPrice:u,decimals:b}};class on extends Me{constructor({chainId:r,contract:d,endpoints:s}){super(),this.contract=d,this.registry=new ge.Registry,this.chainId=r,this.endpoints=s}parseRSVSignature(r){return new Uint8Array([...re.fromHex(r.r),...re.fromHex(r.s)])}async getChainInfo(){return{...await fi(this.chainId),...this.endpoints}}async getBalance(r){try{const{restUrl:d,denom:s,decimals:i}=await this.getChainInfo(),a=await fetch(`${d}/cosmos/bank/v1beta1/balances/${r}`);if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);const f=(await a.json()).balances.find(b=>b.denom===s)?.amount??"0";return(parseInt(f)/Math.pow(10,i)).toString()}catch(d){throw console.error("Failed to fetch Cosmos balance:",d),new Error("Failed to fetch Cosmos balance")}}async deriveAddressAndPublicKey(r,d){const{prefix:s}=await this.getChainInfo(),i=await this.contract.getDerivedPublicKey({path:d,predecessor:r});if(!i)throw new Error("Failed to get derived public key");const a=Qe(i),c=Fe.sha256(re.fromHex(a)),u=Fe.ripemd160(c);return{address:nt.bech32.encode(s,nt.bech32.toWords(u)),publicKey:a}}setTransaction(r,d){const s=ke.TxRaw.encode(r).finish();window.localStorage.setItem(d,re.toBase64(s))}getTransaction(r,d){const s=window.localStorage.getItem(r);if(s)return d?.remove&&window.localStorage.removeItem(r),ke.TxRaw.decode(re.fromBase64(s))}async getMPCPayloadAndTransaction(r){const{denom:d,rpcUrl:s,gasPrice:i}=await this.getChainInfo(),a=re.fromHex(r.publicKey),c=r.gas||2e5,u=Te.calculateFee(c,Te.GasPrice.fromString(`${i}${d}`)),y=await(await Te.StargateClient.connect(s)).getAccount(r.address);if(!y)throw new Error(`Account ${r.address} does not exist on chain`);const{accountNumber:b,sequence:l}=y,_={typeUrl:"/cosmos.tx.v1beta1.TxBody",value:{messages:r.messages,memo:r.memo||""}},p=this.registry.encode(_),g=ge.encodePubkey(pn.encodeSecp256k1Pubkey(a)),h=ge.makeAuthInfoBytes([{pubkey:g,sequence:l}],u.amount,Number(u.gas),void 0,void 0,ci.SignMode.SIGN_MODE_DIRECT),m=ge.makeSignDoc(p,h,this.chainId,b),v=ge.makeSignBytes(m),N=Array.from(Fe.sha256(v));return{transaction:ke.TxRaw.fromPartial({bodyBytes:p,authInfoBytes:h,signatures:[]}),mpcPayloads:[N]}}addSignature({transaction:r,mpcSignatures:d}){r.signatures=d.map(i=>this.parseRSVSignature(i));const s=ke.TxRaw.encode(r).finish();return Buffer.from(s).toString("hex")}async broadcastTx(r){try{const{rpcUrl:d}=await this.getChainInfo(),s=await Te.StargateClient.connect(d),i=re.fromHex(r),a=await s.broadcastTx(i);if(a.code!==0)throw new Error(`Broadcast error: ${a.rawLog}`);return a.transactionHash}catch(d){throw console.error("Transaction broadcast failed:",d),new Error("Failed to broadcast transaction.")}}}const li=async(n,r)=>{try{const d=await Ce({networkId:n.nearAuthentication.networkId,accountId:n.nearAuthentication.accountId,keypair:r}),s=new pe({networkId:n.nearAuthentication.networkId,contractId:n.chainConfig.contract,accountId:d.accountId,keypair:r}),i=new Yt({rpcUrl:n.chainConfig.providerUrl,contract:s}),{transaction:a,mpcPayloads:c}=await i.getMPCPayloadAndTransaction(n.transaction),u=await s.sign({payload:c[0],path:n.derivationPath,key_version:0}),f=i.addSignature({transaction:a,mpcSignatures:[u]});return{transactionHash:await i.broadcastTx(f),success:!0}}catch(d){return console.error(d),{success:!1,errorMessage:d instanceof Error?d.message:String(d)}}},pi=async(n,r)=>{try{const d=await Ce({networkId:n.nearAuthentication.networkId,accountId:n.nearAuthentication.accountId,keypair:r}),s=new pe({networkId:n.nearAuthentication.networkId,contractId:n.chainConfig.contract,accountId:d.accountId,keypair:r}),i=new de({btcRpcAdapter:new en.Mempool(n.chainConfig.providerUrl),contract:s,network:n.chainConfig.network}),{transaction:a,mpcPayloads:c}=await i.getMPCPayloadAndTransaction(n.transaction),u=await Promise.all(c.map(async b=>await s.sign({payload:b,path:n.derivationPath,key_version:0}))),f=i.addSignature({transaction:a,mpcSignatures:u});return{transactionHash:await i.broadcastTx(f),success:!0}}catch(d){return{success:!1,errorMessage:d instanceof Error?d.message:String(d)}}},yi=async(n,r)=>{try{const d=await Ce({networkId:n.nearAuthentication.networkId,accountId:n.nearAuthentication.accountId,keypair:r}),s=new pe({networkId:n.nearAuthentication.networkId,contractId:n.chainConfig.contract,accountId:d.accountId,keypair:r}),i=new on({contract:s,chainId:n.chainConfig.chainId}),{transaction:a,mpcPayloads:c}=await i.getMPCPayloadAndTransaction(n.transaction),u=await Promise.all(c.map(async b=>await s.sign({payload:b,path:n.derivationPath,key_version:0}))),f=i.addSignature({transaction:a,mpcSignatures:u});return{transactionHash:await i.broadcastTx(f),success:!0}}catch(d){return console.error(d),{success:!1,errorMessage:d instanceof Error?d.message:String(d)}}},hi=Object.freeze({__proto__:null,BTCTransaction:pi,CosmosTransaction:yi,EVMTransaction:li}),gi=Object.freeze({__proto__:null,keypair:hi}),mi=Object.freeze({__proto__:null,ChainSignatureContract:pe,signAndSend:gi,transactionBuilder:ii}),bi=Object.freeze({__proto__:null,near:mi}),Ye=n=>({r:n.big_r.affine_point.substring(2),s:n.s.scalar,v:n.recovery_id}),Qe=n=>{const r=n.slice(2);if(r.length!==128)throw new Error("Invalid uncompressed public key length");const d=r.slice(0,64),s=r.slice(64);return(parseInt(s.slice(-1),16)%2===0?"02":"03")+d},_i=Object.freeze({__proto__:null,compressPubKey:Qe,toRSV:Ye}),vi=Object.freeze({__proto__:null,chains:bi,cryptography:_i});exports.BTCRpcAdapter=Qt;exports.BTCRpcAdapters=en;exports.Bitcoin=de;exports.Chain=Me;exports.ChainSignatureContract=Xt;exports.Cosmos=on;exports.EVM=Yt;exports.fetchEVMFeeProperties=Zt;exports.utils=vi;
12
+ //# sourceMappingURL=index.browser.cjs.map