@greymass/eosio
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -1,2 +0,2 @@ | ||
import t from"bn.js";import{rand as e,ec as r}from"elliptic";import{sha256 as o,sha512 as i,ripemd160 as n}from"hash.js";class s{constructor(t,e={}){if((t=t.trim()).endsWith("/")&&(t=t.slice(0,-1)),this.url=t,e.fetch)this.fetch=e.fetch;else if("undefined"!=typeof window&&window.fetch)this.fetch=window.fetch.bind(window);else{if("undefined"==typeof global||!global.fetch)throw new Error("Missing fetch");this.fetch=global.fetch.bind(global)}}async call(t,e){const r=this.url+t,o=await this.fetch(r,{method:"POST",body:void 0!==e?JSON.stringify(e):void 0});try{return o.json()}catch(t){if(!o.ok)throw Error(`HTTP ${o.status}: ${o.statusText}`);throw t.message="Unable to parse JSON response from server: "+t.message,t}}}function a(t,e){const r=t.length;if(r!==e.length)return!1;for(let o=0;o<r;o++)if(t[o]!==e[o])return!1;return!0}const c={};function u(){c.enc=new Array(255),c.dec={};for(let t=0;t<=255;++t){const e=t.toString(16).padStart(2,"0");c.enc[t]=e,c.dec[e]=t}}function d(t){c.enc||u();const e=t.length,r=new Array(e);for(let o=0;o<e;++o)r[o]=c.enc[t[o]];return r.join("")}function l(t){return e(t)}class p{constructor(t){if(!Number.isFinite(t))throw new Error("Invalid number");var e;this.value=(e=this.constructor.max,Math.min(Math.max(t,this.constructor.min),e))}static get max(){return Math.pow(2,8*this.byteWidth-(this.isSigned?1:0))-1}static get min(){return this.isSigned?-(this.max+1):0}static from(e){if(e instanceof this)return e;if("string"==typeof e?e=Number.parseInt(e,10):e instanceof f?e=e.value.toNumber():e instanceof p?e=e.value:t.isBN(e)&&(e=e.toNumber()),"number"!=typeof e)throw new Error("Invalid integer");return new this(e)}static fromABI(t){return new this(t.readNum(this.byteWidth,this.isSigned))}static random(){const t=l(this.byteWidth),e=new mt(t);return this.fromABI(e)}equals(t){return this.value===this.constructor.from(t).value}toABI(t){const e=this.constructor;t.writeNum(this.value,e.byteWidth,e.isSigned)}toNumber(){return this.value}toString(){return this.value.toFixed(0)}toJSON(){return this.value}}class f{constructor(t){const e=this.constructor;if(t.byteLength()>e.byteWidth)throw new Error("Number too wide");this.value=t}static from(e){return e instanceof this?e:e instanceof f?new this(e.value):e instanceof Uint8Array?new this(new t(e,void 0,"le")):(e instanceof p&&(e=e.value),new this(new t(e)))}static fromABI(t){return new this(t.readBn(this.byteWidth,this.isSigned))}static random(){const t=l(this.byteWidth),e=new mt(t);return this.fromABI(e)}equals(t,e=!1){const r=this.constructor;return!(!e&&"number"==typeof t.constructor.byteWidth&&t.constructor.byteWidth!==r.byteWidth)&&this.value.eq(r.from(t).value)}toABI(t){const e=this.constructor;t.writeBn(this.value,e.byteWidth,e.isSigned)}toNumber(){return this.value.toNumber()}toString(){return this.value.toString()}toJSON(){return this.value.bitLength()>32?this.value.toString():this.value.toNumber()}}class h extends p{static from(t){return super.from(t)}}h.abiName="int8",h.byteWidth=1,h.isSigned=!0;class y extends p{static from(t){return super.from(t)}}y.abiName="int16",y.byteWidth=2,y.isSigned=!0;class m extends p{static from(t){return super.from(t)}}m.abiName="int32",m.byteWidth=4,m.isSigned=!0;class v extends f{static from(t){return super.from(t)}}v.abiName="int64",v.byteWidth=8,v.isSigned=!0;class g extends f{static from(t){return super.from(t)}}g.abiName="int128",g.byteWidth=16,g.isSigned=!0;class w extends p{static from(t){return super.from(t)}}w.abiName="uint8",w.byteWidth=1,w.isSigned=!1;class b extends p{static from(t){return super.from(t)}}b.abiName="uint16",b.byteWidth=2,b.isSigned=!1;class _ extends p{static from(t){return super.from(t)}}_.abiName="uint32",_.byteWidth=4,_.isSigned=!1;class A extends f{static from(t){return super.from(t)}}A.abiName="uint64",A.byteWidth=8,A.isSigned=!1;class x extends f{static from(t){return super.from(t)}}x.abiName="uint128",x.byteWidth=16,x.isSigned=!1;class k extends p{static from(t){return super.from(t)}static fromABI(t){return new this(t.readVarint32())}toABI(t){t.writeVarint32(this.value)}}k.abiName="varint32",k.byteWidth=32,k.isSigned=!0;class S extends p{static from(t){return super.from(t)}static fromABI(t){return new this(t.readVaruint32())}toABI(t){t.writeVaruint32(this.value)}}S.abiName="varuint32",S.byteWidth=32,S.isSigned=!1;class I{constructor(t){this.rawValue=t}static from(t){if(t instanceof I)return t;if("string"==typeof t)return new I(function(t){function e(t){return t>="a".charCodeAt(0)&&t<="z".charCodeAt(0)?t-"a".charCodeAt(0)+6:t>="1".charCodeAt(0)&&t<="5".charCodeAt(0)?t-"1".charCodeAt(0)+1:0}const r=new Uint8Array(8);let o=63;for(let i=0;i<t.length;++i){let n=e(t.charCodeAt(i));o<5&&(n<<=1);for(let t=4;t>=0;--t)o>=0&&(r[Math.floor(o/8)]|=(n>>t&1)<<o%8,--o)}return A.from(r)}(t));if(t instanceof A)return new I(t);throw new Error("Invalid name")}static fromABI(t){return new I(A.fromABI(t))}equals(t){return this.rawValue.equals(I.from(t).rawValue)}toString(){return function(t){const e=t.value.toArray("le",8);let r="";for(let t=63;t>=0;){let o=0;for(let r=0;r<5;++r)t>=0&&(o=o<<1|e[Math.floor(t/8)]>>t%8&1,--t);r+=o>=6?String.fromCharCode(o+"a".charCodeAt(0)-6):o>=1?String.fromCharCode(o+"1".charCodeAt(0)-1):"."}for(;r.endsWith(".");)r=r.substr(0,r.length-1);return r}(this.rawValue)}toABI(t){this.rawValue.toABI(t)}toJSON(){return this.toString()}}I.abiName="name",I.pattern=/^[a-z1-5.]{0,13}$/;class N{constructor(t){this.version=t.version||N.version,this.types=t.types||[],this.variants=t.variants||[],this.structs=t.structs||[],this.actions=t.actions||[],this.tables=t.tables||[],this.ricardian_clauses=t.ricardian_clauses||[]}static from(t){return t instanceof N?t:new N("string"==typeof t?JSON.parse(t):t)}resolveType(t){return this.resolve({name:t,types:{}},{id:0})}resolve({name:t,types:e},r){const o=e[t];if(o)return o;const i=new N.ResolvedType(t,++r.id);e[i.typeName]=i;const n=this.types.find(t=>t.new_type_name==i.name);if(n)return i.ref=this.resolve({name:n.type,types:e},r),i;const s=this.resolveStruct(i.name);if(s)return i.fields=s.map(t=>({name:t.name,type:this.resolve({name:t.type,types:e},r)})),i;const a=this.getVariant(i.name);return a?(i.variant=a.types.map(t=>this.resolve({name:t,types:e},r)),i):i}resolveStruct(t){let e=this.getStruct(t);if(!e)return;const r=[],o=new Set;do{for(let t=e.fields.length-1;t>=0;t--)r.unshift(e.fields[t]);if(o.add(e.name),o.has(e.base))return;e=this.getStruct(e.base)}while(void 0!==e);return r}getStruct(t){return this.structs.find(e=>e.name==t)}getVariant(t){return this.variants.find(e=>e.name==t)}getActionType(t){const e=I.from(t).toString(),r=this.actions.find(t=>t.name.toString()===e);if(r)return r.type}}N.version="eosio::abi/1.1",function(t){t.ResolvedType=class{constructor(t,e=0){let r=t;r.endsWith("$")?(r=r.slice(0,-1),this.isExtension=!0):this.isExtension=!1,r.endsWith("?")?(r=r.slice(0,-1),this.isOptional=!0):this.isOptional=!1,r.endsWith("[]")?(r=r.slice(0,-2),this.isArray=!0):this.isArray=!1,this.id=e,this.name=r}get typeName(){let t=this.name;return this.isArray&&(t+="[]"),this.isOptional&&(t+="?"),this.isExtension&&(t+="$"),t}}}(N||(N={}));class B{constructor(t){const e=this.constructor.byteSize;if(t.byteLength!==e)throw new Error(`Checksum size mismatch, expected ${e} bytes got ${t.byteLength}`);this.array=t}static from(t){return new this(t instanceof B?t.array:q.from(t).array)}static fromABI(t){return new this(t.readArray(this.byteSize))}equals(t){return a(this.array,this.constructor.from(t).array)}get hexString(){return d(this.array)}toABI(t){t.writeArray(this.array)}toString(){return this.hexString}toJSON(){return this.toString()}}class E extends B{static from(t){return super.from(t)}static hash(t){const e=new Uint8Array(o().update(q.from(t).array).digest());return new E(e)}}E.abiName="checksum256",E.byteSize=32;class U extends B{static from(t){return super.from(t)}static hash(t){const e=new Uint8Array(i().update(q.from(t).array).digest());return new U(e)}}U.abiName="checksum512",U.byteSize=64;class P extends B{static from(t){return super.from(t)}static hash(t){const e=new Uint8Array(n().update(q.from(t).array).digest());return new P(e)}}P.abiName="checksum160",P.byteSize=20;class q{constructor(t=new Uint8Array){this.array=t}static from(t,e){return t instanceof q?t:"string"==typeof t?q.fromString(t,e):t instanceof Uint8Array?new q(t):new q(new Uint8Array(t))}static fromString(t,e="hex"){if("hex"===e){const e=function(t){if(c.dec||u(),"string"!=typeof t)throw new Error("Expected string containing hex digits");if(t.length%2)throw new Error("Odd number of hex digits");const e=(t=t.toLowerCase()).length/2,r=new Uint8Array(e);for(let o=0;o<e;o++){const e=c.dec[t[2*o]+t[2*o+1]];if(void 0===e)throw new Error("Expected hex string");r[o]=e}return r}(t);return new q(e)}if("utf8"==e){const e=new TextEncoder;return new q(e.encode(t))}throw new Error("Unknown encoding: "+e)}static fromABI(t){const e=t.readVaruint32();return new q(t.readArray(e))}static equal(t,e){return q.from(t).equals(q.from(e))}static random(t){return new q(l(t))}static isBytes(t){return t instanceof q||t instanceof Uint8Array||!(!Array.isArray(t)||!t.every(t=>"number"==typeof t))||!("string"!=typeof t||!/[\da-f]/i.test(t)&&""!==t)}get ripemd160Digest(){return P.hash(this)}get sha256Digest(){return E.hash(this)}get sha512Digest(){return U.hash(this)}get hexString(){return d(this.array)}get utf8String(){return(new TextDecoder).decode(this.array)}appending(t){t=q.from(t);const e=new ArrayBuffer(this.array.byteLength+t.array.byteLength),r=new Uint8Array(e);return r.set(this.array),r.set(t.array,this.array.byteLength),new q(r)}droppingFirst(t=1){return new q(this.array.subarray(t))}copy(){const t=new ArrayBuffer(this.array.byteLength),e=new Uint8Array(t);return e.set(this.array),new q(e)}equals(t){return a(this.array,q.from(t).array)}toString(t="hex"){if("hex"===t)return this.hexString;if("utf8"===t)return this.utf8String;throw new Error("Unknown encoding: "+t)}toABI(t){t.writeVaruint32(this.array.byteLength),t.writeArray(this.array)}toJSON(){return this.hexString}}function W(t){const e=[],r=[],o=[],i=new Set,n=t=>{let e;return e="string"!=typeof t.type?s(t.type):t.type,!0===t.array&&(e+="[]"),!0===t.extension&&(e+="$"),!0===t.optional&&(e+="?"),e},s=t=>{if(!t.abiName)throw new Error("Encountered non-conforming type");if(i.has(t))return t.abiName;if(i.add(t),t.abiAlias)o.push({new_type_name:t.abiName,type:n(t.abiAlias)});else if(t.abiFields){const r=t.abiFields.map(t=>({name:t.name,type:n(t)})),o={base:t.abiBase?s(t.abiBase):"",name:t.abiName,fields:r};e.push(o)}else if(t.abiVariant){const e={name:t.abiName,types:t.abiVariant.map(n)};r.push(e)}return t.abiName},a=s(t);return{abi:N.from({structs:e,variants:r,types:o}),types:Array.from(i),root:a}}function j(t){let e="string"==typeof t.type?t.type:t.type.abiName;return!0===t.array&&(e+="[]"),!0===t.extension&&(e+="$"),!0===t.optional&&(e+="?"),e}function C(t){return"string"==typeof t||void 0!==t.abiName?{type:t}:t}q.abiName="bytes";class F{constructor(t){if(!Number.isFinite(t))throw new Error("Invalid number");this.value=t}static from(t){return t instanceof this?t:("string"==typeof t?t=Number.parseFloat(t):t instanceof F&&(t=t.value),new this(t))}static fromABI(t){return new this(t.readFloat(this.byteWidth))}static random(){const t=l(this.byteWidth),e=new mt(t);return this.fromABI(e)}equals(t){return this.value===this.constructor.from(t).value}toABI(t){t.writeFloat(this.value,this.constructor.byteWidth)}toString(){return this.value.toString()}toJSON(){return this.toString()}}class O extends F{toString(){return this.value.toFixed(7)}static from(t){return super.from(t)}}O.abiName="float32",O.byteWidth=4;class R extends F{static from(t){return super.from(t)}}R.abiName="float64",R.byteWidth=8;class T{constructor(t){if(16!==t.array.length)throw new Error("Invalid float128");this.data=t}static from(t){return t instanceof this?t:("string"==typeof t&&t.startsWith("0x")&&(t=t.slice(2)),new this(q.from(t)))}static fromABI(t){return new this(new q(t.readArray(this.byteWidth)))}static random(){const t=l(16),e=new mt(t);return this.fromABI(e)}equals(t){return this.data.equals(this.constructor.from(t).data)}toABI(t){t.writeArray(this.data.array)}toString(){return"0x"+this.data.hexString}toJSON(){return this.toString()}}T.abiName="float128",T.byteWidth=16;class ${constructor(t,e){this.units=t,this.symbol=e}static from(t){if(t instanceof $)return t;const e=("string"==typeof t?t:"").split(" ");if(2!==e.length)throw new Error("Invalid asset string");const r=e[0].replace(".",""),o=(e[0].split(".")[1]||"").length,i=$.Symbol.fromParts(e[1],o);return new $(v.from(r),i)}static fromABI(t){const e=v.fromABI(t),r=$.Symbol.fromABI(t);return new $(e,r)}equals(t){const{symbol:e,units:r}=$.from(t);return this.symbol.value.equals(e.value)&&this.units.equals(r)}get value(){return this.symbol.convertUnits(this.units)}set value(t){this.units=this.symbol.convertFloat(t)}toABI(t){this.units.toABI(t),this.symbol.toABI(t)}toString(){const t=this.units.toString().split("");let e=!1;"-"===t[0]&&(e=!0,t.shift());const r=this.symbol.precision;for(;t.length<=r;)t.unshift("0");r>0&&t.splice(t.length-r,0,".");let o=t.join("");return e&&(o="-"+o),o+" "+this.symbol.name}toJSON(){return this.toString()}}$.abiName="asset",function(e){class r{constructor(t){if(M(t)>r.maxPrecision)throw new Error("Invalid asset symbol, precision too large");if(!r.symbolNamePattern.test(V(t)))throw new Error("Invalid asset symbol, name must be uppercase A-Z");this.value=t}static from(t){if(t instanceof r)return t;if(t instanceof A)return new r(t);const e=t.split(",");if(2!==e.length)throw new Error("Invalid symbol string");const o=Number.parseInt(e[0]);return r.fromParts(e[1],o)}static fromParts(e,o){return new r(function(e,r){const o=J(e);return o.unshift(r),A.from(new t(o,"le"))}(e,o))}static fromABI(t){return new r(A.fromABI(t))}equals(t){return this.value.equals(r.from(t).value)}get name(){return V(this.value)}get precision(){return M(this.value)}get code(){return new o(A.from(this.value.value.clone().iushrn(8)))}toABI(t){this.value.toABI(t)}convertUnits(t){return t.value.toNumber()/Math.pow(10,this.precision)}convertFloat(t){const e=Math.pow(10,this.precision)*t;if(e>=9007199254740992)throw new Error("Conversion looses precision");return v.from(e)}toString(){return`${this.precision},${this.name}`}toJSON(){return this.toString()}}r.abiName="symbol",r.symbolNamePattern=/^[A-Z]{1,7}$/,r.maxPrecision=18,e.Symbol=r;class o{constructor(t){this.value=t}static from(e){return e instanceof o?e:("string"==typeof e&&(e=A.from(new t(J(e),"le"))),new this(A.from(e)))}static fromABI(t){return new o(A.fromABI(t))}equals(t){return this.value.equals(o.from(t).value)}toABI(t){this.value.toABI(t)}toString(){return L(this.value.value.toArray("be"))}toJSON(){return this.toString()}}o.abiName="symbol_code",e.SymbolCode=o}($||($={}));class D{constructor(t,e){this.quantity=t,this.contract=e}static from(t){return t instanceof D?t:new this($.from(t.quantity),I.from(t.contract))}static fromABI(t){return new D($.fromABI(t),I.fromABI(t))}equals(t){return this.quantity.equals(t.quantity)&&this.contract.equals(t.contract)}toABI(t){this.quantity.toABI(t),this.contract.toABI(t)}toJSON(){return{quantity:this.quantity,contract:this.contract}}}function M(t){return t.value.and(A.from(255).value).toNumber()}function V(t){return L(t.value.toArray("be").slice(0,-1))}function L(t){return t.map(t=>String.fromCharCode(t)).reverse().join("")}function J(t){const e=[],r=Math.min(t.length,7);for(let o=0;o<r;o++)e.push(t.charCodeAt(o));return e}var z,K;D.abiName="extended_asset",function(t){const e="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",r=new Int16Array(255).fill(-1);for(let t=0;t<58;++t)r[e.charCodeAt(t)]=t;function i(t,e){if(null==e)return function(t){const e=[];for(let o=0;o<t.length;++o){let i=r[t.charCodeAt(o)];if(i<0)throw new Error("Invalid Base58 value");for(let t=0;t<e.length;++t){const r=58*e[t]+i;e[t]=255&r,i=r>>8}i&&e.push(i)}for(const r of t){if("1"!==r)break;e.push(0)}return e.reverse(),q.from(e)}(t);const o=new Uint8Array(e);for(let i=0;i<t.length;++i){let n=r[t.charCodeAt(i)];if(n<0)throw new Error("Invalid Base58 value");for(let t=0;t<e;++t){const e=58*o[t]+n;o[t]=e,n=e>>8}if(n)throw new Error("Base58 value is out of range")}return o.reverse(),new q(o)}function s(t){t=q.from(t);const o=[];for(const i of t.array){let t=i;for(let i=0;i<o.length;++i){const n=(r[o[i]]<<8)+t;o[i]=e.charCodeAt(n%58),t=n/58|0}for(;t;)o.push(e.charCodeAt(t%58)),t=t/58|0}for(const e of t.array){if(e)break;o.push("1".charCodeAt(0))}return o.reverse(),String.fromCharCode(...o)}function c(t,e){const r=n().update(t);return e&&r.update(e),r.digest().slice(0,4)}function u(t){const e=o().update(t).digest();return o().update(e).digest().slice(0,4)}t.decode=i,t.decodeCheck=function(t,e){const r=i(t,null!=e?e+4:e),o=r.array.subarray(0,-4);if(!a(r.array.subarray(-4),u(o)))throw new Error("Checksum mismatch");return new q(o)},t.decodeRipemd160Check=function(t,e,r){const o=i(t,null!=e?e+4:e),n=o.array.subarray(0,-4);if(!a(o.array.subarray(-4),c(n,r)))throw new Error("Checksum mismatch");return new q(n)},t.encode=s,t.encodeCheck=function(t){return s(t=(t=q.from(t)).appending(u(t.array)))},t.encodeRipemd160Check=function(t,e){return s(t=(t=q.from(t)).appending(c(t.array,e)))}}(z||(z={})),function(t){t.K1="K1",t.R1="R1",t.WA="WA"}(K||(K={})),function(t){t.indexFor=function(e){switch(e){case t.K1:return 0;case t.R1:return 1;case t.WA:return 2;default:throw new Error("Unknown curve type: "+e)}},t.from=function(e){let r;switch(r="number"!=typeof e?t.indexFor(e):e,r){case 0:return t.K1;case 1:return t.R1;case 2:return t.WA;default:throw new Error("Unknown curve type")}}}(K||(K={}));class G{constructor(t,e){this.type=t,this.data=e}static from(t){if(t instanceof G)return t;if("object"==typeof t&&t.type&&t.compressed)return new G(K.from(t.type),new q(t.compressed));if("string"!=typeof t)throw new Error("Invalid public key");if(t.startsWith("PUB_")){const e=t.split("_");if(3!==e.length)throw new Error("Invalid public key string");const r=K.from(e[1]),o=z.decodeRipemd160Check(e[2],r===K.K1||r===K.R1?33:void 0,r);return new G(r,o)}if(t.length>=50){const e=z.decodeRipemd160Check(t.slice(-50));return new G(K.K1,e)}throw new Error("Invalid public key string")}static fromABI(t){const e=K.from(t.readByte());if(e==K.WA){const r=new q(t.readArray(33));return q.fromABI(t),new G(e,r)}return new G(e,new q(t.readArray(33)))}equals(t){const e=G.from(t);return this.type===e.type&&this.data.equals(e.data)}toLegacyString(t="EOS"){if(this.type!==K.K1)throw new Error("Unable to create legacy formatted string for non-K1 key");return`${t}${z.encodeRipemd160Check(this.data)}`}toString(){return`PUB_${this.type}_${z.encodeRipemd160Check(this.data,this.type)}`}toABI(t){if(this.type===K.WA)throw new Error("WA keys are not supported yet");t.writeByte(K.indexFor(this.type)),t.writeArray(this.data.array)}toJSON(){return this.toString()}}G.abiName="public_key";const H={};function Z(t){let e=H[t];if(!e)if("K1"===t)e=H[t]=new r("secp256k1");else{if("R1"!==t)throw new Error("Unknown curve type: "+t);e=H[t]=new r("p256")}return e}class Q{constructor(t,e){this.type=t,this.data=e}static from(t){if(t instanceof Q)return t;if("object"==typeof t&&t.r&&t.s){const e=new Uint8Array(65);let r=t.recid;const o=K.from(t.type);return t.type!==K.K1&&t.type!==K.R1||(r+=31),e[0]=r,e.set(t.r,1),e.set(t.s,33),new Q(o,new q(e))}if("string"!=typeof t)throw new Error("Invalid signature");if(t.startsWith("SIG_")){const e=t.split("_");if(3!==e.length)throw new Error("Invalid signature string");const r=K.from(e[1]),o=z.decodeRipemd160Check(e[2],r===K.K1||r===K.R1?65:void 0,r);return new Q(r,o)}throw new Error("Invalid signature string")}static fromABI(t){const e=K.from(t.readByte());if(e===K.WA){const e=new q(t.readArray(65));return q.fromABI(t),q.fromABI(t),new Q(K.WA,e)}return new Q(e,new q(t.readArray(65)))}equals(t){const e=Q.from(t);return this.type===e.type&&this.data.equals(e.data)}recoverDigest(t){t=E.from(t);const e=function(t,e,r){const o=Z(r),i=t[0]-31,n=t.subarray(1,33),s=t.subarray(33),a=o.recoverPubKey(e,{r:n,s},i);return new Uint8Array(a.encodeCompressed())}(this.data.array,t.array,this.type);return G.from({compressed:e,type:this.type})}recoverMessage(t){return this.recoverDigest(q.from(t).sha256Digest)}verifyDigest(t,e){return t=E.from(t),function(t,e,r,o){const i=Z(o),n=t.subarray(1,33),s=t.subarray(33);return i.verify(e,{r:n,s},r)}(this.data.array,t.array,e.data.array,this.type)}verifyMessage(t,e){return this.verifyDigest(q.from(t).sha256Digest,e)}toString(){return`SIG_${this.type}_${z.encodeRipemd160Check(this.data,this.type)}`}toABI(t){if(this.type===K.WA)throw new Error("WA signatures are not supported yet");t.writeByte(K.indexFor(this.type)),t.writeArray(this.data.array)}toJSON(){return this.toString()}}Q.abiName="signature";class X{constructor(t){const e=this.constructor.abiVariant;this.value=t[1];const r=e.map(j).findIndex(e=>e===t[0]);if(0>r||e.length<=r)throw new Error("Unknown variant "+t[0]);this.variantIdx=r}static from(t){return t[ht]?new this(t):t instanceof this?t:ft({object:t,type:this})}equals(t){const e=this.constructor.from(t);return this.variantIdx===e.variantIdx&&tt({object:this}).equals(tt({object:e}))}get variantName(){return j(this.constructor.abiVariant[this.variantIdx])}toJSON(){return[this.variantName,this.value]}}X.abiVariant=[],function(t){t.type=function(t,e){return function(r){return r.abiName=t,r.abiVariant=e.map(C),r}}}(X||(X={}));class Y extends Error{constructor(t,e){super(`Encoding error at ${t.codingPath.map(({field:t,type:e})=>"number"==typeof t?t:`${t}<${e.typeName}>`).join(".")}: ${e.message}`),this.stack=e.stack,this.ctx=t,this.underlyingError=e}}function tt(t){let e,r;"string"==typeof t.type?r=t.type:t.type&&function(t){return"string"!=typeof t&&void 0===t.abiName&&void 0!==t.type}(t.type)?("string"!=typeof t.type.type&&(e=t.type.type),r=j(t.type)):t.type&&void 0!==t.type.abiName?(e=t.type,r=t.type.abiName):(e=function t(e,r="jsobj"){var o;if(e.constructor&&void 0!==e.constructor.abiName)return e.constructor;if(Array.isArray(e)){const o=e.map(e=>t(e,r)),i=o[0];if(!i)return;if(!o.every(t=>t&&t.abiName===i.abiName))return;return i}const i=typeof e;if("object"===i&&null!==e){const i=Object.keys(e).map(o=>({name:o,type:t(e[o],r+"_nested")}));if(i.find(t=>!t.type))return;return(o=class extends rt{}).abiName=r,o.abiFields=i,o}switch(i){case"boolean":return ct;case"string":return at}}(t.object),e&&(r=e.abiName,Array.isArray(t.object)&&(r+="[]")));const o=t.customTypes||[];if(e)o.unshift(e);else if(r){const t=new N.ResolvedType(r).name;e=o.find(e=>e.abiName===t)}let i;if(t.abi&&r)i=N.from(t.abi).resolveType(r);else if(e){const t=W(e);i=t.abi.resolveType(r||e.abiName),o.push(...t.types)}else{if(!r)throw new Error("Unable to determine the type of the object to be encoded. To encode custom ABI types you must pass the type argument.");i=new N.ResolvedType(r)}const n=dt(o),s=t.encoder||new et;t.metadata&&(s.metadata=t.metadata);const a={types:n,encoder:s,codingPath:[{field:"root",type:i}]};try{!function t(e,r,o){const i=null!=e;if(!r.isOptional||(o.encoder.writeByte(i?1:0),i))if(r.isArray){if(!Array.isArray(e))throw new Error("Expected array for: "+r.typeName);const t=e.length;o.encoder.writeVaruint32(t);for(let i=0;i<t;i++)o.codingPath.push({field:i,type:r}),n(e[i]),o.codingPath.pop()}else n(e);function n(e){const n=o.types[r.name];if(!r.ref||n){if(!i){if(r.isExtension)return;throw new Error(`Found ${e} for non-optional type: ${r.typeName}`)}if(n&&n.toABI)n.toABI(e,o.encoder);else if("function"==typeof e.toABI&&e.constructor.abiName===r.name)e.toABI(o.encoder);else if(r.fields){if("object"!=typeof e)throw new Error("Expected object for: "+r.name);for(const i of r.fields)o.codingPath.push({field:i.name,type:i.type}),t(e[i.name],i.type,o),o.codingPath.pop()}else if(r.variant){let i;Array.isArray(e)&&2===e.length&&"string"==typeof e[0]?(i=e[0],e=e[1]):e instanceof X?(i=e.variantName,e=e.value):i=lt(e);const n=r.variant.findIndex(t=>t.typeName===i);if(-1===n){const t=r.variant.map(t=>`'${t.typeName}'`).join(", ");throw new Error(`Unknown variant type '${i}', expected one of ${t}`)}const s=r.variant[n];o.encoder.writeVaruint32(n),o.codingPath.push({field:"v"+n,type:s}),t(e,s,o),o.codingPath.pop()}else{if(!n)throw new Error("any"===r.name?"Unable to encode any type to binary":"Unknown type");const t=n.from(e);if(!t.toABI)throw new Error(`Invalid type ${r.name}, no encoding methods implemented`);t.toABI(o.encoder)}}else t(e,r.ref,o)}}(t.object,i,a)}catch(t){throw new Y(a,t)}return q.from(s.getData())}class et{constructor(t=1024){this.pageSize=t,this.pos=0,this.textEncoder=new TextEncoder,this.metadata={};const e=new ArrayBuffer(t);this.data=new DataView(e),this.array=new Uint8Array(e)}ensure(t){if(this.data.byteLength>=this.pos+t)return;const e=Math.ceil(t/this.pageSize),r=new ArrayBuffer(this.data.byteLength+this.pageSize*e),o=new DataView(r),i=new Uint8Array(r);i.set(this.array),this.data=o,this.array=i}writeByte(t){this.ensure(1),this.array[this.pos++]=t}writeArray(t){const e=t.length;this.ensure(e),this.array.set(t,this.pos),this.pos+=e}writeNum(t,e,r){this.ensure(e);const o=this.data,i=this.pos;switch(e*(r?-1:1)){case 1:o.setUint8(i,t);break;case 2:o.setUint16(i,t,!0);break;case 4:o.setUint32(i,t,!0);break;case-1:o.setInt8(i,t);break;case-2:o.setInt16(i,t,!0);break;case-4:o.setInt32(i,t,!0);break;default:throw new Error("Invalid integer width")}this.pos+=e}writeBn(t,e,r){r&&(t=t.toTwos(8*e)),this.writeArray(t.toArrayLike(Uint8Array,"le",e))}writeFloat(t,e){switch(this.ensure(e),e){case 4:this.data.setFloat32(this.pos,t,!0);break;case 8:this.data.setFloat64(this.pos,t,!0);break;default:throw new Error("Invalid float size")}this.pos+=e}writeVaruint32(t){for(this.ensure(4);;){if(!(t>>>7)){this.array[this.pos++]=t;break}this.array[this.pos++]=128|127&t,t>>>=7}}writeVarint32(t){this.writeVaruint32(t<<1^t>>31)}writeString(t){this.writeVaruint32(t.length),this.writeArray(this.textEncoder.encode(t))}getData(){return new Uint8Array(this.array.buffer,this.array.byteOffset,this.pos)}}class rt{constructor(t){const e=this.constructor;for(const r of e.structFields)this[r.name]=t[r.name]}static from(t){if(!0===t[ht])return new this(t);if(t instanceof this)return t;const e={};for(const r of this.structFields){const o=void 0===t[r.name]?r.default:t[r.name];if(void 0===o&&!0!==r.optional&&!r.name.includes("?"))throw new Error("Missing value for non optional field: "+r.name);e[r.name]=o}return ft({object:e,type:this})}static get structFields(){const t=[],e=r=>{r.abiBase&&e(r.abiBase);for(const e of r.abiFields||[])t.push(e)};return e(this),t}equals(t){const e=this.constructor;return(!t.constructor||"string"!=typeof t.constructor.abiName||t.constructor.abiName===e.abiName)&&tt({object:this}).equals(tt({object:e.from(t)}))}toJSON(){const t=this.constructor,e={};for(const r of t.structFields)e[r.name]=this[r.name];return e}}!function(t){const e=Symbol("FieldsOwner");t.type=function(t){return function(e){return e.abiName=t,e}},t.field=function(t,r){return r||(r={}),(o,i)=>{const n=o.constructor;n.abiFields?n.abiFields[e]!==n&&(n.abiBase=n.abiFields[e],n.abiFields=[],n.abiFields[e]=n):(n.abiFields=[],n.abiFields[e]=n),n.abiFields.push({...r,name:i,type:t})}}}(rt||(rt={}));class ot{constructor(t){this.value=t}static from(t){return t instanceof this?t:t instanceof ot?this.fromMilliseconds(t.toMilliseconds()):t instanceof Date?this.fromDate(t):"string"==typeof t?this.fromString(t):this.fromInteger(t)}static fromString(t){const e=Date.parse(t+"Z");if(!Number.isFinite(e))throw new Error("Invalid date string");return this.fromMilliseconds(e)}static fromDate(t){return this.fromMilliseconds(t.getTime())}toABI(t){this.value.toABI(t)}equals(t){const e=this.constructor;return this.toMilliseconds()===e.from(t).toMilliseconds()}toMilliseconds(){throw new Error("Not implemented")}toDate(){return new Date(this.toMilliseconds())}toJSON(){return this.toString()}}class it extends ot{static fromMilliseconds(t){return new it(v.from(Math.round(1e3*t)))}static fromInteger(t){return new it(v.from(t))}static fromABI(t){return new this(v.fromABI(t))}toString(){return this.toDate().toISOString().slice(0,-1)}toMilliseconds(){return this.value.value.divRound(new t(1e3)).toNumber()}}it.abiName="time_point";class nt extends ot{static fromMilliseconds(t){return new nt(_.from(Math.round(t/1e3)))}static fromInteger(t){return new nt(_.from(t))}static fromABI(t){return new this(_.fromABI(t))}toString(){return this.toDate().toISOString().slice(0,-5)}toMilliseconds(){return 1e3*this.value.value}}nt.abiName="time_point_sec";class st extends ot{static fromMilliseconds(t){return new nt(_.from(Math.round((t-9466848e5)/500)))}static fromInteger(t){return new nt(_.from(t))}static fromABI(t){return new this(_.fromABI(t))}toString(){return this.toDate().toISOString().slice(0,-1)}toMilliseconds(){return 500*this.value.value+9466848e5}}st.abiName="block_timestamp_type";const at={abiName:"string",fromABI:t=>t.readString(),from:t=>t,toABI:(t,e)=>{e.writeString(t)}},ct={abiName:"bool",fromABI:t=>1===t.readByte(),from:t=>t,toABI:(t,e)=>{e.writeByte(!0===t?1:0)}},ut=[ct,at,$,$.Symbol,$.SymbolCode,D,q,P,E,U,h,y,m,v,g,O,R,T,I,G,Q,it,nt,st,w,b,_,A,x,k,S];function dt(t=[]){const e={};for(const t of ut)e[t.abiName]=t;for(const r of t)e[r.abiName]=r;return e}function lt(t){if(t.constructor&&void 0!==t.constructor.abiName)return t.constructor.abiName;if(Array.isArray(t)){const e=t.map(lt),r=e[0];if(!r||!e.every(t=>t===r))return;return r+"[]"}switch(typeof t){case"boolean":return"bool";case"string":return"string"}}class pt extends Error{constructor(t,e){super(`Decoding error at ${t.codingPath.map(({field:t,type:e})=>"number"==typeof t?t:`${t}<${e.typeName}>`).join(".")}: ${e.message}`),this.stack=e.stack,this.ctx=t,this.underlyingError=e}}function ft(t){const e=C(t.type),r=j(e),o=t.customTypes||[];let i;if(t.abi)i=N.from(t.abi);else try{let t;if("string"==typeof e.type){if(t=dt(o)[new N.ResolvedType(e.type).name],!t)throw new Error("Unknown type: "+e.type)}else t=e.type;const r=W(t);i=r.abi,o.push(...r.types)}catch(t){throw Error(`Unable to synthesize ABI for: ${r} (${t.message}). To decode non-class types you need to pass the ABI definition manually.`)}const n=i.resolveType(r);"string"!=typeof e.type&&o.unshift(e.type);const s={types:dt(o),codingPath:[{field:"root",type:n}]};try{if(t.data){let e;if(t.data instanceof mt)e=t.data;else{const r=q.from(t.data);e=new mt(r.array)}return t.metadata&&(e.metadata=t.metadata),function t(e,r,o){if(o.codingPath.length>32)throw new Error("Maximum decoding depth exceeded");if(!e.isExtension||r.canRead()){if(e.isOptional&&0===r.readByte())return null;if(e.isArray){const t=r.readVaruint32(),n=[];for(let r=0;r<t;r++)o.codingPath.push({field:r,type:e}),n.push(i()),o.codingPath.pop();return n}return i()}function i(){const i=o.types[e.name];if(i&&i.fromABI)return i.fromABI(r);if(e.ref){o.codingPath.push({field:"",type:e.ref});const i=t(e.ref,r,o);return o.codingPath.pop(),i}if(e.fields){const n={};for(const i of e.fields)o.codingPath.push({field:i.name,type:i.type}),n[i.name]=t(i.type,r,o),o.codingPath.pop();return i?(n[ht]=!0,i.from(n)):n}if(e.variant){const n=r.readByte(),s=e.variant[n];if(!s)throw new Error("Unknown variant idx: "+n);o.codingPath.push({field:"v"+n,type:s});const a=[s.typeName,t(s,r,o)];return o.codingPath.pop(),i?i.from(a):a}throw i?new Error("Invalid type"):new Error("any"===e.name?"Unable to decode any type from binary":"Unknown type")}}(n,e,s)}if(void 0!==t.object)return yt(t.object,n,s);if(t.json)return yt(JSON.parse(t.json),n,s);throw new Error("Nothing to decode, you must set one of data, json, object")}catch(t){throw new pt(s,t)}}const ht=Symbol("Resolved");function yt(t,e,r){if(null==t){if(e.isOptional||e.isExtension)return null;throw new Error(`Unexpectedly encountered ${t} for non-optional`)}if(e.isArray){if(!Array.isArray(t))throw new Error("Expected array");const i=[],n=t.length;for(let s=0;s<n;s++)r.codingPath.push({field:s,type:e}),i.push(o(t[s])),r.codingPath.pop();return i}return o(t);function o(t){const o=r.types[e.name];if(e.ref&&!o)return yt(t,e.ref,r);if(e.fields){if("object"!=typeof t)throw new Error("Expected object");if("function"==typeof o&&t instanceof o)return t;const i={};for(const o of e.fields)r.codingPath.push({field:o.name,type:o.type}),i[o.name]=yt(t[o.name],o.type,r),r.codingPath.pop();return o?(i[ht]=!0,o.from(i)):i}if(e.variant){let i;Array.isArray(t)&&2===t.length&&"string"==typeof t[0]?(i=t[0],t=t[1]):t instanceof X?(i=t.variantName,t=t.value):i=lt(t);const n=e.variant.findIndex(t=>t.typeName===i);if(-1===n)throw new Error("Unknown variant type: "+i);const s=e.variant[n];r.codingPath.push({field:"v"+n,type:s});const a=[s.typeName,yt(t,s,r)];return r.codingPath.pop(),o?(a[ht]=!0,o.from(a)):a}if(!o){if("any"===e.name)return t;throw new Error("Unknown type")}return o.from(t)}}class mt{constructor(t){this.array=t,this.pos=0,this.textDecoder=new TextDecoder,this.metadata={},this.data=new DataView(t.buffer,t.byteOffset,t.byteLength)}canRead(t=1){return!(this.pos+t>this.array.byteLength)}ensure(t){if(!this.canRead(t))throw new Error("Read past end of buffer")}readByte(){return this.ensure(1),this.array[this.pos++]}readNum(t,e){this.ensure(t);const r=this.data,o=this.pos;let i;switch(t*(e?-1:1)){case 1:i=r.getUint8(o);break;case 2:i=r.getUint16(o,!0);break;case 4:i=r.getUint32(o,!0);break;case-1:i=r.getInt8(o);break;case-2:i=r.getInt16(o,!0);break;case-4:i=r.getInt32(o,!0);break;default:throw new Error("Invalid integer width")}return this.pos+=t,i}readBn(e,r){this.ensure(e);const o=new t(this.array.subarray(this.pos,this.pos+e),"le");return this.pos+=e,r?o.fromTwos(8*e):o}readFloat(t){let e;switch(this.ensure(t),t){case 4:e=this.data.getFloat32(this.pos,!0);break;case 8:e=this.data.getFloat64(this.pos,!0);break;default:throw new Error("Invalid float size")}return this.pos+=t,e}readVaruint32(){let t=0,e=0;for(;;){const r=this.readByte();if(t|=(127&r)<<e,e+=7,!(128&r))break}return t>>>0}readVarint32(){const t=this.readVaruint32();return 1&t?~t>>1|2147483648:t>>>1}readArray(t){this.ensure(t);const e=this.array.subarray(this.pos,this.pos+t);return this.pos+=t,e}readString(){const t=this.readVaruint32();return this.textDecoder.decode(this.readArray(t))}}function vt(t,e,r,o){var i,n=arguments.length,s=n<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,r,o);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(s=(n<3?i(s):n>3?i(e,r,s):i(e,r))||s);return n>3&&s&&Object.defineProperty(e,r,s),s}var gt;let wt=gt=class extends rt{static from(t){if("string"==typeof t){const e=t.split("@");if(2!==e.length&&e[0].length>0&&e[1].length>0)throw new Error("Invalid permission level string, should be in the format <actor>@<permission>");t={actor:e[0],permission:e[1]}}return super.from(t)}equals(t){const e=gt.from(t);return this.actor.equals(e.actor)&&this.permission.equals(e.permission)}};var bt;vt([rt.field("name")],wt.prototype,"actor",void 0),vt([rt.field("name")],wt.prototype,"permission",void 0),wt=gt=vt([rt.type("permission_level")],wt);let _t=bt=class extends rt{static from(t,e){const r=t.data;if(!q.isBytes(r)){let o;if(e)o=N.from(e).getActionType(t.name);else if(!r.constructor||void 0===r.constructor.abiName)throw new Error("Missing ABI definition when creating action with untyped action data");t={...t,data:tt({object:r,type:o,abi:e})}}return super.from(t)}equals(t){const e=bt.from(t);return this.account.equals(e.account)&&this.name.equals(e.name)&&function(t,e){const r=t.length;if(r!==e.length)return!1;for(let o=0;o<r;o++)if(!t[o].equals(e[o]))return!1;return!0}(this.authorization,e.authorization)&&this.data.equals(e.data)}decodeData(t){if("string"==typeof t||t.abiName)return ft({data:this.data,type:t});{const e=N.from(t),r=e.getActionType(this.name);if(!r)throw new Error(`Action ${this.name} does not exist in provided ABI`);return ft({data:this.data,type:r,abi:e})}}};var At;vt([rt.field("name")],_t.prototype,"account",void 0),vt([rt.field("name")],_t.prototype,"name",void 0),vt([rt.field(wt,{array:!0})],_t.prototype,"authorization",void 0),vt([rt.field("bytes")],_t.prototype,"data",void 0),_t=bt=vt([rt.type("action")],_t);let xt=class extends rt{};vt([rt.field("uint16")],xt.prototype,"type",void 0),vt([rt.field("bytes")],xt.prototype,"data",void 0),xt=vt([rt.type("transaction_extension")],xt);let kt=class extends rt{static from(t){return super.from(t)}};vt([rt.field("time_point_sec")],kt.prototype,"expiration",void 0),vt([rt.field("uint16")],kt.prototype,"ref_block_num",void 0),vt([rt.field("uint32")],kt.prototype,"ref_block_prefix",void 0),vt([rt.field("varuint32",{default:0})],kt.prototype,"max_net_usage_words",void 0),vt([rt.field("uint8",{default:0})],kt.prototype,"max_cpu_usage_ms",void 0),vt([rt.field("varuint32",{default:0})],kt.prototype,"delay_sec",void 0),kt=vt([rt.type("transaction_header")],kt);let St=At=class extends kt{static from(t,e){const r=t=>{return _t.from(t,(r=t.account,e?Array.isArray(e)?e.filter(t=>I.from(t.contract).equals(r)).map(({abi:t})=>t)[0]:e:void 0));var r},o=(t.actions||[]).map(r),i=(t.context_free_actions||[]).map(r),n={...t,context_free_actions:i,actions:o};return super.from(n)}equals(t){const e=At.from(t);return this.id.equals(e.id)}get id(){return tt({object:this}).sha256Digest}signingDigest(t){let e=q.from(E.from(t).array);return e=e.appending(tt({object:this})),e=e.appending(new Uint8Array(32)),e.sha256Digest}};vt([rt.field(_t,{array:!0,default:[]})],St.prototype,"context_free_actions",void 0),vt([rt.field(_t,{array:!0,default:[]})],St.prototype,"actions",void 0),vt([rt.field(xt,{array:!0,default:[]})],St.prototype,"transaction_extensions",void 0),St=At=vt([rt.type("transaction")],St);let It=class extends St{static from(t){return super.from(t)}};vt([rt.field("signature[]",{default:[]})],It.prototype,"signatures",void 0),vt([rt.field("bytes[]",{default:[]})],It.prototype,"context_free_data",void 0),It=vt([rt.type("signed_transaction")],It);let Nt=class extends rt{static fromSigned(t){const e=St.from(t);return this.from({signatures:t.signatures,packed_context_free_data:tt({object:t.context_free_data,type:"bytes[]"}),packed_trx:tt({object:e})})}getTransaction(){if(0!==this.compression.value)throw new Error("Transaction compression not supported yet");return ft({data:this.packed_trx,type:St})}getSignedTransaction(){const t=this.getTransaction();return It.from({...t,signatures:this.signatures})}};vt([rt.field("signature[]")],Nt.prototype,"signatures",void 0),vt([rt.field("uint8",{default:0})],Nt.prototype,"compression",void 0),vt([rt.field("bytes")],Nt.prototype,"packed_context_free_data",void 0),vt([rt.field("bytes")],Nt.prototype,"packed_trx",void 0),Nt=vt([rt.type("packed_transaction")],Nt);let Bt=class extends rt{};vt([rt.field("string")],Bt.prototype,"status",void 0),vt([rt.field("uint32")],Bt.prototype,"cpu_usage_us",void 0),vt([rt.field("uint32")],Bt.prototype,"net_usage_words",void 0),Bt=vt([rt.type("transaction_receipt")],Bt);let Et=class extends rt{};vt([rt.field("uint32")],Et.prototype,"weight",void 0),vt([rt.field(wt)],Et.prototype,"permission",void 0),Et=vt([rt.type("account_auth")],Et);let Ut=class extends rt{};vt([rt.field("uint32")],Ut.prototype,"weight",void 0),vt([rt.field("public_key")],Ut.prototype,"key",void 0),Ut=vt([rt.type("key_auth")],Ut);let Pt=class extends rt{};vt([rt.field("uint32")],Pt.prototype,"threshold",void 0),vt([rt.field(Ut,{array:!0,default:[]})],Pt.prototype,"keys",void 0),vt([rt.field(Et,{array:!0,default:[]})],Pt.prototype,"accounts",void 0),Pt=vt([rt.type("required_auth")],Pt);let qt=class extends rt{};vt([rt.field("name")],qt.prototype,"perm_name",void 0),vt([rt.field("name")],qt.prototype,"parent",void 0),vt([rt.field(Pt)],qt.prototype,"required_auth",void 0),qt=vt([rt.type("account_permission")],qt);let Wt=class extends rt{};vt([rt.field("int32")],Wt.prototype,"used",void 0),vt([rt.field("int32")],Wt.prototype,"available",void 0),vt([rt.field("int32")],Wt.prototype,"max",void 0),Wt=vt([rt.type("account_resource_limit")],Wt);let jt=class extends rt{};vt([rt.field("name")],jt.prototype,"owner",void 0),vt([rt.field("asset")],jt.prototype,"net_weight",void 0),vt([rt.field("asset")],jt.prototype,"cpu_weight",void 0),vt([rt.field("uint64")],jt.prototype,"ram_bytes",void 0),jt=vt([rt.type("account_total_resources")],jt);let Ct=class extends rt{};vt([rt.field("name")],Ct.prototype,"from",void 0),vt([rt.field("name")],Ct.prototype,"to",void 0),vt([rt.field("asset")],Ct.prototype,"net_weight",void 0),vt([rt.field("asset")],Ct.prototype,"cpu_weight",void 0),Ct=vt([rt.type("account_self_delegated_bandwidth")],Ct);let Ft=class extends rt{};vt([rt.field("name")],Ft.prototype,"owner",void 0),vt([rt.field("time_point")],Ft.prototype,"request_time",void 0),vt([rt.field("asset")],Ft.prototype,"net_amount",void 0),vt([rt.field("asset")],Ft.prototype,"cpu_amount",void 0),Ft=vt([rt.type("account_refund_request")],Ft);let Ot=class extends rt{};vt([rt.field("name")],Ot.prototype,"owner",void 0),vt([rt.field("name")],Ot.prototype,"proxy",void 0),vt([rt.field("name",{array:!0})],Ot.prototype,"producers",void 0),vt([rt.field("int64")],Ot.prototype,"staked",void 0),vt([rt.field("bool")],Ot.prototype,"is_proxy",void 0),vt([rt.field("uint32")],Ot.prototype,"flags1",void 0),vt([rt.field("uint32")],Ot.prototype,"reserved2",void 0),vt([rt.field("string")],Ot.prototype,"reserved3",void 0),Ot=vt([rt.type("account_voter_info")],Ot);let Rt=class extends rt{};vt([rt.field("time_point")],Rt.prototype,"key",void 0),vt([rt.field("int64")],Rt.prototype,"value",void 0),Rt=vt([rt.type("account_rex_info_maturities")],Rt);let Tt=class extends rt{};vt([rt.field("uint32")],Tt.prototype,"version",void 0),vt([rt.field("name")],Tt.prototype,"owner",void 0),vt([rt.field("asset")],Tt.prototype,"vote_stake",void 0),vt([rt.field("asset")],Tt.prototype,"rex_balance",void 0),vt([rt.field("int64")],Tt.prototype,"matured_rex",void 0),vt([rt.field(Rt,{array:!0})],Tt.prototype,"rex_maturities",void 0),Tt=vt([rt.type("account_rex_info")],Tt);let $t=class extends rt{};vt([rt.field("name")],$t.prototype,"account_name",void 0),vt([rt.field("uint32")],$t.prototype,"head_block_num",void 0),vt([rt.field("time_point")],$t.prototype,"head_block_time",void 0),vt([rt.field("bool")],$t.prototype,"privileged",void 0),vt([rt.field("time_point")],$t.prototype,"last_code_update",void 0),vt([rt.field("time_point")],$t.prototype,"created",void 0),vt([rt.field("asset?")],$t.prototype,"core_liquid_balance",void 0),vt([rt.field("int64")],$t.prototype,"ram_quota",void 0),vt([rt.field("int64")],$t.prototype,"net_weight",void 0),vt([rt.field("int64")],$t.prototype,"cpu_weight",void 0),vt([rt.field(Wt)],$t.prototype,"net_limit",void 0),vt([rt.field(Wt)],$t.prototype,"cpu_limit",void 0),vt([rt.field("uint64")],$t.prototype,"ram_usage",void 0),vt([rt.field(qt,{array:!0})],$t.prototype,"permissions",void 0),vt([rt.field(jt)],$t.prototype,"total_resources",void 0),vt([rt.field(Ct,{optional:!0})],$t.prototype,"self_delegated_bandwidth",void 0),vt([rt.field(Ft,{optional:!0})],$t.prototype,"refund_request",void 0),vt([rt.field(Ot,{optional:!0})],$t.prototype,"voter_info",void 0),vt([rt.field(Tt,{optional:!0})],$t.prototype,"rex_info",void 0),$t=vt([rt.type("account_object")],$t);let Dt=class extends rt{};vt([rt.field("name")],Dt.prototype,"producer_name",void 0),vt([rt.field("public_key")],Dt.prototype,"block_signing_key",void 0),Dt=vt([rt.type("new_producers_entry")],Dt);let Mt=class extends rt{};vt([rt.field("uint32")],Mt.prototype,"version",void 0),vt([rt.field(Dt,{array:!0})],Mt.prototype,"producers",void 0),Mt=vt([rt.type("new_producers")],Mt);let Vt=class extends rt{};vt([rt.field("uint16")],Vt.prototype,"type",void 0),vt([rt.field("bytes")],Vt.prototype,"data",void 0),Vt=vt([rt.type("block_extension")],Vt);let Lt=class extends rt{};vt([rt.field("uint16")],Lt.prototype,"type",void 0),vt([rt.field("bytes")],Lt.prototype,"data",void 0),Lt=vt([rt.type("header_extension")],Lt);let Jt=class extends rt{};vt([rt.field("time_point")],Jt.prototype,"timestamp",void 0),vt([rt.field("name")],Jt.prototype,"producer",void 0),vt([rt.field("uint16")],Jt.prototype,"confirmed",void 0),vt([rt.field("checksum256")],Jt.prototype,"previous",void 0),vt([rt.field("checksum256")],Jt.prototype,"transaction_mroot",void 0),vt([rt.field("checksum256")],Jt.prototype,"action_mroot",void 0),vt([rt.field("uint32")],Jt.prototype,"schedule_version",void 0),vt([rt.field(Mt,{optional:!0})],Jt.prototype,"new_producers",void 0),vt([rt.field("header_extension",{optional:!0})],Jt.prototype,"header_extensions",void 0),vt([rt.field("any",{optional:!0})],Jt.prototype,"new_protocol_features",void 0),vt([rt.field("signature")],Jt.prototype,"producer_signature",void 0),vt([rt.field(Bt,{array:!0})],Jt.prototype,"transactions",void 0),vt([rt.field("block_extension",{optional:!0})],Jt.prototype,"block_extensions",void 0),vt([rt.field("checksum256")],Jt.prototype,"id",void 0),vt([rt.field("uint32")],Jt.prototype,"block_num",void 0),vt([rt.field("uint32")],Jt.prototype,"ref_block_prefix",void 0),Jt=vt([rt.type("get_block_response")],Jt);let zt=class extends rt{};vt([rt.field("name")],zt.prototype,"producer_name",void 0),vt([rt.field("any")],zt.prototype,"authority",void 0),zt=vt([rt.type("active_schedule_producer_authority")],zt);let Kt=class extends rt{};vt([rt.field("name")],Kt.prototype,"producer_name",void 0),vt([rt.field(zt)],Kt.prototype,"authority",void 0),Kt=vt([rt.type("active_schedule_producer")],Kt);let Gt=class extends rt{};vt([rt.field("uint32")],Gt.prototype,"version",void 0),vt([rt.field(Kt,{array:!0})],Gt.prototype,"producers",void 0),Gt=vt([rt.type("active_schedule")],Gt);let Ht=class extends rt{};vt([rt.field("time_point")],Ht.prototype,"timestamp",void 0),vt([rt.field("name")],Ht.prototype,"producer",void 0),vt([rt.field("uint16")],Ht.prototype,"confirmed",void 0),vt([rt.field("checksum256")],Ht.prototype,"previous",void 0),vt([rt.field("checksum256")],Ht.prototype,"transaction_mroot",void 0),vt([rt.field("checksum256")],Ht.prototype,"action_mroot",void 0),vt([rt.field("uint32")],Ht.prototype,"schedule_version",void 0),vt([rt.field(Lt,{array:!0,optional:!0})],Ht.prototype,"header_extensions",void 0),vt([rt.field("signature")],Ht.prototype,"producer_signature",void 0),Ht=vt([rt.type("block_state_header")],Ht);let Zt=class extends rt{};vt([rt.field("uint32")],Zt.prototype,"block_num",void 0),vt([rt.field("uint32")],Zt.prototype,"dpos_proposed_irreversible_blocknum",void 0),vt([rt.field("uint32")],Zt.prototype,"dpos_irreversible_blocknum",void 0),vt([rt.field("checksum256")],Zt.prototype,"id",void 0),vt([rt.field(Ht)],Zt.prototype,"header",void 0),vt([rt.field("any")],Zt.prototype,"active_schedule",void 0),vt([rt.field("any")],Zt.prototype,"blockroot_merkle",void 0),vt([rt.field("any")],Zt.prototype,"producer_to_last_produced",void 0),vt([rt.field("any")],Zt.prototype,"producer_to_last_implied_irb",void 0),vt([rt.field("any")],Zt.prototype,"valid_block_signing_authority",void 0),vt([rt.field("any")],Zt.prototype,"confirm_count",void 0),vt([rt.field("any")],Zt.prototype,"pending_schedule",void 0),vt([rt.field("any")],Zt.prototype,"activated_protocol_features",void 0),vt([rt.field("any")],Zt.prototype,"additional_signatures",void 0),Zt=vt([rt.type("get_block_header_state_response")],Zt);let Qt=class extends rt{getTransactionHeader(t=120){const e=nt.fromMilliseconds(this.head_block_time.toMilliseconds()+1e3*t),r=this.last_irreversible_block_id.array.subarray(8,12),o=new Uint32Array(r.buffer,r.byteOffset,1)[0];return kt.from({expiration:e,ref_block_num:65535&this.last_irreversible_block_num.value,ref_block_prefix:o})}};vt([rt.field("string")],Qt.prototype,"server_version",void 0),vt([rt.field("checksum256")],Qt.prototype,"chain_id",void 0),vt([rt.field("uint32")],Qt.prototype,"head_block_num",void 0),vt([rt.field("uint32")],Qt.prototype,"last_irreversible_block_num",void 0),vt([rt.field("checksum256")],Qt.prototype,"last_irreversible_block_id",void 0),vt([rt.field("checksum256")],Qt.prototype,"head_block_id",void 0),vt([rt.field("time_point")],Qt.prototype,"head_block_time",void 0),vt([rt.field("name")],Qt.prototype,"head_block_producer",void 0),vt([rt.field("uint64")],Qt.prototype,"virtual_block_cpu_limit",void 0),vt([rt.field("uint64")],Qt.prototype,"virtual_block_net_limit",void 0),vt([rt.field("uint64")],Qt.prototype,"block_cpu_limit",void 0),vt([rt.field("uint64")],Qt.prototype,"block_net_limit",void 0),vt([rt.field("string?")],Qt.prototype,"server_version_string",void 0),vt([rt.field("uint32")],Qt.prototype,"fork_db_head_block_num",void 0),vt([rt.field("checksum256")],Qt.prototype,"fork_db_head_block_id",void 0),Qt=vt([rt.type("get_info_response")],Qt);var Xt={__proto__:null,get AccountAuth(){return Et},get KeyAuth(){return Ut},get RequiredAuth(){return Pt},get AccountPermission(){return qt},get AccountResourceLimit(){return Wt},get AccountTotalResources(){return jt},get AccountSelfDelegatedBandwidth(){return Ct},get AccountRefundRequest(){return Ft},get AccountVoterInfo(){return Ot},get AccountRexInfoMaturities(){return Rt},get AccountRexInfo(){return Tt},get AccountObject(){return $t},get NewProducersEntry(){return Dt},get NewProducers(){return Mt},get BlockExtension(){return Vt},get HeaderExtension(){return Lt},get GetBlockResponse(){return Jt},get ActiveScheduleProducerAuthority(){return zt},get ActiveScheduleProducer(){return Kt},get ActiveSchedule(){return Gt},get BlockStateHeader(){return Ht},get GetBlockHeaderStateResponse(){return Zt},get GetInfoResponse(){return Qt}};class Yt{constructor(t){this.client=t}async get_abi(t){return this.client.call({path:"/v1/chain/get_abi",params:{account_name:I.from(t)}})}async get_account(t){return this.client.call({path:"/v1/chain/get_account",params:{account_name:I.from(t)},responseType:$t})}async get_block(t){return this.client.call({path:"/v1/chain/get_block",params:{block_num_or_id:t},responseType:Jt})}async get_block_header_state(t){return this.client.call({path:"/v1/chain/get_block_header_state",params:{block_num_or_id:t},responseType:Zt})}async get_currency_balance(t,e,r){const o={account:I.from(e),code:I.from(t)};return r&&(o.symbol=r),this.client.call({path:"/v1/chain/get_currency_balance",params:o,responseType:"asset[]"})}async get_info(){return this.client.call({path:"/v1/chain/get_info",responseType:Qt})}async push_transaction(t){return t instanceof Nt||(t=Nt.fromSigned(It.from(t))),this.client.call({path:"/v1/chain/push_transaction",params:t})}}class te extends Error{constructor(t,e){super(`${te.formatError(e)} at ${t}`),this.path=t,this.error=e}static formatError(t){return"unspecified"===t.what&&t.details&&t.details.length>0?t.details[0].message:t.what&&t.what.length>0?t.what:"Unknown API error"}get name(){return this.error.name||"unspecified"}get code(){return this.error.code||0}get details(){return this.error.details}}class ee{constructor(t){if(this.v1={chain:new Yt(this)},t.provider)this.provider=t.provider;else{if(!t.url)throw new Error("Missing url or provider");this.provider=new s(t.url,t)}}async call(t){const e=await this.provider.call(t.path,t.params);if(e.error)throw new te(t.path,e.error);return t.responseType?ft({type:t.responseType,object:e}):e}}var re,oe={__proto__:null,v1:Xt};function ie(t,e){return!(128&t[0]||0===t[0]&&!(128&t[1])||128&e[0]||0===e[0]&&!(128&e[1]))}class ne{constructor(t,e){this.type=t,this.data=e}static from(t){if(t instanceof ne)return t;if("string"!=typeof t)throw new Error("Invalid private key");if(t.startsWith("PVT_")){const e=t.split("_");if(3!==e.length)throw new Error("Invalid private key string");const r=K.from(e[1]);let o;switch(r){case K.K1:case K.R1:o=32}const i=z.decodeRipemd160Check(e[2],o,r);return new ne(r,i)}{const e=K.K1,r=z.decodeCheck(t);if(128!==r.array[0])throw new Error("Invalid private key wif");return new ne(e,r.droppingFirst())}}static generate(t){return new ne(K.from(t),new q(function(t){return Z(t).genKeyPair().getPrivate().toArrayLike(Uint8Array,"be")}(t)))}signDigest(t){return t=E.from(t),Q.from(function(t,e,r){const o=Z(r).keyFromPrivate(t);let i,n,s;if("K1"===r){let t=1;do{i=o.sign(e,{canonical:!0,pers:[t++]}),n=i.r.toArrayLike(Uint8Array,"be",32),s=i.s.toArrayLike(Uint8Array,"be",32)}while(!ie(n,s))}else i=o.sign(e,{canonical:!0}),n=i.r.toArrayLike(Uint8Array,"be",32),s=i.s.toArrayLike(Uint8Array,"be",32);return{type:r,r:n,s,recid:i.recoveryParam||0}}(this.data.array,t.array,this.type))}signMessage(t){return this.signDigest(q.from(t).sha256Digest)}sharedSecret(t){const e=function(t,e,r){const o=Z(r),i=o.keyFromPrivate(t),n=o.keyFromPublic(e).getPublic();return i.derive(n).toArrayLike(Uint8Array,"be")}(this.data.array,t.data.array,this.type);return new q(e).sha512Digest}toPublic(){const t=function(t,e){const r=Z(e).keyFromPrivate(t).getPublic();return new Uint8Array(r.encodeCompressed())}(this.data.array,this.type);return G.from({compressed:t,type:this.type})}toWif(){if(this.type!==K.K1)throw new Error("Unable to generate WIF for non-k1 key");return z.encodeCheck(q.from([128]).appending(this.data))}toString(){return`PVT_${this.type}_${z.encodeRipemd160Check(this.data,this.type)}`}toJSON(){return this.toString()}}function se(t){return function(e){return e.abiAlias={type:Object.getPrototypeOf(e.prototype).constructor},e.abiName=t,e}}!function(t){t.encode=tt,t.decode=ft,t.synthesize=function(t){return W(t).abi}}(re||(re={}));export{N as ABI,mt as ABIDecoder,et as ABIEncoder,oe as API,ee as APIClient,te as APIError,_t as Action,$ as Asset,z as Base58,st as BlockTimestamp,q as Bytes,P as Checksum160,E as Checksum256,U as Checksum512,K as CurveType,D as ExtendedAsset,s as FetchProvider,g as Int128,y as Int16,m as Int32,v as Int64,h as Int8,I as Name,Nt as PackedTransaction,wt as PermissionLevel,ne as PrivateKey,G as PublicKey,re as Serializer,Q as Signature,It as SignedTransaction,rt as Struct,it as TimePoint,nt as TimePointSec,St as Transaction,xt as TransactionExtension,kt as TransactionHeader,Bt as TransactionReceipt,se as TypeAlias,x as UInt128,b as UInt16,_ as UInt32,A as UInt64,w as UInt8,k as VarInt,S as VarUInt,X as Variant}; | ||
import t from"bn.js";import{rand as e,ec as r}from"elliptic";import{sha256 as o,sha512 as i,ripemd160 as n}from"hash.js";class s{constructor(t,e={}){if((t=t.trim()).endsWith("/")&&(t=t.slice(0,-1)),this.url=t,e.fetch)this.fetch=e.fetch;else if("undefined"!=typeof window&&window.fetch)this.fetch=window.fetch.bind(window);else{if("undefined"==typeof global||!global.fetch)throw new Error("Missing fetch");this.fetch=global.fetch.bind(global)}}async call(t,e){const r=this.url+t,o=await this.fetch(r,{method:"POST",body:void 0!==e?JSON.stringify(e):void 0});try{return o.json()}catch(t){if(!o.ok)throw Error(`HTTP ${o.status}: ${o.statusText}`);throw t.message="Unable to parse JSON response from server: "+t.message,t}}}function a(t,e){const r=t.length;if(r!==e.length)return!1;for(let o=0;o<r;o++)if(t[o]!==e[o])return!1;return!0}const c={};function u(){c.enc=new Array(255),c.dec={};for(let t=0;t<=255;++t){const e=t.toString(16).padStart(2,"0");c.enc[t]=e,c.dec[e]=t}}function d(t){c.enc||u();const e=t.length,r=new Array(e);for(let o=0;o<e;++o)r[o]=c.enc[t[o]];return r.join("")}function l(t){return e(t)}class p{constructor(t){if(!Number.isFinite(t))throw new Error("Invalid number");var e;this.value=(e=this.constructor.max,Math.min(Math.max(t,this.constructor.min),e))}static get max(){return Math.pow(2,8*this.byteWidth-(this.isSigned?1:0))-1}static get min(){return this.isSigned?-(this.max+1):0}static from(e){if(e instanceof this)return e;if("string"==typeof e?e=Number.parseInt(e,10):e instanceof f?e=e.value.toNumber():e instanceof p?e=e.value:t.isBN(e)&&(e=e.toNumber()),"number"!=typeof e)throw new Error("Invalid integer");return new this(e)}static fromABI(t){return new this(t.readNum(this.byteWidth,this.isSigned))}static random(){const t=l(this.byteWidth),e=new mt(t);return this.fromABI(e)}equals(t){return this.value===this.constructor.from(t).value}toABI(t){const e=this.constructor;t.writeNum(this.value,e.byteWidth,e.isSigned)}toNumber(){return this.value}toString(){return this.value.toFixed(0)}toJSON(){return this.value}}class f{constructor(t){const e=this.constructor;if(t.byteLength()>e.byteWidth)throw new Error("Number too wide");this.value=t}static from(e){return e instanceof this?e:e instanceof f?new this(e.value):e instanceof Uint8Array?new this(new t(e,void 0,"le")):(e instanceof p&&(e=e.value),new this(new t(e)))}static fromABI(t){return new this(t.readBn(this.byteWidth,this.isSigned))}static random(){const t=l(this.byteWidth),e=new mt(t);return this.fromABI(e)}equals(t,e=!1){const r=this.constructor;return!(!e&&"number"==typeof t.constructor.byteWidth&&t.constructor.byteWidth!==r.byteWidth)&&this.value.eq(r.from(t).value)}toABI(t){const e=this.constructor;t.writeBn(this.value,e.byteWidth,e.isSigned)}toNumber(){return this.value.toNumber()}toString(){return this.value.toString()}toJSON(){return this.value.bitLength()>32?this.value.toString():this.value.toNumber()}}class h extends p{static from(t){return super.from(t)}}h.abiName="int8",h.byteWidth=1,h.isSigned=!0;class y extends p{static from(t){return super.from(t)}}y.abiName="int16",y.byteWidth=2,y.isSigned=!0;class m extends p{static from(t){return super.from(t)}}m.abiName="int32",m.byteWidth=4,m.isSigned=!0;class v extends f{static from(t){return super.from(t)}}v.abiName="int64",v.byteWidth=8,v.isSigned=!0;class g extends f{static from(t){return super.from(t)}}g.abiName="int128",g.byteWidth=16,g.isSigned=!0;class w extends p{static from(t){return super.from(t)}}w.abiName="uint8",w.byteWidth=1,w.isSigned=!1;class b extends p{static from(t){return super.from(t)}}b.abiName="uint16",b.byteWidth=2,b.isSigned=!1;class _ extends p{static from(t){return super.from(t)}}_.abiName="uint32",_.byteWidth=4,_.isSigned=!1;class A extends f{static from(t){return super.from(t)}}A.abiName="uint64",A.byteWidth=8,A.isSigned=!1;class x extends f{static from(t){return super.from(t)}}x.abiName="uint128",x.byteWidth=16,x.isSigned=!1;class k extends p{static from(t){return super.from(t)}static fromABI(t){return new this(t.readVarint32())}toABI(t){t.writeVarint32(this.value)}}k.abiName="varint32",k.byteWidth=32,k.isSigned=!0;class S extends p{static from(t){return super.from(t)}static fromABI(t){return new this(t.readVaruint32())}toABI(t){t.writeVaruint32(this.value)}}S.abiName="varuint32",S.byteWidth=32,S.isSigned=!1;class I{constructor(t){this.rawValue=t}static from(t){if(t instanceof I)return t;if("string"==typeof t)return new I(function(t){function e(t){return t>="a".charCodeAt(0)&&t<="z".charCodeAt(0)?t-"a".charCodeAt(0)+6:t>="1".charCodeAt(0)&&t<="5".charCodeAt(0)?t-"1".charCodeAt(0)+1:0}const r=new Uint8Array(8);let o=63;for(let i=0;i<t.length;++i){let n=e(t.charCodeAt(i));o<5&&(n<<=1);for(let t=4;t>=0;--t)o>=0&&(r[Math.floor(o/8)]|=(n>>t&1)<<o%8,--o)}return A.from(r)}(t));if(t instanceof A)return new I(t);throw new Error("Invalid name")}static fromABI(t){return new I(A.fromABI(t))}equals(t){return this.rawValue.equals(I.from(t).rawValue)}toString(){return function(t){const e=t.value.toArray("le",8);let r="";for(let t=63;t>=0;){let o=0;for(let r=0;r<5;++r)t>=0&&(o=o<<1|e[Math.floor(t/8)]>>t%8&1,--t);r+=o>=6?String.fromCharCode(o+"a".charCodeAt(0)-6):o>=1?String.fromCharCode(o+"1".charCodeAt(0)-1):"."}for(;r.endsWith(".");)r=r.substr(0,r.length-1);return r}(this.rawValue)}toABI(t){this.rawValue.toABI(t)}toJSON(){return this.toString()}}I.abiName="name",I.pattern=/^[a-z1-5.]{0,13}$/;class N{constructor(t){this.version=t.version||N.version,this.types=t.types||[],this.variants=t.variants||[],this.structs=t.structs||[],this.actions=t.actions||[],this.tables=t.tables||[],this.ricardian_clauses=t.ricardian_clauses||[]}static from(t){return t instanceof N?t:new N("string"==typeof t?JSON.parse(t):t)}resolveType(t){return this.resolve({name:t,types:{}},{id:0})}resolve({name:t,types:e},r){const o=e[t];if(o)return o;const i=new N.ResolvedType(t,++r.id);e[i.typeName]=i;const n=this.types.find(t=>t.new_type_name==i.name);if(n)return i.ref=this.resolve({name:n.type,types:e},r),i;const s=this.resolveStruct(i.name);if(s)return i.fields=s.map(t=>({name:t.name,type:this.resolve({name:t.type,types:e},r)})),i;const a=this.getVariant(i.name);return a?(i.variant=a.types.map(t=>this.resolve({name:t,types:e},r)),i):i}resolveStruct(t){let e=this.getStruct(t);if(!e)return;const r=[],o=new Set;do{for(let t=e.fields.length-1;t>=0;t--)r.unshift(e.fields[t]);if(o.add(e.name),o.has(e.base))return;e=this.getStruct(e.base)}while(void 0!==e);return r}getStruct(t){return this.structs.find(e=>e.name==t)}getVariant(t){return this.variants.find(e=>e.name==t)}getActionType(t){const e=I.from(t).toString(),r=this.actions.find(t=>t.name.toString()===e);if(r)return r.type}}N.version="eosio::abi/1.1",function(t){t.ResolvedType=class{constructor(t,e=0){let r=t;r.endsWith("$")?(r=r.slice(0,-1),this.isExtension=!0):this.isExtension=!1,r.endsWith("?")?(r=r.slice(0,-1),this.isOptional=!0):this.isOptional=!1,r.endsWith("[]")?(r=r.slice(0,-2),this.isArray=!0):this.isArray=!1,this.id=e,this.name=r}get typeName(){let t=this.name;return this.isArray&&(t+="[]"),this.isOptional&&(t+="?"),this.isExtension&&(t+="$"),t}}}(N||(N={}));class B{constructor(t){const e=this.constructor.byteSize;if(t.byteLength!==e)throw new Error(`Checksum size mismatch, expected ${e} bytes got ${t.byteLength}`);this.array=t}static from(t){return new this(t instanceof B?t.array:q.from(t).array)}static fromABI(t){return new this(t.readArray(this.byteSize))}equals(t){return a(this.array,this.constructor.from(t).array)}get hexString(){return d(this.array)}toABI(t){t.writeArray(this.array)}toString(){return this.hexString}toJSON(){return this.toString()}}class E extends B{static from(t){return super.from(t)}static hash(t){const e=new Uint8Array(o().update(q.from(t).array).digest());return new E(e)}}E.abiName="checksum256",E.byteSize=32;class U extends B{static from(t){return super.from(t)}static hash(t){const e=new Uint8Array(i().update(q.from(t).array).digest());return new U(e)}}U.abiName="checksum512",U.byteSize=64;class P extends B{static from(t){return super.from(t)}static hash(t){const e=new Uint8Array(n().update(q.from(t).array).digest());return new P(e)}}P.abiName="checksum160",P.byteSize=20;class q{constructor(t=new Uint8Array){this.array=t}static from(t,e){return t instanceof q?t:"string"==typeof t?q.fromString(t,e):t instanceof Uint8Array?new q(t):new q(new Uint8Array(t))}static fromString(t,e="hex"){if("hex"===e){const e=function(t){if(c.dec||u(),"string"!=typeof t)throw new Error("Expected string containing hex digits");if(t.length%2)throw new Error("Odd number of hex digits");const e=(t=t.toLowerCase()).length/2,r=new Uint8Array(e);for(let o=0;o<e;o++){const e=c.dec[t[2*o]+t[2*o+1]];if(void 0===e)throw new Error("Expected hex string");r[o]=e}return r}(t);return new q(e)}if("utf8"==e){const e=new TextEncoder;return new q(e.encode(t))}throw new Error("Unknown encoding: "+e)}static fromABI(t){const e=t.readVaruint32();return new q(t.readArray(e))}static equal(t,e){return q.from(t).equals(q.from(e))}static random(t){return new q(l(t))}static isBytes(t){return t instanceof q||t instanceof Uint8Array||!(!Array.isArray(t)||!t.every(t=>"number"==typeof t))||!("string"!=typeof t||!/[\da-f]/i.test(t)&&""!==t)}get ripemd160Digest(){return P.hash(this)}get sha256Digest(){return E.hash(this)}get sha512Digest(){return U.hash(this)}get hexString(){return d(this.array)}get utf8String(){return(new TextDecoder).decode(this.array)}appending(t){t=q.from(t);const e=new ArrayBuffer(this.array.byteLength+t.array.byteLength),r=new Uint8Array(e);return r.set(this.array),r.set(t.array,this.array.byteLength),new q(r)}droppingFirst(t=1){return new q(this.array.subarray(t))}copy(){const t=new ArrayBuffer(this.array.byteLength),e=new Uint8Array(t);return e.set(this.array),new q(e)}equals(t){return a(this.array,q.from(t).array)}toString(t="hex"){if("hex"===t)return this.hexString;if("utf8"===t)return this.utf8String;throw new Error("Unknown encoding: "+t)}toABI(t){t.writeVaruint32(this.array.byteLength),t.writeArray(this.array)}toJSON(){return this.hexString}}function W(t){const e=[],r=[],o=[],i=new Set,n=t=>{let e;return e="string"!=typeof t.type?s(t.type):t.type,!0===t.array&&(e+="[]"),!0===t.extension&&(e+="$"),!0===t.optional&&(e+="?"),e},s=t=>{if(!t.abiName)throw new Error("Encountered non-conforming type");if(i.has(t))return t.abiName;if(i.add(t),t.abiAlias)o.push({new_type_name:t.abiName,type:n(t.abiAlias)});else if(t.abiFields){const r=t.abiFields.map(t=>({name:t.name,type:n(t)})),o={base:t.abiBase?s(t.abiBase):"",name:t.abiName,fields:r};e.push(o)}else if(t.abiVariant){const e={name:t.abiName,types:t.abiVariant.map(n)};r.push(e)}return t.abiName},a=s(t);return{abi:N.from({structs:e,variants:r,types:o}),types:Array.from(i),root:a}}function j(t){let e="string"==typeof t.type?t.type:t.type.abiName;return!0===t.array&&(e+="[]"),!0===t.extension&&(e+="$"),!0===t.optional&&(e+="?"),e}function C(t){return"string"==typeof t||void 0!==t.abiName?{type:t}:t}q.abiName="bytes";class F{constructor(t){if(!Number.isFinite(t))throw new Error("Invalid number");this.value=t}static from(t){return t instanceof this?t:("string"==typeof t?t=Number.parseFloat(t):t instanceof F&&(t=t.value),new this(t))}static fromABI(t){return new this(t.readFloat(this.byteWidth))}static random(){const t=l(this.byteWidth),e=new mt(t);return this.fromABI(e)}equals(t){return this.value===this.constructor.from(t).value}toABI(t){t.writeFloat(this.value,this.constructor.byteWidth)}toString(){return this.value.toString()}toJSON(){return this.toString()}}class O extends F{toString(){return this.value.toFixed(7)}static from(t){return super.from(t)}}O.abiName="float32",O.byteWidth=4;class R extends F{static from(t){return super.from(t)}}R.abiName="float64",R.byteWidth=8;class T{constructor(t){if(16!==t.array.length)throw new Error("Invalid float128");this.data=t}static from(t){return t instanceof this?t:("string"==typeof t&&t.startsWith("0x")&&(t=t.slice(2)),new this(q.from(t)))}static fromABI(t){return new this(new q(t.readArray(this.byteWidth)))}static random(){const t=l(16),e=new mt(t);return this.fromABI(e)}equals(t){return this.data.equals(this.constructor.from(t).data)}toABI(t){t.writeArray(this.data.array)}toString(){return"0x"+this.data.hexString}toJSON(){return this.toString()}}T.abiName="float128",T.byteWidth=16;class ${constructor(t,e){this.units=t,this.symbol=e}static from(t){if(t instanceof $)return t;const e=("string"==typeof t?t:"").split(" ");if(2!==e.length)throw new Error("Invalid asset string");const r=e[0].replace(".",""),o=(e[0].split(".")[1]||"").length,i=$.Symbol.fromParts(e[1],o);return new $(v.from(r),i)}static fromABI(t){const e=v.fromABI(t),r=$.Symbol.fromABI(t);return new $(e,r)}equals(t){const{symbol:e,units:r}=$.from(t);return this.symbol.value.equals(e.value)&&this.units.equals(r)}get value(){return this.symbol.convertUnits(this.units)}set value(t){this.units=this.symbol.convertFloat(t)}toABI(t){this.units.toABI(t),this.symbol.toABI(t)}toString(){const t=this.units.toString().split("");let e=!1;"-"===t[0]&&(e=!0,t.shift());const r=this.symbol.precision;for(;t.length<=r;)t.unshift("0");r>0&&t.splice(t.length-r,0,".");let o=t.join("");return e&&(o="-"+o),o+" "+this.symbol.name}toJSON(){return this.toString()}}$.abiName="asset",function(e){class r{constructor(t){if(M(t)>r.maxPrecision)throw new Error("Invalid asset symbol, precision too large");if(!r.symbolNamePattern.test(V(t)))throw new Error("Invalid asset symbol, name must be uppercase A-Z");this.value=t}static from(t){if(t instanceof r)return t;if(t instanceof A)return new r(t);const e=t.split(",");if(2!==e.length)throw new Error("Invalid symbol string");const o=Number.parseInt(e[0]);return r.fromParts(e[1],o)}static fromParts(e,o){return new r(function(e,r){const o=J(e);return o.unshift(r),A.from(new t(o,"le"))}(e,o))}static fromABI(t){return new r(A.fromABI(t))}equals(t){return this.value.equals(r.from(t).value)}get name(){return V(this.value)}get precision(){return M(this.value)}get code(){return new o(A.from(this.value.value.clone().iushrn(8)))}toABI(t){this.value.toABI(t)}convertUnits(t){return t.value.toNumber()/Math.pow(10,this.precision)}convertFloat(t){const e=Math.pow(10,this.precision)*t;if(e>=9007199254740992)throw new Error("Conversion looses precision");return v.from(e)}toString(){return`${this.precision},${this.name}`}toJSON(){return this.toString()}}r.abiName="symbol",r.symbolNamePattern=/^[A-Z]{1,7}$/,r.maxPrecision=18,e.Symbol=r;class o{constructor(t){this.value=t}static from(e){return e instanceof o?e:("string"==typeof e&&(e=A.from(new t(J(e),"le"))),new this(A.from(e)))}static fromABI(t){return new o(A.fromABI(t))}equals(t){return this.value.equals(o.from(t).value)}toABI(t){this.value.toABI(t)}toString(){return L(this.value.value.toArray("be"))}toJSON(){return this.toString()}}o.abiName="symbol_code",e.SymbolCode=o}($||($={}));class D{constructor(t,e){this.quantity=t,this.contract=e}static from(t){return t instanceof D?t:new this($.from(t.quantity),I.from(t.contract))}static fromABI(t){return new D($.fromABI(t),I.fromABI(t))}equals(t){return this.quantity.equals(t.quantity)&&this.contract.equals(t.contract)}toABI(t){this.quantity.toABI(t),this.contract.toABI(t)}toJSON(){return{quantity:this.quantity,contract:this.contract}}}function M(t){return t.value.and(A.from(255).value).toNumber()}function V(t){return L(t.value.toArray("be").slice(0,-1))}function L(t){return t.map(t=>String.fromCharCode(t)).reverse().join("")}function J(t){const e=[],r=Math.min(t.length,7);for(let o=0;o<r;o++)e.push(t.charCodeAt(o));return e}var z,K;D.abiName="extended_asset",function(t){const e="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",r=new Int16Array(255).fill(-1);for(let t=0;t<58;++t)r[e.charCodeAt(t)]=t;function i(t,e){if(null==e)return function(t){const e=[];for(let o=0;o<t.length;++o){let i=r[t.charCodeAt(o)];if(i<0)throw new Error("Invalid Base58 value");for(let t=0;t<e.length;++t){const r=58*e[t]+i;e[t]=255&r,i=r>>8}i&&e.push(i)}for(const r of t){if("1"!==r)break;e.push(0)}return e.reverse(),q.from(e)}(t);const o=new Uint8Array(e);for(let i=0;i<t.length;++i){let n=r[t.charCodeAt(i)];if(n<0)throw new Error("Invalid Base58 value");for(let t=0;t<e;++t){const e=58*o[t]+n;o[t]=e,n=e>>8}if(n)throw new Error("Base58 value is out of range")}return o.reverse(),new q(o)}function s(t){t=q.from(t);const o=[];for(const i of t.array){let t=i;for(let i=0;i<o.length;++i){const n=(r[o[i]]<<8)+t;o[i]=e.charCodeAt(n%58),t=n/58|0}for(;t;)o.push(e.charCodeAt(t%58)),t=t/58|0}for(const e of t.array){if(e)break;o.push("1".charCodeAt(0))}return o.reverse(),String.fromCharCode(...o)}function c(t,e){const r=n().update(t);return e&&r.update(e),r.digest().slice(0,4)}function u(t){const e=o().update(t).digest();return o().update(e).digest().slice(0,4)}t.decode=i,t.decodeCheck=function(t,e){const r=i(t,null!=e?e+4:e),o=r.array.subarray(0,-4);if(!a(r.array.subarray(-4),u(o)))throw new Error("Checksum mismatch");return new q(o)},t.decodeRipemd160Check=function(t,e,r){const o=i(t,null!=e?e+4:e),n=o.array.subarray(0,-4);if(!a(o.array.subarray(-4),c(n,r)))throw new Error("Checksum mismatch");return new q(n)},t.encode=s,t.encodeCheck=function(t){return s(t=(t=q.from(t)).appending(u(t.array)))},t.encodeRipemd160Check=function(t,e){return s(t=(t=q.from(t)).appending(c(t.array,e)))}}(z||(z={})),function(t){t.K1="K1",t.R1="R1",t.WA="WA"}(K||(K={})),function(t){t.indexFor=function(e){switch(e){case t.K1:return 0;case t.R1:return 1;case t.WA:return 2;default:throw new Error("Unknown curve type: "+e)}},t.from=function(e){let r;switch(r="number"!=typeof e?t.indexFor(e):e,r){case 0:return t.K1;case 1:return t.R1;case 2:return t.WA;default:throw new Error("Unknown curve type")}}}(K||(K={}));class G{constructor(t,e){this.type=t,this.data=e}static from(t){if(t instanceof G)return t;if("object"==typeof t&&t.type&&t.compressed)return new G(K.from(t.type),new q(t.compressed));if("string"!=typeof t)throw new Error("Invalid public key");if(t.startsWith("PUB_")){const e=t.split("_");if(3!==e.length)throw new Error("Invalid public key string");const r=K.from(e[1]),o=z.decodeRipemd160Check(e[2],r===K.K1||r===K.R1?33:void 0,r);return new G(r,o)}if(t.length>=50){const e=z.decodeRipemd160Check(t.slice(-50));return new G(K.K1,e)}throw new Error("Invalid public key string")}static fromABI(t){const e=K.from(t.readByte());if(e==K.WA){const r=new q(t.readArray(33));return q.fromABI(t),new G(e,r)}return new G(e,new q(t.readArray(33)))}equals(t){const e=G.from(t);return this.type===e.type&&this.data.equals(e.data)}toLegacyString(t="EOS"){if(this.type!==K.K1)throw new Error("Unable to create legacy formatted string for non-K1 key");return`${t}${z.encodeRipemd160Check(this.data)}`}toString(){return`PUB_${this.type}_${z.encodeRipemd160Check(this.data,this.type)}`}toABI(t){if(this.type===K.WA)throw new Error("WA keys are not supported yet");t.writeByte(K.indexFor(this.type)),t.writeArray(this.data.array)}toJSON(){return this.toString()}}G.abiName="public_key";const H={};function Z(t){let e=H[t];if(!e)if("K1"===t)e=H[t]=new r("secp256k1");else{if("R1"!==t)throw new Error("Unknown curve type: "+t);e=H[t]=new r("p256")}return e}class Q{constructor(t,e){this.type=t,this.data=e}static from(t){if(t instanceof Q)return t;if("object"==typeof t&&t.r&&t.s){const e=new Uint8Array(65);let r=t.recid;const o=K.from(t.type);return t.type!==K.K1&&t.type!==K.R1||(r+=31),e[0]=r,e.set(t.r,1),e.set(t.s,33),new Q(o,new q(e))}if("string"!=typeof t)throw new Error("Invalid signature");if(t.startsWith("SIG_")){const e=t.split("_");if(3!==e.length)throw new Error("Invalid signature string");const r=K.from(e[1]),o=z.decodeRipemd160Check(e[2],r===K.K1||r===K.R1?65:void 0,r);return new Q(r,o)}throw new Error("Invalid signature string")}static fromABI(t){const e=K.from(t.readByte());if(e===K.WA){const e=new q(t.readArray(65));return q.fromABI(t),q.fromABI(t),new Q(K.WA,e)}return new Q(e,new q(t.readArray(65)))}equals(t){const e=Q.from(t);return this.type===e.type&&this.data.equals(e.data)}recoverDigest(t){t=E.from(t);const e=function(t,e,r){const o=Z(r),i=t[0]-31,n=t.subarray(1,33),s=t.subarray(33),a=o.recoverPubKey(e,{r:n,s},i);return new Uint8Array(a.encodeCompressed())}(this.data.array,t.array,this.type);return G.from({compressed:e,type:this.type})}recoverMessage(t){return this.recoverDigest(q.from(t).sha256Digest)}verifyDigest(t,e){return t=E.from(t),function(t,e,r,o){const i=Z(o),n=t.subarray(1,33),s=t.subarray(33);return i.verify(e,{r:n,s},r)}(this.data.array,t.array,e.data.array,this.type)}verifyMessage(t,e){return this.verifyDigest(q.from(t).sha256Digest,e)}toString(){return`SIG_${this.type}_${z.encodeRipemd160Check(this.data,this.type)}`}toABI(t){if(this.type===K.WA)throw new Error("WA signatures are not supported yet");t.writeByte(K.indexFor(this.type)),t.writeArray(this.data.array)}toJSON(){return this.toString()}}Q.abiName="signature";class X{constructor(t){const e=this.constructor.abiVariant;this.value=t[1];const r=e.map(j).findIndex(e=>e===t[0]);if(0>r||e.length<=r)throw new Error("Unknown variant "+t[0]);this.variantIdx=r}static from(t){return t[ht]?new this(t):t instanceof this?t:ft({object:t,type:this})}equals(t){const e=this.constructor.from(t);return this.variantIdx===e.variantIdx&&tt({object:this}).equals(tt({object:e}))}get variantName(){return j(this.constructor.abiVariant[this.variantIdx])}toJSON(){return[this.variantName,this.value]}}X.abiVariant=[],function(t){t.type=function(t,e){return function(r){return r.abiName=t,r.abiVariant=e.map(C),r}}}(X||(X={}));class Y extends Error{constructor(t,e){super(`Encoding error at ${t.codingPath.map(({field:t,type:e})=>"number"==typeof t?t:`${t}<${e.typeName}>`).join(".")}: ${e.message}`),this.stack=e.stack,this.ctx=t,this.underlyingError=e}}function tt(t){let e,r;"string"==typeof t.type?r=t.type:t.type&&function(t){return"string"!=typeof t&&void 0===t.abiName&&void 0!==t.type}(t.type)?("string"!=typeof t.type.type&&(e=t.type.type),r=j(t.type)):t.type&&void 0!==t.type.abiName?(e=t.type,r=t.type.abiName):(e=function t(e,r="jsobj"){var o;if(e.constructor&&void 0!==e.constructor.abiName)return e.constructor;if(Array.isArray(e)){const o=e.map(e=>t(e,r)),i=o[0];if(!i)return;if(!o.every(t=>t&&t.abiName===i.abiName))return;return i}const i=typeof e;if("object"===i&&null!==e){const i=Object.keys(e).map(o=>({name:o,type:t(e[o],r+"_nested")}));if(i.find(t=>!t.type))return;return(o=class extends rt{}).abiName=r,o.abiFields=i,o}switch(i){case"boolean":return ct;case"string":return at}}(t.object),e&&(r=e.abiName,Array.isArray(t.object)&&(r+="[]")));const o=t.customTypes||[];if(e)o.unshift(e);else if(r){const t=new N.ResolvedType(r).name;e=o.find(e=>e.abiName===t)}let i;if(t.abi&&r)i=N.from(t.abi).resolveType(r);else if(e){const t=W(e);i=t.abi.resolveType(r||e.abiName),o.push(...t.types)}else{if(!r)throw new Error("Unable to determine the type of the object to be encoded. To encode custom ABI types you must pass the type argument.");i=new N.ResolvedType(r)}const n=dt(o),s=t.encoder||new et;t.metadata&&(s.metadata=t.metadata);const a={types:n,encoder:s,codingPath:[{field:"root",type:i}]};try{!function t(e,r,o){const i=null!=e;if(!r.isOptional||(o.encoder.writeByte(i?1:0),i))if(r.isArray){if(!Array.isArray(e))throw new Error("Expected array for: "+r.typeName);const t=e.length;o.encoder.writeVaruint32(t);for(let i=0;i<t;i++)o.codingPath.push({field:i,type:r}),n(e[i]),o.codingPath.pop()}else n(e);function n(e){const n=o.types[r.name];if(!r.ref||n){if(!i){if(r.isExtension)return;throw new Error(`Found ${e} for non-optional type: ${r.typeName}`)}if(n&&n.toABI)n.toABI(e,o.encoder);else if("function"==typeof e.toABI&&e.constructor.abiName===r.name)e.toABI(o.encoder);else if(r.fields){if("object"!=typeof e)throw new Error("Expected object for: "+r.name);for(const i of r.fields)o.codingPath.push({field:i.name,type:i.type}),t(e[i.name],i.type,o),o.codingPath.pop()}else if(r.variant){let i;Array.isArray(e)&&2===e.length&&"string"==typeof e[0]?(i=e[0],e=e[1]):e instanceof X?(i=e.variantName,e=e.value):i=lt(e);const n=r.variant.findIndex(t=>t.typeName===i);if(-1===n){const t=r.variant.map(t=>`'${t.typeName}'`).join(", ");throw new Error(`Unknown variant type '${i}', expected one of ${t}`)}const s=r.variant[n];o.encoder.writeVaruint32(n),o.codingPath.push({field:"v"+n,type:s}),t(e,s,o),o.codingPath.pop()}else{if(!n)throw new Error("any"===r.name?"Unable to encode any type to binary":"Unknown type");const t=n.from(e);if(!t.toABI)throw new Error(`Invalid type ${r.name}, no encoding methods implemented`);t.toABI(o.encoder)}}else t(e,r.ref,o)}}(t.object,i,a)}catch(t){throw new Y(a,t)}return q.from(s.getData())}class et{constructor(t=1024){this.pageSize=t,this.pos=0,this.textEncoder=new TextEncoder,this.metadata={};const e=new ArrayBuffer(t);this.data=new DataView(e),this.array=new Uint8Array(e)}ensure(t){if(this.data.byteLength>=this.pos+t)return;const e=Math.ceil(t/this.pageSize),r=new ArrayBuffer(this.data.byteLength+this.pageSize*e),o=new DataView(r),i=new Uint8Array(r);i.set(this.array),this.data=o,this.array=i}writeByte(t){this.ensure(1),this.array[this.pos++]=t}writeArray(t){const e=t.length;this.ensure(e),this.array.set(t,this.pos),this.pos+=e}writeNum(t,e,r){this.ensure(e);const o=this.data,i=this.pos;switch(e*(r?-1:1)){case 1:o.setUint8(i,t);break;case 2:o.setUint16(i,t,!0);break;case 4:o.setUint32(i,t,!0);break;case-1:o.setInt8(i,t);break;case-2:o.setInt16(i,t,!0);break;case-4:o.setInt32(i,t,!0);break;default:throw new Error("Invalid integer width")}this.pos+=e}writeBn(t,e,r){r&&(t=t.toTwos(8*e)),this.writeArray(t.toArrayLike(Uint8Array,"le",e))}writeFloat(t,e){switch(this.ensure(e),e){case 4:this.data.setFloat32(this.pos,t,!0);break;case 8:this.data.setFloat64(this.pos,t,!0);break;default:throw new Error("Invalid float size")}this.pos+=e}writeVaruint32(t){for(this.ensure(4);;){if(!(t>>>7)){this.array[this.pos++]=t;break}this.array[this.pos++]=128|127&t,t>>>=7}}writeVarint32(t){this.writeVaruint32(t<<1^t>>31)}writeString(t){this.writeVaruint32(t.length),this.writeArray(this.textEncoder.encode(t))}getData(){return new Uint8Array(this.array.buffer,this.array.byteOffset,this.pos)}}class rt{constructor(t){const e=this.constructor;for(const r of e.structFields)this[r.name]=t[r.name]}static from(t){if(!0===t[ht])return new this(t);if(t instanceof this)return t;const e={};for(const r of this.structFields){const o=void 0===t[r.name]?r.default:t[r.name];if(void 0===o&&!0!==r.optional&&!r.name.includes("?"))throw new Error("Missing value for non optional field: "+r.name);e[r.name]=o}return ft({object:e,type:this})}static get structFields(){const t=[],e=r=>{r.abiBase&&e(r.abiBase);for(const e of r.abiFields||[])t.push(e)};return e(this),t}equals(t){const e=this.constructor;return(!t.constructor||"string"!=typeof t.constructor.abiName||t.constructor.abiName===e.abiName)&&tt({object:this}).equals(tt({object:e.from(t)}))}toJSON(){const t=this.constructor,e={};for(const r of t.structFields)e[r.name]=this[r.name];return e}}!function(t){const e=Symbol("FieldsOwner");t.type=function(t){return function(e){return e.abiName=t,e}},t.field=function(t,r){return r||(r={}),(o,i)=>{const n=o.constructor;n.abiFields?n.abiFields[e]!==n&&(n.abiBase=n.abiFields[e],n.abiFields=[],n.abiFields[e]=n):(n.abiFields=[],n.abiFields[e]=n),n.abiFields.push({...r,name:i,type:t})}}}(rt||(rt={}));class ot{constructor(t){this.value=t}static from(t){return t instanceof this?t:t instanceof ot?this.fromMilliseconds(t.toMilliseconds()):t instanceof Date?this.fromDate(t):"string"==typeof t?this.fromString(t):this.fromInteger(t)}static fromString(t){const e=Date.parse(t+"Z");if(!Number.isFinite(e))throw new Error("Invalid date string");return this.fromMilliseconds(e)}static fromDate(t){return this.fromMilliseconds(t.getTime())}toABI(t){this.value.toABI(t)}equals(t){const e=this.constructor;return this.toMilliseconds()===e.from(t).toMilliseconds()}toMilliseconds(){throw new Error("Not implemented")}toDate(){return new Date(this.toMilliseconds())}toJSON(){return this.toString()}}class it extends ot{static fromMilliseconds(t){return new it(v.from(Math.round(1e3*t)))}static fromInteger(t){return new it(v.from(t))}static fromABI(t){return new this(v.fromABI(t))}toString(){return this.toDate().toISOString().slice(0,-1)}toMilliseconds(){return this.value.value.divRound(new t(1e3)).toNumber()}}it.abiName="time_point";class nt extends ot{static fromMilliseconds(t){return new nt(_.from(Math.round(t/1e3)))}static fromInteger(t){return new nt(_.from(t))}static fromABI(t){return new this(_.fromABI(t))}toString(){return this.toDate().toISOString().slice(0,-5)}toMilliseconds(){return 1e3*this.value.value}}nt.abiName="time_point_sec";class st extends ot{static fromMilliseconds(t){return new nt(_.from(Math.round((t-9466848e5)/500)))}static fromInteger(t){return new nt(_.from(t))}static fromABI(t){return new this(_.fromABI(t))}toString(){return this.toDate().toISOString().slice(0,-1)}toMilliseconds(){return 500*this.value.value+9466848e5}}st.abiName="block_timestamp_type";const at={abiName:"string",fromABI:t=>t.readString(),from:t=>t,toABI:(t,e)=>{e.writeString(t)}},ct={abiName:"bool",fromABI:t=>1===t.readByte(),from:t=>t,toABI:(t,e)=>{e.writeByte(!0===t?1:0)}},ut=[ct,at,$,$.Symbol,$.SymbolCode,D,q,P,E,U,h,y,m,v,g,O,R,T,I,G,Q,it,nt,st,w,b,_,A,x,k,S];function dt(t=[]){const e={};for(const t of ut)e[t.abiName]=t;for(const r of t)e[r.abiName]=r;return e}function lt(t){if(t.constructor&&void 0!==t.constructor.abiName)return t.constructor.abiName;if(Array.isArray(t)){const e=t.map(lt),r=e[0];if(!r||!e.every(t=>t===r))return;return r+"[]"}switch(typeof t){case"boolean":return"bool";case"string":return"string"}}class pt extends Error{constructor(t,e){super(`Decoding error at ${t.codingPath.map(({field:t,type:e})=>"number"==typeof t?t:`${t}<${e.typeName}>`).join(".")}: ${e.message}`),this.stack=e.stack,this.ctx=t,this.underlyingError=e}}function ft(t){const e=C(t.type),r=j(e),o=t.customTypes||[];let i;if(t.abi)i=N.from(t.abi);else try{let t;if("string"==typeof e.type){if(t=dt(o)[new N.ResolvedType(e.type).name],!t)throw new Error("Unknown type: "+e.type)}else t=e.type;const r=W(t);i=r.abi,o.push(...r.types)}catch(t){throw Error(`Unable to synthesize ABI for: ${r} (${t.message}). To decode non-class types you need to pass the ABI definition manually.`)}const n=i.resolveType(r);"string"!=typeof e.type&&o.unshift(e.type);const s={types:dt(o),codingPath:[{field:"root",type:n}]};try{if(t.data){let e;if(t.data instanceof mt)e=t.data;else{const r=q.from(t.data);e=new mt(r.array)}return t.metadata&&(e.metadata=t.metadata),function t(e,r,o){if(o.codingPath.length>32)throw new Error("Maximum decoding depth exceeded");if(!e.isExtension||r.canRead()){if(e.isOptional&&0===r.readByte())return null;if(e.isArray){const t=r.readVaruint32(),n=[];for(let r=0;r<t;r++)o.codingPath.push({field:r,type:e}),n.push(i()),o.codingPath.pop();return n}return i()}function i(){const i=o.types[e.name];if(i&&i.fromABI)return i.fromABI(r);if(e.ref){o.codingPath.push({field:"",type:e.ref});const i=t(e.ref,r,o);return o.codingPath.pop(),i}if(e.fields){const n={};for(const i of e.fields)o.codingPath.push({field:i.name,type:i.type}),n[i.name]=t(i.type,r,o),o.codingPath.pop();return i?(n[ht]=!0,i.from(n)):n}if(e.variant){const n=r.readByte(),s=e.variant[n];if(!s)throw new Error("Unknown variant idx: "+n);o.codingPath.push({field:"v"+n,type:s});const a=[s.typeName,t(s,r,o)];return o.codingPath.pop(),i?i.from(a):a}throw i?new Error("Invalid type"):new Error("any"===e.name?"Unable to decode any type from binary":"Unknown type")}}(n,e,s)}if(void 0!==t.object)return yt(t.object,n,s);if(t.json)return yt(JSON.parse(t.json),n,s);throw new Error("Nothing to decode, you must set one of data, json, object")}catch(t){throw new pt(s,t)}}const ht=Symbol("Resolved");function yt(t,e,r){if(null==t){if(e.isOptional||e.isExtension)return null;throw new Error(`Unexpectedly encountered ${t} for non-optional`)}if(e.isArray){if(!Array.isArray(t))throw new Error("Expected array");const i=[],n=t.length;for(let s=0;s<n;s++)r.codingPath.push({field:s,type:e}),i.push(o(t[s])),r.codingPath.pop();return i}return o(t);function o(t){const o=r.types[e.name];if(e.ref&&!o)return yt(t,e.ref,r);if(e.fields){if("object"!=typeof t)throw new Error("Expected object");if("function"==typeof o&&t instanceof o)return t;const i={};for(const o of e.fields)r.codingPath.push({field:o.name,type:o.type}),i[o.name]=yt(t[o.name],o.type,r),r.codingPath.pop();return o?(i[ht]=!0,o.from(i)):i}if(e.variant){let i;Array.isArray(t)&&2===t.length&&"string"==typeof t[0]?(i=t[0],t=t[1]):t instanceof X?(i=t.variantName,t=t.value):i=lt(t);const n=e.variant.findIndex(t=>t.typeName===i);if(-1===n)throw new Error("Unknown variant type: "+i);const s=e.variant[n];r.codingPath.push({field:"v"+n,type:s});const a=[s.typeName,yt(t,s,r)];return r.codingPath.pop(),o?(a[ht]=!0,o.from(a)):a}if(!o){if("any"===e.name)return t;throw new Error("Unknown type")}return o.from(t)}}class mt{constructor(t){this.array=t,this.pos=0,this.textDecoder=new TextDecoder,this.metadata={},this.data=new DataView(t.buffer,t.byteOffset,t.byteLength)}canRead(t=1){return!(this.pos+t>this.array.byteLength)}ensure(t){if(!this.canRead(t))throw new Error("Read past end of buffer")}readByte(){return this.ensure(1),this.array[this.pos++]}readNum(t,e){this.ensure(t);const r=this.data,o=this.pos;let i;switch(t*(e?-1:1)){case 1:i=r.getUint8(o);break;case 2:i=r.getUint16(o,!0);break;case 4:i=r.getUint32(o,!0);break;case-1:i=r.getInt8(o);break;case-2:i=r.getInt16(o,!0);break;case-4:i=r.getInt32(o,!0);break;default:throw new Error("Invalid integer width")}return this.pos+=t,i}readBn(e,r){this.ensure(e);const o=new t(this.array.subarray(this.pos,this.pos+e),"le");return this.pos+=e,r?o.fromTwos(8*e):o}readFloat(t){let e;switch(this.ensure(t),t){case 4:e=this.data.getFloat32(this.pos,!0);break;case 8:e=this.data.getFloat64(this.pos,!0);break;default:throw new Error("Invalid float size")}return this.pos+=t,e}readVaruint32(){let t=0,e=0;for(;;){const r=this.readByte();if(t|=(127&r)<<e,e+=7,!(128&r))break}return t>>>0}readVarint32(){const t=this.readVaruint32();return 1&t?~t>>1|2147483648:t>>>1}readArray(t){this.ensure(t);const e=this.array.subarray(this.pos,this.pos+t);return this.pos+=t,e}readString(){const t=this.readVaruint32();return this.textDecoder.decode(this.readArray(t))}}function vt(t,e,r,o){var i,n=arguments.length,s=n<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,r,o);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(s=(n<3?i(s):n>3?i(e,r,s):i(e,r))||s);return n>3&&s&&Object.defineProperty(e,r,s),s}var gt;let wt=gt=class extends rt{static from(t){if("string"==typeof t){const e=t.split("@");if(2!==e.length&&e[0].length>0&&e[1].length>0)throw new Error("Invalid permission level string, should be in the format <actor>@<permission>");t={actor:e[0],permission:e[1]}}return super.from(t)}equals(t){const e=gt.from(t);return this.actor.equals(e.actor)&&this.permission.equals(e.permission)}};var bt;vt([rt.field("name")],wt.prototype,"actor",void 0),vt([rt.field("name")],wt.prototype,"permission",void 0),wt=gt=vt([rt.type("permission_level")],wt);let _t=bt=class extends rt{static from(t,e){const r=t.data;if(!q.isBytes(r)){let o;if(e)o=N.from(e).getActionType(t.name);else if(!r.constructor||void 0===r.constructor.abiName)throw new Error("Missing ABI definition when creating action with untyped action data");t={...t,data:tt({object:r,type:o,abi:e})}}return super.from(t)}equals(t){const e=bt.from(t);return this.account.equals(e.account)&&this.name.equals(e.name)&&function(t,e){const r=t.length;if(r!==e.length)return!1;for(let o=0;o<r;o++)if(!t[o].equals(e[o]))return!1;return!0}(this.authorization,e.authorization)&&this.data.equals(e.data)}decodeData(t){if("string"==typeof t||t.abiName)return ft({data:this.data,type:t});{const e=N.from(t),r=e.getActionType(this.name);if(!r)throw new Error(`Action ${this.name} does not exist in provided ABI`);return ft({data:this.data,type:r,abi:e})}}};var At;vt([rt.field("name")],_t.prototype,"account",void 0),vt([rt.field("name")],_t.prototype,"name",void 0),vt([rt.field(wt,{array:!0})],_t.prototype,"authorization",void 0),vt([rt.field("bytes")],_t.prototype,"data",void 0),_t=bt=vt([rt.type("action")],_t);let xt=class extends rt{};vt([rt.field("uint16")],xt.prototype,"type",void 0),vt([rt.field("bytes")],xt.prototype,"data",void 0),xt=vt([rt.type("transaction_extension")],xt);let kt=class extends rt{static from(t){return super.from(t)}};vt([rt.field("time_point_sec")],kt.prototype,"expiration",void 0),vt([rt.field("uint16")],kt.prototype,"ref_block_num",void 0),vt([rt.field("uint32")],kt.prototype,"ref_block_prefix",void 0),vt([rt.field("varuint32",{default:0})],kt.prototype,"max_net_usage_words",void 0),vt([rt.field("uint8",{default:0})],kt.prototype,"max_cpu_usage_ms",void 0),vt([rt.field("varuint32",{default:0})],kt.prototype,"delay_sec",void 0),kt=vt([rt.type("transaction_header")],kt);let St=At=class extends kt{static from(t,e){const r=t=>{return _t.from(t,(r=t.account,e?Array.isArray(e)?e.filter(t=>I.from(t.contract).equals(r)).map(({abi:t})=>t)[0]:e:void 0));var r},o=(t.actions||[]).map(r),i=(t.context_free_actions||[]).map(r),n={...t,context_free_actions:i,actions:o};return super.from(n)}equals(t){const e=At.from(t);return this.id.equals(e.id)}get id(){return tt({object:this}).sha256Digest}signingDigest(t){let e=q.from(E.from(t).array);return e=e.appending(tt({object:this})),e=e.appending(new Uint8Array(32)),e.sha256Digest}};vt([rt.field(_t,{array:!0,default:[]})],St.prototype,"context_free_actions",void 0),vt([rt.field(_t,{array:!0,default:[]})],St.prototype,"actions",void 0),vt([rt.field(xt,{array:!0,default:[]})],St.prototype,"transaction_extensions",void 0),St=At=vt([rt.type("transaction")],St);let It=class extends St{static from(t){return super.from(t)}};vt([rt.field("signature[]",{default:[]})],It.prototype,"signatures",void 0),vt([rt.field("bytes[]",{default:[]})],It.prototype,"context_free_data",void 0),It=vt([rt.type("signed_transaction")],It);let Nt=class extends rt{static fromSigned(t){const e=St.from(t);return this.from({signatures:t.signatures,packed_context_free_data:tt({object:t.context_free_data,type:"bytes[]"}),packed_trx:tt({object:e})})}getTransaction(){if(0!==this.compression.value)throw new Error("Transaction compression not supported yet");return ft({data:this.packed_trx,type:St})}getSignedTransaction(){const t=this.getTransaction();return It.from({...t,signatures:this.signatures})}};vt([rt.field("signature[]")],Nt.prototype,"signatures",void 0),vt([rt.field("uint8",{default:0})],Nt.prototype,"compression",void 0),vt([rt.field("bytes")],Nt.prototype,"packed_context_free_data",void 0),vt([rt.field("bytes")],Nt.prototype,"packed_trx",void 0),Nt=vt([rt.type("packed_transaction")],Nt);let Bt=class extends rt{};vt([rt.field("string")],Bt.prototype,"status",void 0),vt([rt.field("uint32")],Bt.prototype,"cpu_usage_us",void 0),vt([rt.field("uint32")],Bt.prototype,"net_usage_words",void 0),Bt=vt([rt.type("transaction_receipt")],Bt);let Et=class extends rt{};vt([rt.field("uint32")],Et.prototype,"weight",void 0),vt([rt.field(wt)],Et.prototype,"permission",void 0),Et=vt([rt.type("account_auth")],Et);let Ut=class extends rt{};vt([rt.field("uint32")],Ut.prototype,"weight",void 0),vt([rt.field("public_key")],Ut.prototype,"key",void 0),Ut=vt([rt.type("key_auth")],Ut);let Pt=class extends rt{};vt([rt.field("uint32")],Pt.prototype,"threshold",void 0),vt([rt.field(Ut,{array:!0,default:[]})],Pt.prototype,"keys",void 0),vt([rt.field(Et,{array:!0,default:[]})],Pt.prototype,"accounts",void 0),Pt=vt([rt.type("required_auth")],Pt);let qt=class extends rt{};vt([rt.field("name")],qt.prototype,"perm_name",void 0),vt([rt.field("name")],qt.prototype,"parent",void 0),vt([rt.field(Pt)],qt.prototype,"required_auth",void 0),qt=vt([rt.type("account_permission")],qt);let Wt=class extends rt{};vt([rt.field("int32")],Wt.prototype,"used",void 0),vt([rt.field("int32")],Wt.prototype,"available",void 0),vt([rt.field("int32")],Wt.prototype,"max",void 0),Wt=vt([rt.type("account_resource_limit")],Wt);let jt=class extends rt{};vt([rt.field("name")],jt.prototype,"owner",void 0),vt([rt.field("asset")],jt.prototype,"net_weight",void 0),vt([rt.field("asset")],jt.prototype,"cpu_weight",void 0),vt([rt.field("uint64")],jt.prototype,"ram_bytes",void 0),jt=vt([rt.type("account_total_resources")],jt);let Ct=class extends rt{};vt([rt.field("name")],Ct.prototype,"from",void 0),vt([rt.field("name")],Ct.prototype,"to",void 0),vt([rt.field("asset")],Ct.prototype,"net_weight",void 0),vt([rt.field("asset")],Ct.prototype,"cpu_weight",void 0),Ct=vt([rt.type("account_self_delegated_bandwidth")],Ct);let Ft=class extends rt{};vt([rt.field("name")],Ft.prototype,"owner",void 0),vt([rt.field("time_point")],Ft.prototype,"request_time",void 0),vt([rt.field("asset")],Ft.prototype,"net_amount",void 0),vt([rt.field("asset")],Ft.prototype,"cpu_amount",void 0),Ft=vt([rt.type("account_refund_request")],Ft);let Ot=class extends rt{};vt([rt.field("name")],Ot.prototype,"owner",void 0),vt([rt.field("name")],Ot.prototype,"proxy",void 0),vt([rt.field("name",{array:!0})],Ot.prototype,"producers",void 0),vt([rt.field("int64")],Ot.prototype,"staked",void 0),vt([rt.field("bool")],Ot.prototype,"is_proxy",void 0),vt([rt.field("uint32")],Ot.prototype,"flags1",void 0),vt([rt.field("uint32")],Ot.prototype,"reserved2",void 0),vt([rt.field("string")],Ot.prototype,"reserved3",void 0),Ot=vt([rt.type("account_voter_info")],Ot);let Rt=class extends rt{};vt([rt.field("time_point")],Rt.prototype,"key",void 0),vt([rt.field("int64")],Rt.prototype,"value",void 0),Rt=vt([rt.type("account_rex_info_maturities")],Rt);let Tt=class extends rt{};vt([rt.field("uint32")],Tt.prototype,"version",void 0),vt([rt.field("name")],Tt.prototype,"owner",void 0),vt([rt.field("asset")],Tt.prototype,"vote_stake",void 0),vt([rt.field("asset")],Tt.prototype,"rex_balance",void 0),vt([rt.field("int64")],Tt.prototype,"matured_rex",void 0),vt([rt.field(Rt,{array:!0})],Tt.prototype,"rex_maturities",void 0),Tt=vt([rt.type("account_rex_info")],Tt);let $t=class extends rt{};vt([rt.field("name")],$t.prototype,"account_name",void 0),vt([rt.field("uint32")],$t.prototype,"head_block_num",void 0),vt([rt.field("time_point")],$t.prototype,"head_block_time",void 0),vt([rt.field("bool")],$t.prototype,"privileged",void 0),vt([rt.field("time_point")],$t.prototype,"last_code_update",void 0),vt([rt.field("time_point")],$t.prototype,"created",void 0),vt([rt.field("asset?")],$t.prototype,"core_liquid_balance",void 0),vt([rt.field("int64")],$t.prototype,"ram_quota",void 0),vt([rt.field("int64")],$t.prototype,"net_weight",void 0),vt([rt.field("int64")],$t.prototype,"cpu_weight",void 0),vt([rt.field(Wt)],$t.prototype,"net_limit",void 0),vt([rt.field(Wt)],$t.prototype,"cpu_limit",void 0),vt([rt.field("uint64")],$t.prototype,"ram_usage",void 0),vt([rt.field(qt,{array:!0})],$t.prototype,"permissions",void 0),vt([rt.field(jt)],$t.prototype,"total_resources",void 0),vt([rt.field(Ct,{optional:!0})],$t.prototype,"self_delegated_bandwidth",void 0),vt([rt.field(Ft,{optional:!0})],$t.prototype,"refund_request",void 0),vt([rt.field(Ot,{optional:!0})],$t.prototype,"voter_info",void 0),vt([rt.field(Tt,{optional:!0})],$t.prototype,"rex_info",void 0),$t=vt([rt.type("account_object")],$t);let Dt=class extends rt{};vt([rt.field("name")],Dt.prototype,"producer_name",void 0),vt([rt.field("public_key")],Dt.prototype,"block_signing_key",void 0),Dt=vt([rt.type("new_producers_entry")],Dt);let Mt=class extends rt{};vt([rt.field("uint32")],Mt.prototype,"version",void 0),vt([rt.field(Dt,{array:!0})],Mt.prototype,"producers",void 0),Mt=vt([rt.type("new_producers")],Mt);let Vt=class extends rt{};vt([rt.field("uint16")],Vt.prototype,"type",void 0),vt([rt.field("bytes")],Vt.prototype,"data",void 0),Vt=vt([rt.type("block_extension")],Vt);let Lt=class extends rt{};vt([rt.field("uint16")],Lt.prototype,"type",void 0),vt([rt.field("bytes")],Lt.prototype,"data",void 0),Lt=vt([rt.type("header_extension")],Lt);let Jt=class extends rt{};vt([rt.field("time_point")],Jt.prototype,"timestamp",void 0),vt([rt.field("name")],Jt.prototype,"producer",void 0),vt([rt.field("uint16")],Jt.prototype,"confirmed",void 0),vt([rt.field("checksum256")],Jt.prototype,"previous",void 0),vt([rt.field("checksum256")],Jt.prototype,"transaction_mroot",void 0),vt([rt.field("checksum256")],Jt.prototype,"action_mroot",void 0),vt([rt.field("uint32")],Jt.prototype,"schedule_version",void 0),vt([rt.field(Mt,{optional:!0})],Jt.prototype,"new_producers",void 0),vt([rt.field("header_extension",{optional:!0})],Jt.prototype,"header_extensions",void 0),vt([rt.field("any",{optional:!0})],Jt.prototype,"new_protocol_features",void 0),vt([rt.field("signature")],Jt.prototype,"producer_signature",void 0),vt([rt.field(Bt,{array:!0})],Jt.prototype,"transactions",void 0),vt([rt.field("block_extension",{optional:!0})],Jt.prototype,"block_extensions",void 0),vt([rt.field("checksum256")],Jt.prototype,"id",void 0),vt([rt.field("uint32")],Jt.prototype,"block_num",void 0),vt([rt.field("uint32")],Jt.prototype,"ref_block_prefix",void 0),Jt=vt([rt.type("get_block_response")],Jt);let zt=class extends rt{};vt([rt.field("name")],zt.prototype,"producer_name",void 0),vt([rt.field("any")],zt.prototype,"authority",void 0),zt=vt([rt.type("active_schedule_producer_authority")],zt);let Kt=class extends rt{};vt([rt.field("name")],Kt.prototype,"producer_name",void 0),vt([rt.field(zt)],Kt.prototype,"authority",void 0),Kt=vt([rt.type("active_schedule_producer")],Kt);let Gt=class extends rt{};vt([rt.field("uint32")],Gt.prototype,"version",void 0),vt([rt.field(Kt,{array:!0})],Gt.prototype,"producers",void 0),Gt=vt([rt.type("active_schedule")],Gt);let Ht=class extends rt{};vt([rt.field("time_point")],Ht.prototype,"timestamp",void 0),vt([rt.field("name")],Ht.prototype,"producer",void 0),vt([rt.field("uint16")],Ht.prototype,"confirmed",void 0),vt([rt.field("checksum256")],Ht.prototype,"previous",void 0),vt([rt.field("checksum256")],Ht.prototype,"transaction_mroot",void 0),vt([rt.field("checksum256")],Ht.prototype,"action_mroot",void 0),vt([rt.field("uint32")],Ht.prototype,"schedule_version",void 0),vt([rt.field(Lt,{array:!0,optional:!0})],Ht.prototype,"header_extensions",void 0),vt([rt.field("signature")],Ht.prototype,"producer_signature",void 0),Ht=vt([rt.type("block_state_header")],Ht);let Zt=class extends rt{};vt([rt.field("uint32")],Zt.prototype,"block_num",void 0),vt([rt.field("uint32")],Zt.prototype,"dpos_proposed_irreversible_blocknum",void 0),vt([rt.field("uint32")],Zt.prototype,"dpos_irreversible_blocknum",void 0),vt([rt.field("checksum256")],Zt.prototype,"id",void 0),vt([rt.field(Ht)],Zt.prototype,"header",void 0),vt([rt.field("any")],Zt.prototype,"active_schedule",void 0),vt([rt.field("any")],Zt.prototype,"blockroot_merkle",void 0),vt([rt.field("any")],Zt.prototype,"producer_to_last_produced",void 0),vt([rt.field("any")],Zt.prototype,"producer_to_last_implied_irb",void 0),vt([rt.field("any")],Zt.prototype,"valid_block_signing_authority",void 0),vt([rt.field("any")],Zt.prototype,"confirm_count",void 0),vt([rt.field("any")],Zt.prototype,"pending_schedule",void 0),vt([rt.field("any")],Zt.prototype,"activated_protocol_features",void 0),vt([rt.field("any")],Zt.prototype,"additional_signatures",void 0),Zt=vt([rt.type("get_block_header_state_response")],Zt);let Qt=class extends rt{getTransactionHeader(t=120){const e=nt.fromMilliseconds(this.head_block_time.toMilliseconds()+1e3*t),r=this.last_irreversible_block_id.array.subarray(8,12),o=new Uint32Array(r.buffer,r.byteOffset,1)[0];return kt.from({expiration:e,ref_block_num:65535&this.last_irreversible_block_num.value,ref_block_prefix:o})}};vt([rt.field("string")],Qt.prototype,"server_version",void 0),vt([rt.field("checksum256")],Qt.prototype,"chain_id",void 0),vt([rt.field("uint32")],Qt.prototype,"head_block_num",void 0),vt([rt.field("uint32")],Qt.prototype,"last_irreversible_block_num",void 0),vt([rt.field("checksum256")],Qt.prototype,"last_irreversible_block_id",void 0),vt([rt.field("checksum256")],Qt.prototype,"head_block_id",void 0),vt([rt.field("time_point")],Qt.prototype,"head_block_time",void 0),vt([rt.field("name")],Qt.prototype,"head_block_producer",void 0),vt([rt.field("uint64")],Qt.prototype,"virtual_block_cpu_limit",void 0),vt([rt.field("uint64")],Qt.prototype,"virtual_block_net_limit",void 0),vt([rt.field("uint64")],Qt.prototype,"block_cpu_limit",void 0),vt([rt.field("uint64")],Qt.prototype,"block_net_limit",void 0),vt([rt.field("string?")],Qt.prototype,"server_version_string",void 0),vt([rt.field("uint32?")],Qt.prototype,"fork_db_head_block_num",void 0),vt([rt.field("checksum256?")],Qt.prototype,"fork_db_head_block_id",void 0),Qt=vt([rt.type("get_info_response")],Qt);var Xt={__proto__:null,get AccountAuth(){return Et},get KeyAuth(){return Ut},get RequiredAuth(){return Pt},get AccountPermission(){return qt},get AccountResourceLimit(){return Wt},get AccountTotalResources(){return jt},get AccountSelfDelegatedBandwidth(){return Ct},get AccountRefundRequest(){return Ft},get AccountVoterInfo(){return Ot},get AccountRexInfoMaturities(){return Rt},get AccountRexInfo(){return Tt},get AccountObject(){return $t},get NewProducersEntry(){return Dt},get NewProducers(){return Mt},get BlockExtension(){return Vt},get HeaderExtension(){return Lt},get GetBlockResponse(){return Jt},get ActiveScheduleProducerAuthority(){return zt},get ActiveScheduleProducer(){return Kt},get ActiveSchedule(){return Gt},get BlockStateHeader(){return Ht},get GetBlockHeaderStateResponse(){return Zt},get GetInfoResponse(){return Qt}};class Yt{constructor(t){this.client=t}async get_abi(t){return this.client.call({path:"/v1/chain/get_abi",params:{account_name:I.from(t)}})}async get_account(t){return this.client.call({path:"/v1/chain/get_account",params:{account_name:I.from(t)},responseType:$t})}async get_block(t){return this.client.call({path:"/v1/chain/get_block",params:{block_num_or_id:t},responseType:Jt})}async get_block_header_state(t){return this.client.call({path:"/v1/chain/get_block_header_state",params:{block_num_or_id:t},responseType:Zt})}async get_currency_balance(t,e,r){const o={account:I.from(e),code:I.from(t)};return r&&(o.symbol=r),this.client.call({path:"/v1/chain/get_currency_balance",params:o,responseType:"asset[]"})}async get_info(){return this.client.call({path:"/v1/chain/get_info",responseType:Qt})}async push_transaction(t){return t instanceof Nt||(t=Nt.fromSigned(It.from(t))),this.client.call({path:"/v1/chain/push_transaction",params:t})}}class te extends Error{constructor(t,e){super(`${te.formatError(e)} at ${t}`),this.path=t,this.error=e}static formatError(t){return"unspecified"===t.what&&t.details&&t.details.length>0?t.details[0].message:t.what&&t.what.length>0?t.what:"Unknown API error"}get name(){return this.error.name||"unspecified"}get code(){return this.error.code||0}get details(){return this.error.details}}class ee{constructor(t){if(this.v1={chain:new Yt(this)},t.provider)this.provider=t.provider;else{if(!t.url)throw new Error("Missing url or provider");this.provider=new s(t.url,t)}}async call(t){const e=await this.provider.call(t.path,t.params);if(e.error)throw new te(t.path,e.error);return t.responseType?ft({type:t.responseType,object:e}):e}}var re,oe={__proto__:null,v1:Xt};function ie(t,e){return!(128&t[0]||0===t[0]&&!(128&t[1])||128&e[0]||0===e[0]&&!(128&e[1]))}class ne{constructor(t,e){this.type=t,this.data=e}static from(t){if(t instanceof ne)return t;if("string"!=typeof t)throw new Error("Invalid private key");if(t.startsWith("PVT_")){const e=t.split("_");if(3!==e.length)throw new Error("Invalid private key string");const r=K.from(e[1]);let o;switch(r){case K.K1:case K.R1:o=32}const i=z.decodeRipemd160Check(e[2],o,r);return new ne(r,i)}{const e=K.K1,r=z.decodeCheck(t);if(128!==r.array[0])throw new Error("Invalid private key wif");return new ne(e,r.droppingFirst())}}static generate(t){return new ne(K.from(t),new q(function(t){return Z(t).genKeyPair().getPrivate().toArrayLike(Uint8Array,"be")}(t)))}signDigest(t){return t=E.from(t),Q.from(function(t,e,r){const o=Z(r).keyFromPrivate(t);let i,n,s;if("K1"===r){let t=1;do{i=o.sign(e,{canonical:!0,pers:[t++]}),n=i.r.toArrayLike(Uint8Array,"be",32),s=i.s.toArrayLike(Uint8Array,"be",32)}while(!ie(n,s))}else i=o.sign(e,{canonical:!0}),n=i.r.toArrayLike(Uint8Array,"be",32),s=i.s.toArrayLike(Uint8Array,"be",32);return{type:r,r:n,s,recid:i.recoveryParam||0}}(this.data.array,t.array,this.type))}signMessage(t){return this.signDigest(q.from(t).sha256Digest)}sharedSecret(t){const e=function(t,e,r){const o=Z(r),i=o.keyFromPrivate(t),n=o.keyFromPublic(e).getPublic();return i.derive(n).toArrayLike(Uint8Array,"be")}(this.data.array,t.data.array,this.type);return new q(e).sha512Digest}toPublic(){const t=function(t,e){const r=Z(e).keyFromPrivate(t).getPublic();return new Uint8Array(r.encodeCompressed())}(this.data.array,this.type);return G.from({compressed:t,type:this.type})}toWif(){if(this.type!==K.K1)throw new Error("Unable to generate WIF for non-k1 key");return z.encodeCheck(q.from([128]).appending(this.data))}toString(){return`PVT_${this.type}_${z.encodeRipemd160Check(this.data,this.type)}`}toJSON(){return this.toString()}}function se(t){return function(e){return e.abiAlias={type:Object.getPrototypeOf(e.prototype).constructor},e.abiName=t,e}}!function(t){t.encode=tt,t.decode=ft,t.synthesize=function(t){return W(t).abi}}(re||(re={}));export{N as ABI,mt as ABIDecoder,et as ABIEncoder,oe as API,ee as APIClient,te as APIError,_t as Action,$ as Asset,z as Base58,st as BlockTimestamp,q as Bytes,P as Checksum160,E as Checksum256,U as Checksum512,K as CurveType,D as ExtendedAsset,s as FetchProvider,g as Int128,y as Int16,m as Int32,v as Int64,h as Int8,I as Name,Nt as PackedTransaction,wt as PermissionLevel,ne as PrivateKey,G as PublicKey,re as Serializer,Q as Signature,It as SignedTransaction,rt as Struct,it as TimePoint,nt as TimePointSec,St as Transaction,xt as TransactionExtension,kt as TransactionHeader,Bt as TransactionReceipt,se as TypeAlias,x as UInt128,b as UInt16,_ as UInt32,A as UInt64,w as UInt8,k as VarInt,S as VarUInt,X as Variant}; | ||
//# sourceMappingURL=index.esm.js.map |
{ | ||
"name": "@greymass/eosio", | ||
"description": "Library for working with EOSIO blockchains", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"license": "BSD-3-Clause", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
@@ -262,5 +262,5 @@ import {ABI} from '../../chain/abi' | ||
/** Sequential block number representing the best known head in the fork database tree. */ | ||
@Struct.field('uint32') fork_db_head_block_num?: UInt32 | ||
@Struct.field('uint32?') fork_db_head_block_num?: UInt32 | ||
/** Hash representing the best known head in the fork database tree. */ | ||
@Struct.field('checksum256') fork_db_head_block_id?: Checksum256 | ||
@Struct.field('checksum256?') fork_db_head_block_id?: Checksum256 | ||
@@ -267,0 +267,0 @@ getTransactionHeader(secondsAhead = 120): TransactionHeader { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1052521