@nemoprotocol/points-sdk
Version:
## Table of Contents
7 lines (5 loc) • 164 kB
JavaScript
(function(Ee,V){typeof exports=="object"&&typeof module<"u"?V(exports,require("decimal.js"),require("@cetusprotocol/vaults-sdk")):typeof define=="function"&&define.amd?define(["exports","decimal.js","@cetusprotocol/vaults-sdk"],V):(Ee=typeof globalThis<"u"?globalThis:Ee||self,V(Ee.NemoContractSDK={},Ee.Decimal))})(this,function(Ee,V){"use strict";/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function sa(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Vr(r,e){return Array.isArray(e)?e.length===0?!0:r?e.every(t=>typeof t=="string"):e.every(t=>Number.isSafeInteger(t)):!1}function Jt(r,e){if(typeof e!="string")throw new Error(`${r}: string expected`);return!0}function Dr(r){if(!Number.isSafeInteger(r))throw new Error(`invalid integer: ${r}`)}function Yt(r){if(!Array.isArray(r))throw new Error("array expected")}function zr(r,e){if(!Vr(!0,e))throw new Error(`${r}: array of strings expected`)}function aa(r,e){if(!Vr(!1,e))throw new Error(`${r}: array of numbers expected`)}function ia(...r){const e=a=>a,t=(a,i)=>o=>a(i(o)),n=r.map(a=>a.encode).reduceRight(t,e),s=r.map(a=>a.decode).reduce(t,e);return{encode:n,decode:s}}function oa(r){const e=typeof r=="string"?r.split(""):r,t=e.length;zr("alphabet",e);const n=new Map(e.map((s,a)=>[s,a]));return{encode:s=>(Yt(s),s.map(a=>{if(!Number.isSafeInteger(a)||a<0||a>=t)throw new Error(`alphabet.encode: digit index outside alphabet "${a}". Allowed: ${r}`);return e[a]})),decode:s=>(Yt(s),s.map(a=>{Jt("alphabet.decode",a);const i=n.get(a);if(i===void 0)throw new Error(`Unknown letter: "${a}". Allowed: ${r}`);return i}))}}function ca(r=""){return Jt("join",r),{encode:e=>(zr("join.decode",e),e.join(r)),decode:e=>(Jt("join.decode",e),e.split(r))}}function Wr(r,e,t){if(e<2)throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);if(t<2)throw new Error(`convertRadix: invalid to=${t}, base cannot be less than 2`);if(Yt(r),!r.length)return[];let n=0;const s=[],a=Array.from(r,o=>{if(Dr(o),o<0||o>=e)throw new Error(`invalid integer: ${o}`);return o}),i=a.length;for(;;){let o=0,u=!0;for(let d=n;d<i;d++){const l=a[d],f=e*o,p=f+l;if(!Number.isSafeInteger(p)||f/e!==o||p-l!==f)throw new Error("convertRadix: carry overflow");const v=p/t;o=p%t;const y=Math.floor(v);if(a[d]=y,!Number.isSafeInteger(y)||y*t+o!==p)throw new Error("convertRadix: carry overflow");if(u)y?u=!1:n=d;else continue}if(s.push(o),u)break}for(let o=0;o<r.length-1&&r[o]===0;o++)s.push(0);return s.reverse()}function ua(r){Dr(r);const e=2**8;return{encode:t=>{if(!sa(t))throw new Error("radix.encode input should be Uint8Array");return Wr(Array.from(t),e,r)},decode:t=>(aa("radix.decode",t),Uint8Array.from(Wr(t,r,e)))}}const Fr=(r=>ia(ua(58),oa(r),ca("")))("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),wt=r=>Fr.encode(r),nt=r=>Fr.decode(r);function Y(r){return Uint8Array.from(atob(r),e=>e.charCodeAt(0))}const Qt=8192;function W(r){if(r.length<Qt)return btoa(String.fromCharCode(...r));let e="";for(var t=0;t<r.length;t+=Qt){const n=r.slice(t,t+Qt);e+=String.fromCharCode(...n)}return btoa(e)}function Gr(r){const e=r.startsWith("0x")?r.slice(2):r,t=e.length%2===0?e:`0${e}`,n=t.match(/[0-9a-fA-F]{2}/g)?.map(s=>parseInt(s,16))??[];if(n.length!==t.length/2)throw new Error(`Invalid hex string ${r}`);return Uint8Array.from(n)}function He(r){return r.reduce((e,t)=>e+t.toString(16).padStart(2,"0"),"")}function _t(r,e){return Array.from({length:Math.ceil(r.length/e)},(t,n)=>r.slice(n*e,(n+1)*e))}class qr{constructor(e,t){if(typeof e!="function")throw new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but got: ${e}.`);this._batchLoadFn=e,this._maxBatchSize=pa(t),this._batchScheduleFn=ha(t),this._cacheKeyFn=ba(t),this._cacheMap=ma(t),this._batch=null,this.name=ya(t)}load(e){if(e==null)throw new TypeError(`The loader.load() function must be called with a value, but got: ${String(e)}.`);const t=da(this),n=this._cacheMap;let s;if(n){s=this._cacheKeyFn(e);const i=n.get(s);if(i){const o=t.cacheHits||(t.cacheHits=[]);return new Promise(u=>{o.push(()=>{u(i)})})}}t.keys.push(e);const a=new Promise((i,o)=>{t.callbacks.push({resolve:i,reject:o})});return n&&n.set(s,a),a}loadMany(e){if(!Kr(e))throw new TypeError(`The loader.loadMany() function must be called with Array<key>, but got: ${e}.`);const t=[];for(let n=0;n<e.length;n++)t.push(this.load(e[n]).catch(s=>s));return Promise.all(t)}clear(e){const t=this._cacheMap;if(t){const n=this._cacheKeyFn(e);t.delete(n)}return this}clearAll(){const e=this._cacheMap;return e&&e.clear(),this}prime(e,t){const n=this._cacheMap;if(n){const s=this._cacheKeyFn(e);if(n.get(s)===void 0){let a;t instanceof Error?(a=Promise.reject(t),a.catch(()=>{})):a=Promise.resolve(t),n.set(s,a)}}return this}}const la=typeof process=="object"&&typeof process.nextTick=="function"?function(r){Xt||(Xt=Promise.resolve()),Xt.then(()=>{process.nextTick(r)})}:typeof setImmediate=="function"?function(r){setImmediate(r)}:function(r){setTimeout(r)};let Xt;function da(r){const e=r._batch;if(e!==null&&!e.hasDispatched&&e.keys.length<r._maxBatchSize)return e;const t={hasDispatched:!1,keys:[],callbacks:[]};return r._batch=t,r._batchScheduleFn(()=>{fa(r,t)}),t}function fa(r,e){if(e.hasDispatched=!0,e.keys.length===0){er(e);return}let t;try{t=r._batchLoadFn(e.keys)}catch(n){return Zt(r,e,new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function errored synchronously: ${String(n)}.`))}if(!t||typeof t.then!="function")return Zt(r,e,new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise: ${String(t)}.`));Promise.resolve(t).then(n=>{if(!Kr(n))throw new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise of an Array: ${String(n)}.`);if(n.length!==e.keys.length)throw new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise of an Array of the same length as the Array of keys.
Keys:
${String(e.keys)}
Values:
${String(n)}`);er(e);for(let s=0;s<e.callbacks.length;s++){const a=n[s];a instanceof Error?e.callbacks[s].reject(a):e.callbacks[s].resolve(a)}}).catch(n=>{Zt(r,e,n)})}function Zt(r,e,t){er(e);for(let n=0;n<e.keys.length;n++)r.clear(e.keys[n]),e.callbacks[n].reject(t)}function er(r){if(r.cacheHits)for(let e=0;e<r.cacheHits.length;e++)r.cacheHits[e]()}function pa(r){if(!(!r||r.batch!==!1))return 1;const t=r&&r.maxBatchSize;if(t===void 0)return 1/0;if(typeof t!="number"||t<1)throw new TypeError(`maxBatchSize must be a positive number: ${t}`);return t}function ha(r){const e=r&&r.batchScheduleFn;if(e===void 0)return la;if(typeof e!="function")throw new TypeError(`batchScheduleFn must be a function: ${e}`);return e}function ba(r){const e=r&&r.cacheKeyFn;if(e===void 0)return t=>t;if(typeof e!="function")throw new TypeError(`cacheKeyFn must be a function: ${e}`);return e}function ma(r){if(!(!r||r.cache!==!1))return null;const t=r&&r.cacheMap;if(t===void 0)return new Map;if(t!==null){const s=["get","set","delete","clear"].filter(a=>t&&typeof t[a]!="function");if(s.length!==0)throw new TypeError("Custom cacheMap missing methods: "+s.join(", "))}return t}function ya(r){return r&&r.name?r.name:null}function Kr(r){return typeof r=="object"&&r!==null&&"length"in r&&typeof r.length=="number"&&(r.length===0||r.length>0&&Object.prototype.hasOwnProperty.call(r,r.length-1))}function Tt(r){const e=[];let t=0;if(r===0)return[0];for(;r>0;)e[t]=r&127,(r>>=7)&&(e[t]|=128),t+=1;return e}function ga(r){let e=0,t=0,n=0;for(;;){const s=r[n];if(n+=1,e|=(s&127)<<t,(s&128)===0)break;t+=7}return{value:e,length:n}}class va{constructor(e){this.bytePosition=0,this.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength)}shift(e){return this.bytePosition+=e,this}read8(){const e=this.dataView.getUint8(this.bytePosition);return this.shift(1),e}read16(){const e=this.dataView.getUint16(this.bytePosition,!0);return this.shift(2),e}read32(){const e=this.dataView.getUint32(this.bytePosition,!0);return this.shift(4),e}read64(){const e=this.read32(),n=this.read32().toString(16)+e.toString(16).padStart(8,"0");return BigInt("0x"+n).toString(10)}read128(){const e=BigInt(this.read64()),n=BigInt(this.read64()).toString(16)+e.toString(16).padStart(16,"0");return BigInt("0x"+n).toString(10)}read256(){const e=BigInt(this.read128()),n=BigInt(this.read128()).toString(16)+e.toString(16).padStart(32,"0");return BigInt("0x"+n).toString(10)}readBytes(e){const t=this.bytePosition+this.dataView.byteOffset,n=new Uint8Array(this.dataView.buffer,t,e);return this.shift(e),n}readULEB(){const e=this.bytePosition+this.dataView.byteOffset,t=new Uint8Array(this.dataView.buffer,e),{value:n,length:s}=ga(t);return this.shift(s),n}readVec(e){const t=this.readULEB(),n=[];for(let s=0;s<t;s++)n.push(e(this,s,t));return n}}function wa(r,e){switch(e){case"base58":return wt(r);case"base64":return W(r);case"hex":return He(r);default:throw new Error("Unsupported encoding, supported values are: base64, hex")}}function Hr(r,e=["<",">"]){const[t,n]=e,s=[];let a="",i=0;for(let o=0;o<r.length;o++){const u=r[o];if(u===t&&i++,u===n&&i--,i===0&&u===","){s.push(a.trim()),a="";continue}a+=u}return s.push(a.trim()),s}class _a{constructor({initialSize:e=1024,maxSize:t=1/0,allocateSize:n=1024}={}){this.bytePosition=0,this.size=e,this.maxSize=t,this.allocateSize=n,this.dataView=new DataView(new ArrayBuffer(e))}ensureSizeOrGrow(e){const t=this.bytePosition+e;if(t>this.size){const n=Math.min(this.maxSize,this.size+this.allocateSize);if(t>n)throw new Error(`Attempting to serialize to BCS, but buffer does not have enough size. Allocated size: ${this.size}, Max size: ${this.maxSize}, Required size: ${t}`);this.size=n;const s=new ArrayBuffer(this.size);new Uint8Array(s).set(new Uint8Array(this.dataView.buffer)),this.dataView=new DataView(s)}}shift(e){return this.bytePosition+=e,this}write8(e){return this.ensureSizeOrGrow(1),this.dataView.setUint8(this.bytePosition,Number(e)),this.shift(1)}write16(e){return this.ensureSizeOrGrow(2),this.dataView.setUint16(this.bytePosition,Number(e),!0),this.shift(2)}write32(e){return this.ensureSizeOrGrow(4),this.dataView.setUint32(this.bytePosition,Number(e),!0),this.shift(4)}write64(e){return tr(BigInt(e),8).forEach(t=>this.write8(t)),this}write128(e){return tr(BigInt(e),16).forEach(t=>this.write8(t)),this}write256(e){return tr(BigInt(e),32).forEach(t=>this.write8(t)),this}writeULEB(e){return Tt(e).forEach(t=>this.write8(t)),this}writeVec(e,t){return this.writeULEB(e.length),Array.from(e).forEach((n,s)=>t(this,n,s,e.length)),this}*[Symbol.iterator](){for(let e=0;e<this.bytePosition;e++)yield this.dataView.getUint8(e);return this.toBytes()}toBytes(){return new Uint8Array(this.dataView.buffer.slice(0,this.bytePosition))}toString(e){return wa(this.toBytes(),e)}}function tr(r,e){const t=new Uint8Array(e);let n=0;for(;r>0;)t[n]=Number(r%BigInt(256)),r=r/BigInt(256),n+=1;return t}var Jr=r=>{throw TypeError(r)},Yr=(r,e,t)=>e.has(r)||Jr("Cannot "+t),ae=(r,e,t)=>(Yr(r,e,"read from private field"),t?t.call(r):e.get(r)),St=(r,e,t)=>e.has(r)?Jr("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),kt=(r,e,t,n)=>(Yr(r,e,"write to private field"),e.set(r,t),t),Je,st,At,Oe;const Ta=class ra{constructor(e){St(this,Je),St(this,st),this.name=e.name,this.read=e.read,this.serializedSize=e.serializedSize??(()=>null),kt(this,Je,e.write),kt(this,st,e.serialize??((t,n)=>{const s=new _a({initialSize:this.serializedSize(t)??void 0,...n});return ae(this,Je).call(this,t,s),s.toBytes()})),this.validate=e.validate??(()=>{})}write(e,t){this.validate(e),ae(this,Je).call(this,e,t)}serialize(e,t){return this.validate(e),new Sa(this,ae(this,st).call(this,e,t))}parse(e){const t=new va(e);return this.read(t)}fromHex(e){return this.parse(Gr(e))}fromBase58(e){return this.parse(nt(e))}fromBase64(e){return this.parse(Y(e))}transform({name:e,input:t,output:n,validate:s}){return new ra({name:e??this.name,read:a=>n?n(this.read(a)):this.read(a),write:(a,i)=>ae(this,Je).call(this,t?t(a):a,i),serializedSize:a=>this.serializedSize(t?t(a):a),serialize:(a,i)=>ae(this,st).call(this,t?t(a):a,i),validate:a=>{s?.(a),this.validate(t?t(a):a)}})}};Je=new WeakMap,st=new WeakMap;let fe=Ta;const Qr=Symbol.for("@mysten/serialized-bcs");function rr(r){return!!r&&typeof r=="object"&&r[Qr]===!0}class Sa{constructor(e,t){St(this,At),St(this,Oe),kt(this,At,e),kt(this,Oe,t)}get[Qr](){return!0}toBytes(){return ae(this,Oe)}toHex(){return He(ae(this,Oe))}toBase64(){return W(ae(this,Oe))}toBase58(){return wt(ae(this,Oe))}parse(){return ae(this,At).parse(ae(this,Oe))}}At=new WeakMap,Oe=new WeakMap;function It({size:r,...e}){return new fe({...e,serializedSize:()=>r})}function nr({readMethod:r,writeMethod:e,...t}){return It({...t,read:n=>n[r](),write:(n,s)=>s[e](n),validate:n=>{if(n<0||n>t.maxValue)throw new TypeError(`Invalid ${t.name} value: ${n}. Expected value in range 0-${t.maxValue}`);t.validate?.(n)}})}function sr({readMethod:r,writeMethod:e,...t}){return It({...t,read:n=>n[r](),write:(n,s)=>s[e](BigInt(n)),validate:n=>{const s=BigInt(n);if(s<0||s>t.maxValue)throw new TypeError(`Invalid ${t.name} value: ${s}. Expected value in range 0-${t.maxValue}`);t.validate?.(s)}})}function ka({serialize:r,...e}){const t=new fe({...e,serialize:r,write:(n,s)=>{for(const a of t.serialize(n).toBytes())s.write8(a)}});return t}function Aa({toBytes:r,fromBytes:e,...t}){return new fe({...t,read:n=>{const s=n.readULEB(),a=n.readBytes(s);return e(a)},write:(n,s)=>{const a=r(n);s.writeULEB(a.length);for(let i=0;i<a.length;i++)s.write8(a[i])},serialize:n=>{const s=r(n),a=Tt(s.length),i=new Uint8Array(a.length+s.length);return i.set(a,0),i.set(s,a.length),i},validate:n=>{if(typeof n!="string")throw new TypeError(`Invalid ${t.name} value: ${n}. Expected string`);t.validate?.(n)}})}function Ia(r){let e=null;function t(){return e||(e=r()),e}return new fe({name:"lazy",read:n=>t().read(n),serializedSize:n=>t().serializedSize(n),write:(n,s)=>t().write(n,s),serialize:(n,s)=>t().serialize(n,s).toBytes()})}const c={u8(r){return nr({name:"u8",readMethod:"read8",writeMethod:"write8",size:1,maxValue:2**8-1,...r})},u16(r){return nr({name:"u16",readMethod:"read16",writeMethod:"write16",size:2,maxValue:2**16-1,...r})},u32(r){return nr({name:"u32",readMethod:"read32",writeMethod:"write32",size:4,maxValue:2**32-1,...r})},u64(r){return sr({name:"u64",readMethod:"read64",writeMethod:"write64",size:8,maxValue:2n**64n-1n,...r})},u128(r){return sr({name:"u128",readMethod:"read128",writeMethod:"write128",size:16,maxValue:2n**128n-1n,...r})},u256(r){return sr({name:"u256",readMethod:"read256",writeMethod:"write256",size:32,maxValue:2n**256n-1n,...r})},bool(r){return It({name:"bool",size:1,read:e=>e.read8()===1,write:(e,t)=>t.write8(e?1:0),...r,validate:e=>{if(r?.validate?.(e),typeof e!="boolean")throw new TypeError(`Expected boolean, found ${typeof e}`)}})},uleb128(r){return ka({name:"uleb128",read:e=>e.readULEB(),serialize:e=>Uint8Array.from(Tt(e)),...r})},bytes(r,e){return It({name:`bytes[${r}]`,size:r,read:t=>t.readBytes(r),write:(t,n)=>{const s=new Uint8Array(t);for(let a=0;a<r;a++)n.write8(s[a]??0)},...e,validate:t=>{if(e?.validate?.(t),!t||typeof t!="object"||!("length"in t))throw new TypeError(`Expected array, found ${typeof t}`);if(t.length!==r)throw new TypeError(`Expected array of length ${r}, found ${t.length}`)}})},byteVector(r){return new fe({name:"bytesVector",read:e=>{const t=e.readULEB();return e.readBytes(t)},write:(e,t)=>{const n=new Uint8Array(e);t.writeULEB(n.length);for(let s=0;s<n.length;s++)t.write8(n[s]??0)},...r,serializedSize:e=>{const t="length"in e?e.length:null;return t==null?null:Tt(t).length+t},validate:e=>{if(r?.validate?.(e),!e||typeof e!="object"||!("length"in e))throw new TypeError(`Expected array, found ${typeof e}`)}})},string(r){return Aa({name:"string",toBytes:e=>new TextEncoder().encode(e),fromBytes:e=>new TextDecoder().decode(e),...r})},fixedArray(r,e,t){return new fe({name:`${e.name}[${r}]`,read:n=>{const s=new Array(r);for(let a=0;a<r;a++)s[a]=e.read(n);return s},write:(n,s)=>{for(const a of n)e.write(a,s)},...t,validate:n=>{if(t?.validate?.(n),!n||typeof n!="object"||!("length"in n))throw new TypeError(`Expected array, found ${typeof n}`);if(n.length!==r)throw new TypeError(`Expected array of length ${r}, found ${n.length}`)}})},option(r){return c.enum(`Option<${r.name}>`,{None:null,Some:r}).transform({input:e=>e==null?{None:!0}:{Some:e},output:e=>e.$kind==="Some"?e.Some:null})},vector(r,e){return new fe({name:`vector<${r.name}>`,read:t=>{const n=t.readULEB(),s=new Array(n);for(let a=0;a<n;a++)s[a]=r.read(t);return s},write:(t,n)=>{n.writeULEB(t.length);for(const s of t)r.write(s,n)},...e,validate:t=>{if(e?.validate?.(t),!t||typeof t!="object"||!("length"in t))throw new TypeError(`Expected array, found ${typeof t}`)}})},tuple(r,e){return new fe({name:`(${r.map(t=>t.name).join(", ")})`,serializedSize:t=>{let n=0;for(let s=0;s<r.length;s++){const a=r[s].serializedSize(t[s]);if(a==null)return null;n+=a}return n},read:t=>{const n=[];for(const s of r)n.push(s.read(t));return n},write:(t,n)=>{for(let s=0;s<r.length;s++)r[s].write(t[s],n)},...e,validate:t=>{if(e?.validate?.(t),!Array.isArray(t))throw new TypeError(`Expected array, found ${typeof t}`);if(t.length!==r.length)throw new TypeError(`Expected array of length ${r.length}, found ${t.length}`)}})},struct(r,e,t){const n=Object.entries(e);return new fe({name:r,serializedSize:s=>{let a=0;for(const[i,o]of n){const u=o.serializedSize(s[i]);if(u==null)return null;a+=u}return a},read:s=>{const a={};for(const[i,o]of n)a[i]=o.read(s);return a},write:(s,a)=>{for(const[i,o]of n)o.write(s[i],a)},...t,validate:s=>{if(t?.validate?.(s),typeof s!="object"||s==null)throw new TypeError(`Expected object, found ${typeof s}`)}})},enum(r,e,t){const n=Object.entries(e);return new fe({name:r,read:s=>{const a=s.readULEB(),i=n[a];if(!i)throw new TypeError(`Unknown value ${a} for enum ${r}`);const[o,u]=i;return{[o]:u?.read(s)??!0,$kind:o}},write:(s,a)=>{const[i,o]=Object.entries(s).filter(([u])=>Object.hasOwn(e,u))[0];for(let u=0;u<n.length;u++){const[d,l]=n[u];if(d===i){a.writeULEB(u),l?.write(o,a);return}}},...t,validate:s=>{if(t?.validate?.(s),typeof s!="object"||s==null)throw new TypeError(`Expected object, found ${typeof s}`);const a=Object.keys(s).filter(o=>s[o]!==void 0&&Object.hasOwn(e,o));if(a.length!==1)throw new TypeError(`Expected object with one key, but found ${a.length} for type ${r}}`);const[i]=a;if(!Object.hasOwn(e,i))throw new TypeError(`Invalid enum variant ${i}`)}})},map(r,e){return c.vector(c.tuple([r,e])).transform({name:`Map<${r.name}, ${e.name}>`,input:t=>[...t.entries()],output:t=>{const n=new Map;for(const[s,a]of t)n.set(s,a);return n}})},lazy(r){return Ia(r)}},Xr=/^(?!.*(^(?!@)|[-.@])($|[-.@]))(?:[a-z0-9-]{0,63}(?:\.[a-z0-9-]{0,63})*)?@[a-z0-9-]{0,63}$/i,Zr=/^(?!.*(^|[-.])($|[-.]))(?:[a-z0-9-]{0,63}\.)+sui$/i,Ea=235;function Oa(r){return r.length>Ea?!1:r.includes("@")?Xr.test(r):Zr.test(r)}function Ca(r,e="at"){const t=r.toLowerCase();let n;if(t.includes("@")){if(!Xr.test(t))throw new Error(`Invalid SuiNS name ${r}`);const[s,a]=t.split("@");n=[...s?s.split("."):[],a]}else{if(!Zr.test(t))throw new Error(`Invalid SuiNS name ${r}`);n=t.split(".").slice(0,-1)}return e==="dot"?`${n.join(".")}.sui`:`${n.slice(0,-1).join(".")}@${n[n.length-1]}`}const ja=/^([a-z0-9]+(?:-[a-z0-9]+)*)$/,xa=/^\d+$/,Ma=64,en="/",Q=r=>{const e=r.split(en);if(e.length<2||e.length>3)return!1;const[t,n,s]=e;return s!==void 0&&!xa.test(s)||!Oa(t)?!1:ja.test(n)&&n.length<Ma},$a=r=>{const e=r.split(/::|<|>|,/);for(const t of e)if(t.includes(en)&&!Q(t))return!1;return!0},Pa=32;function tn(r){try{return nt(r).length===Pa}catch{return!1}}const Et=32;function ie(r){return Ra(r)&&Na(r)===Et}function Ot(r){return ie(r)}function Ua(r){return r.includes("::")?Re(r):r}function Re(r){const[e,t]=r.split("::"),n=Q(e),s=r.slice(e.length+t.length+4),a=s.includes("<")?s.slice(0,s.indexOf("<")):s,i=s.includes("<")?Hr(s.slice(s.indexOf("<")+1,s.lastIndexOf(">"))).map(o=>Ua(o.trim())):[];return{address:n?e:I(e),module:t,name:a,typeParams:i}}function Ct(r){const{address:e,module:t,name:n,typeParams:s}=typeof r=="string"?Re(r):r,a=s?.length>0?`<${s.map(i=>typeof i=="string"?i:Ct(i)).join(",")}>`:"";return`${e}::${t}::${n}${a}`}function I(r,e=!1){let t=r.toLowerCase();return!e&&t.startsWith("0x")&&(t=t.slice(2)),`0x${t.padStart(Et*2,"0")}`}function ye(r,e=!1){return I(r,e)}function Ra(r){return/^(0x|0X)?[a-fA-F0-9]+$/.test(r)&&r.length%2===0}function Na(r){return/^(0x|0X)/.test(r)?(r.length-2)/2:r.length/2}const Ba=/^vector<(.+)>$/,La=/^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/;class oe{static parseFromStr(e,t=!1){if(e==="address")return{address:null};if(e==="bool")return{bool:null};if(e==="u8")return{u8:null};if(e==="u16")return{u16:null};if(e==="u32")return{u32:null};if(e==="u64")return{u64:null};if(e==="u128")return{u128:null};if(e==="u256")return{u256:null};if(e==="signer")return{signer:null};const n=e.match(Ba);if(n)return{vector:oe.parseFromStr(n[1],t)};const s=e.match(La);if(s)return{struct:{address:t?I(s[1]):s[1],module:s[2],name:s[3],typeParams:s[5]===void 0?[]:oe.parseStructTypeArgs(s[5],t)}};throw new Error(`Encountered unexpected token when parsing type args for ${e}`)}static parseStructTypeArgs(e,t=!1){return Hr(e).map(n=>oe.parseFromStr(n,t))}static tagToString(e){if("bool"in e)return"bool";if("u8"in e)return"u8";if("u16"in e)return"u16";if("u32"in e)return"u32";if("u64"in e)return"u64";if("u128"in e)return"u128";if("u256"in e)return"u256";if("address"in e)return"address";if("signer"in e)return"signer";if("vector"in e)return`vector<${oe.tagToString(e.vector)}>`;if("struct"in e){const t=e.struct,n=t.typeParams.map(oe.tagToString).join(", ");return`${t.address}::${t.module}::${t.name}${n?`<${n}>`:""}`}throw new Error("Invalid TypeTag")}}function Va(r){return c.u64({name:"unsafe_u64",...r}).transform({input:e=>e,output:e=>Number(e)})}function Da(r){return c.enum("Option",{None:null,Some:r})}const C=c.bytes(Et).transform({validate:r=>{const e=typeof r=="string"?r:He(r);if(!e||!ie(I(e)))throw new Error(`Invalid Sui address ${e}`)},input:r=>typeof r=="string"?Gr(I(r)):r,output:r=>I(He(r))}),ce=c.vector(c.u8()).transform({name:"ObjectDigest",input:r=>nt(r),output:r=>wt(new Uint8Array(r)),validate:r=>{if(nt(r).length!==32)throw new Error("ObjectDigest must be 32 bytes")}}),te=c.struct("SuiObjectRef",{objectId:C,version:c.u64(),digest:ce}),rn=c.struct("SharedObjectRef",{objectId:C,initialSharedVersion:c.u64(),mutable:c.bool()}),nn=c.enum("ObjectArg",{ImmOrOwnedObject:te,SharedObject:rn,Receiving:te}),Ne=c.enum("Owner",{AddressOwner:C,ObjectOwner:C,Shared:c.struct("Shared",{initialSharedVersion:c.u64()}),Immutable:null,ConsensusAddressOwner:c.struct("ConsensusAddressOwner",{owner:C,startVersion:c.u64()})}),sn=c.enum("CallArg",{Pure:c.struct("Pure",{bytes:c.vector(c.u8()).transform({input:r=>typeof r=="string"?Y(r):r,output:r=>W(new Uint8Array(r))})}),Object:nn}),ar=c.enum("TypeTag",{bool:null,u8:null,u64:null,u128:null,address:null,signer:null,vector:c.lazy(()=>ar),struct:c.lazy(()=>dn),u16:null,u32:null,u256:null}),ir=ar.transform({input:r=>typeof r=="string"?oe.parseFromStr(r,!0):r,output:r=>oe.tagToString(r)}),pe=c.enum("Argument",{GasCoin:null,Input:c.u16(),Result:c.u16(),NestedResult:c.tuple([c.u16(),c.u16()])}),an=c.struct("ProgrammableMoveCall",{package:C,module:c.string(),function:c.string(),typeArguments:c.vector(ir),arguments:c.vector(pe)}),on=c.enum("Command",{MoveCall:an,TransferObjects:c.struct("TransferObjects",{objects:c.vector(pe),address:pe}),SplitCoins:c.struct("SplitCoins",{coin:pe,amounts:c.vector(pe)}),MergeCoins:c.struct("MergeCoins",{destination:pe,sources:c.vector(pe)}),Publish:c.struct("Publish",{modules:c.vector(c.vector(c.u8()).transform({input:r=>typeof r=="string"?Y(r):r,output:r=>W(new Uint8Array(r))})),dependencies:c.vector(C)}),MakeMoveVec:c.struct("MakeMoveVec",{type:Da(ir).transform({input:r=>r===null?{None:!0}:{Some:r},output:r=>r.Some??null}),elements:c.vector(pe)}),Upgrade:c.struct("Upgrade",{modules:c.vector(c.vector(c.u8()).transform({input:r=>typeof r=="string"?Y(r):r,output:r=>W(new Uint8Array(r))})),dependencies:c.vector(C),package:C,ticket:pe})}),cn=c.struct("ProgrammableTransaction",{inputs:c.vector(sn),commands:c.vector(on)}),un=c.enum("TransactionKind",{ProgrammableTransaction:cn,ChangeEpoch:null,Genesis:null,ConsensusCommitPrologue:null}),ln=c.enum("TransactionExpiration",{None:null,Epoch:Va()}),dn=c.struct("StructTag",{address:C,module:c.string(),name:c.string(),typeParams:c.vector(ar)}),fn=c.struct("GasData",{payment:c.vector(te),owner:C,price:c.u64(),budget:c.u64()}),pn=c.struct("TransactionDataV1",{kind:un,sender:C,gasData:fn,expiration:ln}),hn=c.enum("TransactionData",{V1:pn}),bn=c.enum("IntentScope",{TransactionData:null,TransactionEffects:null,CheckpointSummary:null,PersonalMessage:null}),mn=c.enum("IntentVersion",{V0:null}),yn=c.enum("AppId",{Sui:null}),gn=c.struct("Intent",{scope:bn,version:mn,appId:yn});function vn(r){return c.struct(`IntentMessage<${r.name}>`,{intent:gn,value:r})}const wn=c.enum("CompressedSignature",{ED25519:c.fixedArray(64,c.u8()),Secp256k1:c.fixedArray(64,c.u8()),Secp256r1:c.fixedArray(64,c.u8()),ZkLogin:c.vector(c.u8())}),_n=c.enum("PublicKey",{ED25519:c.fixedArray(32,c.u8()),Secp256k1:c.fixedArray(33,c.u8()),Secp256r1:c.fixedArray(33,c.u8()),ZkLogin:c.vector(c.u8())}),Tn=c.struct("MultiSigPkMap",{pubKey:_n,weight:c.u8()}),Sn=c.struct("MultiSigPublicKey",{pk_map:c.vector(Tn),threshold:c.u16()}),za=c.struct("MultiSig",{sigs:c.vector(wn),bitmap:c.u16(),multisig_pk:Sn}),Wa=c.vector(c.u8()).transform({input:r=>typeof r=="string"?Y(r):r,output:r=>W(new Uint8Array(r))}),kn=c.struct("SenderSignedTransaction",{intentMessage:vn(hn),txSignatures:c.vector(Wa)}),Fa=c.vector(kn,{name:"SenderSignedData"}),Ga=c.struct("PasskeyAuthenticator",{authenticatorData:c.vector(c.u8()),clientDataJson:c.string(),userSignature:c.vector(c.u8())}),qa=c.enum("PackageUpgradeError",{UnableToFetchPackage:c.struct("UnableToFetchPackage",{packageId:C}),NotAPackage:c.struct("NotAPackage",{objectId:C}),IncompatibleUpgrade:null,DigestDoesNotMatch:c.struct("DigestDoesNotMatch",{digest:c.vector(c.u8())}),UnknownUpgradePolicy:c.struct("UnknownUpgradePolicy",{policy:c.u8()}),PackageIDDoesNotMatch:c.struct("PackageIDDoesNotMatch",{packageId:C,ticketId:C})}),Ka=c.struct("ModuleId",{address:C,name:c.string()}),An=c.struct("MoveLocation",{module:Ka,function:c.u16(),instruction:c.u16(),functionName:c.option(c.string())}),Ha=c.enum("CommandArgumentError",{TypeMismatch:null,InvalidBCSBytes:null,InvalidUsageOfPureArg:null,InvalidArgumentToPrivateEntryFunction:null,IndexOutOfBounds:c.struct("IndexOutOfBounds",{idx:c.u16()}),SecondaryIndexOutOfBounds:c.struct("SecondaryIndexOutOfBounds",{resultIdx:c.u16(),secondaryIdx:c.u16()}),InvalidResultArity:c.struct("InvalidResultArity",{resultIdx:c.u16()}),InvalidGasCoinUsage:null,InvalidValueUsage:null,InvalidObjectByValue:null,InvalidObjectByMutRef:null,SharedObjectOperationNotAllowed:null}),Ja=c.enum("TypeArgumentError",{TypeNotFound:null,ConstraintNotSatisfied:null}),Ya=c.enum("ExecutionFailureStatus",{InsufficientGas:null,InvalidGasObject:null,InvariantViolation:null,FeatureNotYetSupported:null,MoveObjectTooBig:c.struct("MoveObjectTooBig",{objectSize:c.u64(),maxObjectSize:c.u64()}),MovePackageTooBig:c.struct("MovePackageTooBig",{objectSize:c.u64(),maxObjectSize:c.u64()}),CircularObjectOwnership:c.struct("CircularObjectOwnership",{object:C}),InsufficientCoinBalance:null,CoinBalanceOverflow:null,PublishErrorNonZeroAddress:null,SuiMoveVerificationError:null,MovePrimitiveRuntimeError:c.option(An),MoveAbort:c.tuple([An,c.u64()]),VMVerificationOrDeserializationError:null,VMInvariantViolation:null,FunctionNotFound:null,ArityMismatch:null,TypeArityMismatch:null,NonEntryFunctionInvoked:null,CommandArgumentError:c.struct("CommandArgumentError",{argIdx:c.u16(),kind:Ha}),TypeArgumentError:c.struct("TypeArgumentError",{argumentIdx:c.u16(),kind:Ja}),UnusedValueWithoutDrop:c.struct("UnusedValueWithoutDrop",{resultIdx:c.u16(),secondaryIdx:c.u16()}),InvalidPublicFunctionReturnType:c.struct("InvalidPublicFunctionReturnType",{idx:c.u16()}),InvalidTransferObject:null,EffectsTooLarge:c.struct("EffectsTooLarge",{currentSize:c.u64(),maxSize:c.u64()}),PublishUpgradeMissingDependency:null,PublishUpgradeDependencyDowngrade:null,PackageUpgradeError:c.struct("PackageUpgradeError",{upgradeError:qa}),WrittenObjectsTooLarge:c.struct("WrittenObjectsTooLarge",{currentSize:c.u64(),maxSize:c.u64()}),CertificateDenied:null,SuiMoveVerificationTimedout:null,SharedObjectOperationNotAllowed:null,InputObjectDeleted:null,ExecutionCancelledDueToSharedObjectCongestion:c.struct("ExecutionCancelledDueToSharedObjectCongestion",{congestedObjects:c.vector(C)}),AddressDeniedForCoin:c.struct("AddressDeniedForCoin",{address:C,coinType:c.string()}),CoinTypeGlobalPause:c.struct("CoinTypeGlobalPause",{coinType:c.string()}),ExecutionCancelledDueToRandomnessUnavailable:null}),In=c.enum("ExecutionStatus",{Success:null,Failed:c.struct("ExecutionFailed",{error:Ya,command:c.option(c.u64())})}),En=c.struct("GasCostSummary",{computationCost:c.u64(),storageCost:c.u64(),storageRebate:c.u64(),nonRefundableStorageFee:c.u64()}),Qa=c.struct("TransactionEffectsV1",{status:In,executedEpoch:c.u64(),gasUsed:En,modifiedAtVersions:c.vector(c.tuple([C,c.u64()])),sharedObjects:c.vector(te),transactionDigest:ce,created:c.vector(c.tuple([te,Ne])),mutated:c.vector(c.tuple([te,Ne])),unwrapped:c.vector(c.tuple([te,Ne])),deleted:c.vector(te),unwrappedThenDeleted:c.vector(te),wrapped:c.vector(te),gasObject:c.tuple([te,Ne]),eventsDigest:c.option(ce),dependencies:c.vector(ce)}),or=c.tuple([c.u64(),ce]),Xa=c.enum("ObjectIn",{NotExist:null,Exist:c.tuple([or,Ne])}),Za=c.enum("ObjectOut",{NotExist:null,ObjectWrite:c.tuple([ce,Ne]),PackageWrite:or}),ei=c.enum("IDOperation",{None:null,Created:null,Deleted:null}),ti=c.struct("EffectsObjectChange",{inputState:Xa,outputState:Za,idOperation:ei}),ri=c.enum("UnchangedSharedKind",{ReadOnlyRoot:or,MutateDeleted:c.u64(),ReadDeleted:c.u64(),Cancelled:c.u64(),PerEpochConfig:null}),ni=c.struct("TransactionEffectsV2",{status:In,executedEpoch:c.u64(),gasUsed:En,transactionDigest:ce,gasObjectIndex:c.option(c.u32()),eventsDigest:c.option(ce),dependencies:c.vector(ce),lamportVersion:c.u64(),changedObjects:c.vector(c.tuple([C,ti])),unchangedSharedObjects:c.vector(c.tuple([C,ri])),auxDataDigest:c.option(ce)}),si=c.enum("TransactionEffects",{V1:Qa,V2:ni});function at(r){switch(r){case"u8":return c.u8();case"u16":return c.u16();case"u32":return c.u32();case"u64":return c.u64();case"u128":return c.u128();case"u256":return c.u256();case"bool":return c.bool();case"string":return c.string();case"id":case"address":return C}const e=r.match(/^(vector|option)<(.+)>$/);if(e){const[t,n]=e.slice(1);return t==="vector"?c.vector(at(n)):c.option(at(n))}throw new Error(`Invalid Pure type name: ${r}`)}const T={...c,U8:c.u8(),U16:c.u16(),U32:c.u32(),U64:c.u64(),U128:c.u128(),U256:c.u256(),ULEB128:c.uleb128(),Bool:c.bool(),String:c.string(),Address:C,AppId:yn,Argument:pe,CallArg:sn,Command:on,CompressedSignature:wn,GasData:fn,Intent:gn,IntentMessage:vn,IntentScope:bn,IntentVersion:mn,MultiSig:za,MultiSigPkMap:Tn,MultiSigPublicKey:Sn,ObjectArg:nn,ObjectDigest:ce,Owner:Ne,PasskeyAuthenticator:Ga,ProgrammableMoveCall:an,ProgrammableTransaction:cn,PublicKey:_n,SenderSignedData:Fa,SenderSignedTransaction:kn,SharedObjectRef:rn,StructTag:dn,SuiObjectRef:te,TransactionData:hn,TransactionDataV1:pn,TransactionEffects:si,TransactionExpiration:ln,TransactionKind:un,TypeTag:ir};BigInt(1e9);const ai="0x1",On="0x2";ye("0x6");const ii=`${On}::sui::SUI`;ye("0x5");/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function oi(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function cr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function ur(r,...e){if(!oi(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error("Uint8Array expected of length "+e+", got length="+r.length)}function Cn(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function ci(r,e){ur(r);const t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function jt(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function lr(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}const jn=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function xn(r){return r<<24&4278190080|r<<8&16711680|r>>>8&65280|r>>>24&255}const ge=jn?r=>r:r=>xn(r);function ui(r){for(let e=0;e<r.length;e++)r[e]=xn(r[e]);return r}const Ye=jn?r=>r:ui;function li(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function it(r){return typeof r=="string"&&(r=li(r)),ur(r),r}class di{}function fi(r){const e=(n,s)=>r(s).update(it(n)).digest(),t=r({});return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}const pi=Uint8Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9]),xt=BigInt(2**32-1),Mn=BigInt(32);function hi(r,e=!1){return e?{h:Number(r&xt),l:Number(r>>Mn&xt)}:{h:Number(r>>Mn&xt)|0,l:Number(r&xt)|0}}const $n=(r,e,t)=>r>>>t|e<<32-t,Pn=(r,e,t)=>r<<32-t|e>>>t,bi=(r,e,t)=>r<<64-t|e>>>t-32,mi=(r,e,t)=>r>>>t-32|e<<64-t,yi=(r,e)=>e,gi=(r,e)=>r;function Un(r,e,t,n){const s=(e>>>0)+(n>>>0);return{h:r+t+(s/2**32|0)|0,l:s|0}}const Rn=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Nn=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,N=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),m=new Uint32Array(32);function Ce(r,e,t,n,s,a){const i=s[a],o=s[a+1];let u=m[2*r],d=m[2*r+1],l=m[2*e],f=m[2*e+1],p=m[2*t],v=m[2*t+1],y=m[2*n],g=m[2*n+1],U=Rn(u,l,i);d=Nn(U,d,f,o),u=U|0,{Dh:g,Dl:y}={Dh:g^d,Dl:y^u},{Dh:g,Dl:y}={Dh:yi(g,y),Dl:gi(g)},{h:v,l:p}=Un(v,p,g,y),{Bh:f,Bl:l}={Bh:f^v,Bl:l^p},{Bh:f,Bl:l}={Bh:$n(f,l,24),Bl:Pn(f,l,24)},m[2*r]=u,m[2*r+1]=d,m[2*e]=l,m[2*e+1]=f,m[2*t]=p,m[2*t+1]=v,m[2*n]=y,m[2*n+1]=g}function je(r,e,t,n,s,a){const i=s[a],o=s[a+1];let u=m[2*r],d=m[2*r+1],l=m[2*e],f=m[2*e+1],p=m[2*t],v=m[2*t+1],y=m[2*n],g=m[2*n+1],U=Rn(u,l,i);d=Nn(U,d,f,o),u=U|0,{Dh:g,Dl:y}={Dh:g^d,Dl:y^u},{Dh:g,Dl:y}={Dh:$n(g,y,16),Dl:Pn(g,y,16)},{h:v,l:p}=Un(v,p,g,y),{Bh:f,Bl:l}={Bh:f^v,Bl:l^p},{Bh:f,Bl:l}={Bh:bi(f,l,63),Bl:mi(f,l,63)},m[2*r]=u,m[2*r+1]=d,m[2*e]=l,m[2*e+1]=f,m[2*t]=p,m[2*t+1]=v,m[2*n]=y,m[2*n+1]=g}function vi(r,e={},t,n,s){if(cr(t),r<0||r>t)throw new Error("outputLen bigger than keyLen");const{key:a,salt:i,personalization:o}=e;if(a!==void 0&&(a.length<1||a.length>t))throw new Error("key length must be undefined or 1.."+t);if(i!==void 0&&i.length!==n)throw new Error("salt must be undefined or "+n);if(o!==void 0&&o.length!==s)throw new Error("personalization must be undefined or "+s)}class wi extends di{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,cr(e),cr(t),this.blockLen=e,this.outputLen=t,this.buffer=new Uint8Array(e),this.buffer32=jt(this.buffer)}update(e){Cn(this),e=it(e),ur(e);const{blockLen:t,buffer:n,buffer32:s}=this,a=e.length,i=e.byteOffset,o=e.buffer;for(let u=0;u<a;){this.pos===t&&(Ye(s),this.compress(s,0,!1),Ye(s),this.pos=0);const d=Math.min(t-this.pos,a-u),l=i+u;if(d===t&&!(l%4)&&u+d<a){const f=new Uint32Array(o,l,Math.floor((a-u)/4));Ye(f);for(let p=0;u+t<a;p+=s.length,u+=t)this.length+=t,this.compress(f,p,!1);Ye(f);continue}n.set(e.subarray(u,u+d),this.pos),this.pos+=d,this.length+=d,u+=d}return this}digestInto(e){Cn(this),ci(e,this);const{pos:t,buffer32:n}=this;this.finished=!0,lr(this.buffer.subarray(t)),Ye(n),this.compress(n,0,!0),Ye(n);const s=jt(e);this.get().forEach((a,i)=>s[i]=ge(a))}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){const{buffer:t,length:n,finished:s,destroyed:a,outputLen:i,pos:o}=this;return e||(e=new this.constructor({dkLen:i})),e.set(...this.get()),e.buffer.set(t),e.destroyed=a,e.finished=s,e.length=n,e.pos=o,e.outputLen=i,e}clone(){return this._cloneInto()}}class _i extends wi{constructor(e={}){const t=e.dkLen===void 0?64:e.dkLen;super(128,t),this.v0l=N[0]|0,this.v0h=N[1]|0,this.v1l=N[2]|0,this.v1h=N[3]|0,this.v2l=N[4]|0,this.v2h=N[5]|0,this.v3l=N[6]|0,this.v3h=N[7]|0,this.v4l=N[8]|0,this.v4h=N[9]|0,this.v5l=N[10]|0,this.v5h=N[11]|0,this.v6l=N[12]|0,this.v6h=N[13]|0,this.v7l=N[14]|0,this.v7h=N[15]|0,vi(t,e,64,16,16);let{key:n,personalization:s,salt:a}=e,i=0;if(n!==void 0&&(n=it(n),i=n.length),this.v0l^=this.outputLen|i<<8|65536|1<<24,a!==void 0){a=it(a);const o=jt(a);this.v4l^=ge(o[0]),this.v4h^=ge(o[1]),this.v5l^=ge(o[2]),this.v5h^=ge(o[3])}if(s!==void 0){s=it(s);const o=jt(s);this.v6l^=ge(o[0]),this.v6h^=ge(o[1]),this.v7l^=ge(o[2]),this.v7h^=ge(o[3])}if(n!==void 0){const o=new Uint8Array(this.blockLen);o.set(n),this.update(o)}}get(){let{v0l:e,v0h:t,v1l:n,v1h:s,v2l:a,v2h:i,v3l:o,v3h:u,v4l:d,v4h:l,v5l:f,v5h:p,v6l:v,v6h:y,v7l:g,v7h:U}=this;return[e,t,n,s,a,i,o,u,d,l,f,p,v,y,g,U]}set(e,t,n,s,a,i,o,u,d,l,f,p,v,y,g,U){this.v0l=e|0,this.v0h=t|0,this.v1l=n|0,this.v1h=s|0,this.v2l=a|0,this.v2h=i|0,this.v3l=o|0,this.v3h=u|0,this.v4l=d|0,this.v4h=l|0,this.v5l=f|0,this.v5h=p|0,this.v6l=v|0,this.v6h=y|0,this.v7l=g|0,this.v7h=U|0}compress(e,t,n){this.get().forEach((u,d)=>m[d]=u),m.set(N,16);let{h:s,l:a}=hi(BigInt(this.length));m[24]=N[8]^a,m[25]=N[9]^s,n&&(m[28]=~m[28],m[29]=~m[29]);let i=0;const o=pi;for(let u=0;u<12;u++)Ce(0,4,8,12,e,t+2*o[i++]),je(0,4,8,12,e,t+2*o[i++]),Ce(1,5,9,13,e,t+2*o[i++]),je(1,5,9,13,e,t+2*o[i++]),Ce(2,6,10,14,e,t+2*o[i++]),je(2,6,10,14,e,t+2*o[i++]),Ce(3,7,11,15,e,t+2*o[i++]),je(3,7,11,15,e,t+2*o[i++]),Ce(0,5,10,15,e,t+2*o[i++]),je(0,5,10,15,e,t+2*o[i++]),Ce(1,6,11,12,e,t+2*o[i++]),je(1,6,11,12,e,t+2*o[i++]),Ce(2,7,8,13,e,t+2*o[i++]),je(2,7,8,13,e,t+2*o[i++]),Ce(3,4,9,14,e,t+2*o[i++]),je(3,4,9,14,e,t+2*o[i++]);this.v0l^=m[0]^m[16],this.v0h^=m[1]^m[17],this.v1l^=m[2]^m[18],this.v1h^=m[3]^m[19],this.v2l^=m[4]^m[20],this.v2h^=m[5]^m[21],this.v3l^=m[6]^m[22],this.v3h^=m[7]^m[23],this.v4l^=m[8]^m[24],this.v4h^=m[9]^m[25],this.v5l^=m[10]^m[26],this.v5h^=m[11]^m[27],this.v6l^=m[12]^m[28],this.v6h^=m[13]^m[29],this.v7l^=m[14]^m[30],this.v7h^=m[15]^m[31],lr(m)}destroy(){this.destroyed=!0,lr(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const Bn=fi(r=>new _i(r));function Ti(r,e,t){const n=T.Address.serialize(r).toBytes(),s=T.TypeTag.serialize(e).toBytes(),a=T.u64().serialize(t.length).toBytes(),i=Bn.create({dkLen:32});return i.update(new Uint8Array([240])),i.update(n),i.update(a),i.update(t),i.update(s),`0x${He(i.digest().slice(0,32))}`}const Si="object",ki="ID",Ai="ascii",Ii="String",Ei="string",Oi="String",Ci="option",ji="Option";function xi(r){const e=typeof r.body=="object"&&"datatype"in r.body?r.body.datatype:null;return!!e&&I(e.package)===I("0x2")&&e.module==="tx_context"&&e.type==="TxContext"}function dr(r){if(typeof r=="string")switch(r){case"address":return T.Address;case"bool":return T.Bool;case"u8":return T.U8;case"u16":return T.U16;case"u32":return T.U32;case"u64":return T.U64;case"u128":return T.U128;case"u256":return T.U256;default:throw new Error(`Unknown type signature ${r}`)}if("vector"in r){if(r.vector==="u8")return T.vector(T.U8).transform({input:t=>typeof t=="string"?new TextEncoder().encode(t):t,output:t=>t});const e=dr(r.vector);return e?T.vector(e):null}if("datatype"in r){const e=I(r.datatype.package);if(e===I(ai)){if(r.datatype.module===Ai&&r.datatype.type===Ii||r.datatype.module===Ei&&r.datatype.type===Oi)return T.String;if(r.datatype.module===Ci&&r.datatype.type===ji){const t=dr(r.datatype.typeParameters[0]);return t?T.vector(t):null}}if(e===I(On)&&r.datatype.module===Si&&r.datatype.type===ki)return T.Address}return null}function Mi(r){return typeof r=="object"&&"Reference"in r?{ref:"&",body:ot(r.Reference)}:typeof r=="object"&&"MutableReference"in r?{ref:"&mut",body:ot(r.MutableReference)}:{ref:null,body:ot(r)}}function ot(r){if(typeof r=="string")switch(r){case"Address":return"address";case"Bool":return"bool";case"U8":return"u8";case"U16":return"u16";case"U32":return"u32";case"U64":return"u64";case"U128":return"u128";case"U256":return"u256";default:throw new Error(`Unexpected type ${r}`)}if("Vector"in r)return{vector:ot(r.Vector)};if("Struct"in r)return{datatype:{package:r.Struct.address,module:r.Struct.module,type:r.Struct.name,typeParameters:r.Struct.typeArguments.map(ot)}};if("TypeParameter"in r)return{typeParameter:r.TypeParameter};throw new Error(`Unexpected type ${JSON.stringify(r)}`)}function $i(r){return{$kind:"Pure",Pure:{bytes:r instanceof Uint8Array?W(r):r.toBase64()}}}const ve={Pure:$i,ObjectRef({objectId:r,digest:e,version:t}){return{$kind:"Object",Object:{$kind:"ImmOrOwnedObject",ImmOrOwnedObject:{digest:e,version:t,objectId:I(r)}}}},SharedObjectRef({objectId:r,mutable:e,initialSharedVersion:t}){return{$kind:"Object",Object:{$kind:"SharedObject",SharedObject:{mutable:e,initialSharedVersion:t,objectId:I(r)}}}},ReceivingRef({objectId:r,digest:e,version:t}){return{$kind:"Object",Object:{$kind:"Receiving",Receiving:{digest:e,version:t,objectId:I(r)}}}}};var fr;function Pi(r){return{lang:r?.lang??fr?.lang,message:r?.message,abortEarly:r?.abortEarly??fr?.abortEarly,abortPipeEarly:r?.abortPipeEarly??fr?.abortPipeEarly}}var Ui;function Ri(r){return Ui?.get(r)}var Ni;function Bi(r){return Ni?.get(r)}var Li;function Vi(r,e){return Li?.get(r)?.get(e)}function Ln(r){const e=typeof r;return e==="string"?`"${r}"`:e==="number"||e==="bigint"||e==="boolean"?`${r}`:e==="object"||e==="function"?(r&&Object.getPrototypeOf(r)?.constructor?.name)??"null":e}function X(r,e,t,n,s){const a=s&&"input"in s?s.input:t.value,i=s?.expected??r.expects??null,o=s?.received??Ln(a),u={kind:r.kind,type:r.type,input:a,expected:i,received:o,message:`Invalid ${e}: ${i?`Expected ${i} but r`:"R"}eceived ${o}`,requirement:r.requirement,path:s?.path,issues:s?.issues,lang:n.lang,abortEarly:n.abortEarly,abortPipeEarly:n.abortPipeEarly},d=r.kind==="schema",l=s?.message??r.message??Vi(r.reference,u.lang)??(d?Bi(u.lang):null)??n.message??Ri(u.lang);l&&(u.message=typeof l=="function"?l(u):l),d&&(t.typed=!1),t.issues?t.issues.push(u):t.issues=[u]}function Di(r,e){return Object.hasOwn(r,e)&&e!=="__proto__"&&e!=="prototype"&&e!=="constructor"}var zi=class extends Error{issues;constructor(r){super(r[0].message),this.name="ValiError",this.issues=r}};function ct(r,e){return{kind:"validation",type:"check",reference:ct,async:!1,expects:null,requirement:r,message:e,_run(t,n){return t.typed&&!this.requirement(t.value)&&X(this,"input",t,n),t}}}function $(r){return{kind:"validation",type:"integer",reference:$,async:!1,expects:null,requirement:Number.isInteger,message:r,_run(e,t){return e.typed&&!this.requirement(e.value)&&X(this,"integer",e,t),e}}}function Mt(r){return{kind:"transformation",type:"transform",reference:Mt,async:!1,operation:r,_run(e){return e.value=this.operation(e.value),e}}}function pr(r,e,t){return typeof r.default=="function"?r.default(e,t):r.default}function hr(r,e){return!r._run({typed:!1,value:e},{abortEarly:!0}).issues}function _(r,e){return{kind:"schema",type:"array",reference:_,expects:"Array",async:!1,item:r,message:e,_run(t,n){const s=t.value;if(Array.isArray(s)){t.typed=!0,t.value=[];for(let a=0;a<s.length;a++){const i=s[a],o=this.item._run({typed:!1,value:i},n);if(o.issues){const u={type:"array",origin:"value",input:s,key:a,value:i};for(const d of o.issues)d.path?d.path.unshift(u):d.path=[u],t.issues?.push(d);if(t.issues||(t.issues=o.issues),n.abortEarly){t.typed=!1;break}}o.typed||(t.typed=!1),t.value.push(o.value)}}else X(this,"type",t,n);return t}}}function br(r){return{kind:"schema",type:"bigint",reference:br,expects:"bigint",async:!1,message:r,_run(e,t){return typeof e.value=="bigint"?e.typed=!0:X(this,"type",e,t),e}}}function $t(r){return{kind:"schema",type:"boolean",reference:$t,expects:"boolean",async:!1,message:r,_run(e,t){return typeof e.value=="boolean"?e.typed=!0:X(this,"type",e,t),e}}}function ut(r){return{kind:"schema",type:"lazy",reference:ut,expects:"unknown",async:!1,getter:r,_run(e,t){return this.getter(e.value)._run(e,t)}}}function S(r,e){return{kind:"schema",type:"literal",reference:S,expects:Ln(r),async:!1,literal:r,message:e,_run(t,n){return t.value===this.literal?t.typed=!0:X(this,"type",t,n),t}}}function A(r,...e){const t={kind:"schema",type:"nullable",reference:A,expects:`${r.expects} | null`,async:!1,wrapped:r,_run(n,s){return n.value===null&&("default"in this&&(n.value=pr(this,n,s)),n.value===null)?(n.typed=!0,n):this.wrapped._run(n,s)}};return 0 in e&&(t.default=e[0]),t}function Qe(r,...e){const t={kind:"schema",type:"nullish",reference:Qe,expects:`${r.expects} | null | undefined`,async:!1,wrapped:r,_run(n,s){return(n.value===null||n.value===void 0)&&("default"in this&&(n.value=pr(this,n,s)),n.value===null||n.value===void 0)?(n.typed=!0,n):this.wrapped._run(n,s)}};return 0 in e&&(t.default=e[0]),t}function M(r){return{kind:"schema",type:"number",reference:M,expects:"number",async:!1,message:r,_run(e,t){return typeof e.value=="number"&&!isNaN(e.value)?e.typed=!0:X(this,"type",e,t),e}}}function b(r,e){return{kind:"schema",type:"object",reference:b,expects:"Object",async:!1,entries:r,message:e,_run(t,n){const s=t.value;if(s&&typeof s=="object"){t.typed=!0,t.value={};for(const a in this.entries){const i=s[a],o=this.entries[a]._run({typed:!1,value:i},n);if(o.issues){const u={type:"object",origin:"value",input:s,key:a,value:i};for(const d of o.issues)d.path?d.path.unshift(u):d.path=[u],t.issues?.push(d);if(t.issues||(t.issues=o.issues),n.abortEarly){t.typed=!1;break}}o.typed||(t.typed=!1),(o.value!==void 0||a in s)&&(t.value[a]=o.value)}}else X(this,"type",t,n);return t}}}function D(r,...e){const t={kind:"schema",type:"optional",reference:D,expects:`${r.expects} | undefined`,async:!1,wrapped:r,_run(n,s){return n.value===void 0&&("default"in this&&(n.value=pr(this,n,s)),n.value===void 0)?(n.typed=!0,n):this.wrapped._run(n,s)}};return 0 in e&&(t.default=e[0]),t}function lt(r,e,t){return{kind:"schema",type:"record",reference:lt,expects:"Object",async:!1,key:r,value:e,message:t,_run(n,s){const a=n.value;if(a&&typeof a=="object"){n.typed=!0,n.value={};for(const i in a)if(Di(a,i)){const o=a[i],u=this.key._run({typed:!1,value:i},s);if(u.issues){const l={type:"object",origin:"key",input:a,key:i,value:o};for(const f of u.issues)f.path=[l],n.issues?.push(f);if(n.issues||(n.issues=u.issues),s.abortEarly){n.typed=!1;break}}const d=this.value._run({typed:!1,value:o},s);if(d.issues){const l={type:"object",origin:"value",input:a,key:i,value:o};for(const f of d.issues)f.path?f.path.unshift(l):f.path=[l],n.issues?.push(f);if(n.issues||(n.issues=d.issues),s.abortEarly){n.typed=!1;break}}(!u.typed||!d.typed)&&(n.typed=!1),u.typed&&(n.value[u.value]=d.value)}}else X(this,"type",n,s);return n}}}function k(r){return{kind:"schema",type:"string",reference:k,expects:"string",async:!1,message:r,_run(e,t){return typeof e.value=="string"?e.typed=!0:X(this,"type",e,t),e}}}function mr(r,e){return{kind:"schema",type:"tuple",reference:mr,expects:"Array",async:!1,items:r,message:e,_run(t,n){const s=t.value;if(Array.isArray(s)){t.typed=!0,t.value=[];for(let a=0;a<this.items.length;a++){const i=s[a],o=this.items[a]._run({typed:!1,value:i},n);if(o.issues){const u={type:"array",origin:"value",input:s,key:a,value:i};for(const d of o.issues)d.path?d.path.unshift(u):d.path=[u],t.issues?.push(d);if(t.issues||(t.issues=o.issues),n.abortEarly){t.typed=!1;break}}o.typed||(t.typed=!1),t.value.push(o.value)}}else X(this,"type",t,n);return t}}}function Vn(r){let e;if(r)for(const t of r)e?e.push(...t.issues):e=t.issues;return e}function z(r,e){return{kind:"schema",type:"union",reference:z,expects:[...new Set(r.map(t=>t.expects))].join(" | ")||"never",async:!1,options:r,message:e,_run(t,n){let s,a,i;for(const o of this.options){const u=o._run({typed:!1,value:t.value},n);if(u.typed)if(u.issues)a?a.push(u):a=[u];else{s=u;break}else i?i.push(u):i=[u]}if(s)return s;if(a){if(a.length===1)return a[0];X(this,"type",t,n,{issues:Vn(a)}),t.typed=!0}else{if(i?.length===1)return i[0];X(this,"type",t,n,{issues:Vn(i)})}return t}}}function Be(){return{kind:"schema",type:"unknown",reference:Be,expects:"unknown",async:!1,_run(r){return r.typed=!0,r}}}function P(r,e,t){const n=r._run({typed:!1,value:e},Pi(t));if(n.issues)throw new zi(n.issues);return n.value}function E(...r){return{...r[0],pipe:r,_run(e,t){for(let n=0;n<r.length;n++){if(e.issues&&(r[n].kind==="schema"||r[n].kind==="transformation")){e.typed=!1;break}(!e.issues||!t.abortEarly&&!t.abortPipeEarly)&&(e=r[n]._run(e,t))}return e}}}function Le(r){const e=Object.entries(r).map(([t,n])=>b({[t]:n}));return E(z(e),Mt(t=>({...t,$kind:Object.keys(t)[0]})))}const Xe=E(k()