@ecency/sdk 2.3.12 → 2.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/hive.js +2 -2
- package/dist/browser/hive.js.map +1 -1
- package/dist/browser/index.js +3 -3
- package/dist/browser/index.js.map +1 -1
- package/dist/node/hive.cjs +2 -2
- package/dist/node/hive.cjs.map +1 -1
- package/dist/node/hive.mjs +2 -2
- package/dist/node/hive.mjs.map +1 -1
- package/dist/node/index.cjs +3 -3
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +3 -3
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/hive.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {hexToBytes,bytesToHex}from'@noble/hashes/utils.js';import {ripemd160}from'@noble/hashes/legacy.js';import we from'bs58';import {secp256k1}from'@noble/curves/secp256k1.js';import {sha256,sha512}from'@noble/hashes/sha2.js';import {cbc}from'@noble/ciphers/aes.js';var de=Object.defineProperty;var it=(n,e,t)=>e in n?de(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t;var st=(n,e)=>{for(var t in e)de(n,t,{get:e[t],enumerable:true});};var y=(n,e,t)=>it(n,typeof e!="symbol"?e+"":e,t);var W=new ArrayBuffer(0),J=null,G=null;function ot(){return J||(typeof TextEncoder<"u"?J=new TextEncoder:J={encode(n){let e=[];for(let t=0;t<n.length;t++){let r=n.charCodeAt(t);if(r<128)e.push(r);else if(r<2048)e.push(192|r>>6,128|r&63);else if(r>=55296&&r<=56319&&t+1<n.length){let i=n.charCodeAt(++t);r=65536+((r&1023)<<10)+(i&1023),e.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|r&63);}else e.push(224|r>>12,128|r>>6&63,128|r&63);}return new Uint8Array(e)}}),J}function he(){return G||(typeof TextDecoder<"u"?G=new TextDecoder:G={decode(n){let e=n instanceof ArrayBuffer?new Uint8Array(n):new Uint8Array(n.buffer,n.byteOffset,n.byteLength),t="";for(let r=0;r<e.length;){let i=e[r],s;i<128?(s=i,r+=1):(i&224)===192?(s=(i&31)<<6|e[r+1]&63,r+=2):(i&240)===224?(s=(i&15)<<12|(e[r+1]&63)<<6|e[r+2]&63,r+=3):(s=(i&7)<<18|(e[r+1]&63)<<12|(e[r+2]&63)<<6|e[r+3]&63,r+=4),s<=65535?t+=String.fromCharCode(s):(s-=65536,t+=String.fromCharCode(55296+(s>>10),56320+(s&1023)));}return t}}),G}var b=class b{constructor(e=b.DEFAULT_CAPACITY,t=b.DEFAULT_ENDIAN){y(this,"buffer");y(this,"view");y(this,"offset");y(this,"markedOffset");y(this,"limit");y(this,"littleEndian");y(this,"readUInt32",this.readUint32);this.buffer=e===0?W:new ArrayBuffer(e),this.view=e===0?new DataView(W):new DataView(this.buffer),this.offset=0,this.markedOffset=-1,this.limit=e,this.littleEndian=t;}static allocate(e,t){return new b(e,t)}static concat(e,t){let r=0;for(let u=0;u<e.length;++u){let c=e[u];if(c instanceof b)r+=c.limit-c.offset;else if(c instanceof Uint8Array)r+=c.length;else if(c instanceof ArrayBuffer)r+=c.byteLength;else if(Array.isArray(c))r+=c.length;else throw TypeError("Illegal buffer")}if(r===0)return new b(0,t);let i=new b(r,t),s=new Uint8Array(i.buffer),a=0;for(let u=0;u<e.length;++u){let c=e[u];c instanceof b?(s.set(new Uint8Array(c.buffer,c.offset,c.limit-c.offset),a),a+=c.limit-c.offset):c instanceof Uint8Array?(s.set(c,a),a+=c.length):c instanceof ArrayBuffer?(s.set(new Uint8Array(c),a),a+=c.byteLength):(s.set(c,a),a+=c.length);}return i.limit=i.offset=a,i.offset=0,i}static wrap(e,t){if(e instanceof b){let i=e.clone();return i.markedOffset=-1,i}let r;if(e instanceof Uint8Array)r=new b(0,t),e.length>0&&(r.buffer=e.buffer,r.offset=e.byteOffset,r.limit=e.byteOffset+e.byteLength,r.view=new DataView(e.buffer));else if(e instanceof ArrayBuffer)r=new b(0,t),e.byteLength>0&&(r.buffer=e,r.offset=0,r.limit=e.byteLength,r.view=e.byteLength>0?new DataView(e):new DataView(W));else if(Array.isArray(e))r=new b(e.length,t),r.limit=e.length,new Uint8Array(r.buffer).set(e);else throw TypeError("Illegal buffer");return r}writeBytes(e,t){return this.append(e,t)}writeInt8(e,t){let r=typeof t>"u";return r?t=this.offset:t=t,t+1>this.buffer.byteLength&&this.resize(t+1),this.view.setInt8(t,e),r&&(this.offset+=1),this}writeByte(e,t){return this.writeInt8(e,t)}writeUint8(e,t){let r=typeof t>"u";return r?t=this.offset:t=t,t+1>this.buffer.byteLength&&this.resize(t+1),this.view.setUint8(t,e),r&&(this.offset+=1),this}writeUInt8(e,t){return this.writeUint8(e,t)}readUint8(e){let t=typeof e>"u";t?e=this.offset:e=e;let r=this.view.getUint8(e);return t&&(this.offset+=1),r}readUInt8(e){return this.readUint8(e)}writeInt16(e,t){let r=typeof t>"u";return r?t=this.offset:t=t,t+2>this.buffer.byteLength&&this.resize(t+2),this.view.setInt16(t,e,this.littleEndian),r&&(this.offset+=2),this}writeShort(e,t){return this.writeInt16(e,t)}writeUint16(e,t){let r=typeof t>"u";return r?t=this.offset:t=t,t+2>this.buffer.byteLength&&this.resize(t+2),this.view.setUint16(t,e,this.littleEndian),r&&(this.offset+=2),this}writeUInt16(e,t){return this.writeUint16(e,t)}writeInt32(e,t){let r=typeof t>"u";return r?t=this.offset:t=t,t+4>this.buffer.byteLength&&this.resize(t+4),this.view.setInt32(t,e,this.littleEndian),r&&(this.offset+=4),this}writeInt(e,t){return this.writeInt32(e,t)}writeUint32(e,t){let r=typeof t>"u";return r?t=this.offset:t=t,t+4>this.buffer.byteLength&&this.resize(t+4),this.view.setUint32(t,e,this.littleEndian),r&&(this.offset+=4),this}writeUInt32(e,t){return this.writeUint32(e,t)}readUint32(e){let t=typeof e>"u";t?e=this.offset:e=e;let r=this.view.getUint32(e,this.littleEndian);return t&&(this.offset+=4),r}append(e,t){let r=typeof t>"u";r?t=this.offset:t=t;let i;return e instanceof b?(i=new Uint8Array(e.buffer,e.offset,e.limit-e.offset),e.offset+=i.length):e instanceof Uint8Array?i=e:e instanceof ArrayBuffer?i=new Uint8Array(e):i=new Uint8Array(e),i.length<=0?this:(t+i.length>this.buffer.byteLength&&this.resize(t+i.length),new Uint8Array(this.buffer).set(i,t),r&&(this.offset+=i.length),this)}clone(e){let t=new b(0,this.littleEndian);return e?(t.buffer=new ArrayBuffer(this.buffer.byteLength),new Uint8Array(t.buffer).set(new Uint8Array(this.buffer)),t.view=new DataView(t.buffer)):(t.buffer=this.buffer,t.view=this.view),t.offset=this.offset,t.markedOffset=this.markedOffset,t.limit=this.limit,t}copy(e,t){if(e===void 0&&(e=this.offset),t===void 0&&(t=this.limit),e===t)return new b(0,this.littleEndian);let r=t-e,i=new b(r,this.littleEndian);return i.offset=0,i.limit=r,new Uint8Array(i.buffer).set(new Uint8Array(this.buffer).subarray(e,t),0),i}copyTo(e,t,r,i){let s=typeof t>"u",a=typeof r>"u";t=s?e.offset:t,r=a?this.offset:r,i=i===void 0?this.limit:i;let u=i-r;return u===0?e:(e.ensureCapacity(t+u),new Uint8Array(e.buffer).set(new Uint8Array(this.buffer).subarray(r,i),t),a&&(this.offset+=u),s&&(e.offset+=u),this)}ensureCapacity(e){let t=this.buffer.byteLength;return t<e?this.resize((t*=2)>e?t:e):this}flip(){return this.limit=this.offset,this.offset=0,this}resize(e){if(this.buffer.byteLength<e){let t=new ArrayBuffer(e);new Uint8Array(t).set(new Uint8Array(this.buffer)),this.buffer=t,this.view=new DataView(t);}return this}skip(e){return this.offset+=e,this}writeInt64(e,t){let r=typeof t>"u";return r?t=this.offset:t=t,typeof e=="number"&&(e=BigInt(e)),t+8>this.buffer.byteLength&&this.resize(t+8),this.view.setBigInt64(t,e,this.littleEndian),r&&(this.offset+=8),this}writeLong(e,t){return this.writeInt64(e,t)}readInt64(e){let t=typeof e>"u";t?e=this.offset:e=e;let r=this.view.getBigInt64(e,this.littleEndian);return t&&(this.offset+=8),r}readLong(e){return this.readInt64(e)}writeUint64(e,t){let r=typeof t>"u";return r?t=this.offset:t=t,typeof e=="number"&&(e=BigInt(e)),t+8>this.buffer.byteLength&&this.resize(t+8),this.view.setBigUint64(t,e,this.littleEndian),r&&(this.offset+=8),this}writeUInt64(e,t){return this.writeUint64(e,t)}readUint64(e){let t=typeof e>"u";t?e=this.offset:e=e;let r=this.view.getBigUint64(e,this.littleEndian);return t&&(this.offset+=8),r}readUInt64(e){return this.readUint64(e)}toBuffer(e){let t=this.offset,r=this.limit;return !e&&t===0&&r===this.buffer.byteLength?this.buffer:t===r?W:this.buffer.slice(t,r)}toArrayBuffer(e){return this.toBuffer(e)}writeVarint32(e,t){let r=typeof t>"u";r?t=this.offset:t=t;let i=this.calculateVarint32(e);for(t+i>this.buffer.byteLength&&this.resize(t+i),e>>>=0;e>=128;)this.view.setUint8(t++,e&127|128),e>>>=7;return this.view.setUint8(t++,e),r?(this.offset=t,this):i}readVarint32(e){let t=typeof e>"u";typeof e>"u"&&(e=this.offset);let r=0,i=0,s;do s=this.view.getUint8(e++),r<5&&(i|=(s&127)<<7*r),++r;while((s&128)!==0);return i|=0,t?(this.offset=e,i):{value:i,length:r}}calculateVarint32(e){return e=e>>>0,e<128?1:e<16384?2:e<1<<21?3:e<1<<28?4:5}writeVString(e,t){let r=typeof t>"u",i=r?this.offset:t,s=ot().encode(e),a=s.length,u=this.calculateVarint32(a);return i+u+a>this.buffer.byteLength&&this.resize(i+u+a),this.writeVarint32(a,i),i+=u,new Uint8Array(this.buffer).set(s,i),i+=a,r?(this.offset=i,this):i-(t||0)}readVString(e){let t=typeof e>"u";t?e=this.offset:e=e;let r=e,i=this.readVarint32(e),s=i.value,a=i.length;e+=a;let u=he().decode(new Uint8Array(this.buffer,e,s));return e+=s,t?(this.offset=e,u):{string:u,length:e-r}}readUTF8String(e,t){let r=typeof t>"u";r?t=this.offset:t=t;let i=he().decode(new Uint8Array(this.buffer,t,e));return r?(this.offset+=e,i):{string:i,length:e}}};y(b,"LITTLE_ENDIAN",true),y(b,"BIG_ENDIAN",false),y(b,"DEFAULT_CAPACITY",16),y(b,"DEFAULT_ENDIAN",b.BIG_ENDIAN);var _=b;var w={nodes:["https://api.hive.blog","https://api.deathwing.me","https://api.openhive.network","https://techcoderx.com","https://api.syncad.com","https://rpc.mahdiyari.info"],restNodes:["https://hapi.ecency.com","https://api.hive.blog","https://rpc.mahdiyari.info","https://techcoderx.com","https://hiveapi.actifit.io","https://api.c0ff33a.uk"],restNodesByApi:{hivesense:["https://api.hive.blog","https://api.syncad.com"]},chain_id:"beeab0de00000000000000000000000000000000000000000000000000000000",address_prefix:"STM",timeout:5e3,broadcastTimeout:15e3,retry:5},at=n=>{let e=[...new Set(n.map(t=>t.trim()).filter(t=>t.length>0&&/^https?:\/\/.+/.test(t)))];e.length&&(w.nodes=e);};var M=class n{constructor(e,t,r){y(this,"data");y(this,"recovery");y(this,"compressed");this.data=e,this.recovery=t,this.compressed=r??true;}static from(e){if(typeof e=="string"){let t=hexToBytes(e),r=parseInt(bytesToHex(t.subarray(0,1)),16)-31,i=true;r<0&&(i=false,r=r+4);let s=t.subarray(1);return new n(s,r,i)}else throw new Error("Expected string for data")}toBuffer(){let e=new Uint8Array(65).fill(0);return this.compressed?e[0]=this.recovery+31&255:e[0]=this.recovery+27&255,e.set(this.data,1),e}customToString(){return bytesToHex(this.toBuffer())}toString(){return this.customToString()}getPublicKey(e){if(e instanceof Uint8Array&&e.length!==32||typeof e=="string"&&e.length!==64)throw new Error("Expected a valid sha256 hash as message");typeof e=="string"&&(e=hexToBytes(e));let t=secp256k1.Signature.fromBytes(this.data,"compact"),r=new secp256k1.Signature(t.r,t.s,this.recovery);return new S(r.recoverPublicKey(e).toBytes())}};var S=class n{constructor(e,t){y(this,"key");y(this,"prefix");this.key=e,this.prefix=t??w.address_prefix;}static fromString(e){let t=w.address_prefix;if(typeof e!="string"||e.length<=t.length)throw new Error("Invalid public key");let r=e.slice(0,t.length);if(r!==t)throw new Error(`Public key must start with ${t}`);let i;try{i=we.decode(e.slice(t.length));}catch{throw new Error("Invalid public key encoding")}if(i.length!==37)throw new Error("Invalid public key length");let s=i.subarray(0,33),a=i.subarray(33,37),u=ripemd160(s).subarray(0,4);if(!ut(a,u))throw new Error("Public key checksum mismatch");try{secp256k1.Point.fromBytes(s);}catch{throw new Error("Invalid public key")}return new n(s,r)}static from(e){return e instanceof n?e:n.fromString(e)}verify(e,t){return typeof t=="string"&&(t=M.from(t)),secp256k1.verify(t.data,e,this.key,{prehash:false,format:"compact"})}toString(){return ct(this.key,this.prefix)}toJSON(){return this.toString()}inspect(){return `PublicKey: ${this.toString()}`}},ct=(n,e)=>{let t=ripemd160(n);return e+we.encode(new Uint8Array([...n,...t.subarray(0,4)]))},ut=(n,e)=>{if(n.byteLength!==e.byteLength)return false;for(let t=0;t<n.byteLength;t++)if(n[t]!==e[t])return false;return true};var Q=class n{constructor(e,t){y(this,"amount");y(this,"symbol");this.amount=e,this.symbol=t==="HIVE"?"STEEM":t==="HBD"?"SBD":t;}static fromString(e,t=null){let[r,i]=e.split(" ");if(["STEEM","VESTS","SBD","TESTS","TBD","HIVE","HBD"].indexOf(i)===-1)throw new Error(`Invalid asset symbol: ${i}`);if(t&&i!==t)throw new Error(`Invalid asset, expected symbol: ${t} got: ${i}`);let s=Number.parseFloat(r);if(!Number.isFinite(s))throw new Error(`Invalid asset amount: ${r}`);return new n(s,i)}static from(e,t){if(e instanceof n){if(t&&e.symbol!==t)throw new Error(`Invalid asset, expected symbol: ${t} got: ${e.symbol}`);return e}else {if(typeof e=="number"&&Number.isFinite(e))return new n(e,t||"STEEM");if(typeof e=="string")return n.fromString(e,t);throw new Error(`Invalid asset '${String(e)}'`)}}getPrecision(){switch(this.symbol){case "TESTS":case "TBD":case "STEEM":case "SBD":case "HBD":case "HIVE":return 3;case "VESTS":return 6;default:return 3}}toString(){return `${this.amount.toFixed(this.getPrecision())} ${this.symbol}`}toJSON(){return this.toString()}};var X=class n{constructor(e){y(this,"buffer");this.buffer=e;}static from(e){return e instanceof n?e:e instanceof Uint8Array?new n(e):typeof e=="string"?new n(hexToBytes(e)):new n(new Uint8Array(e))}toString(){return bytesToHex(this.buffer)}toJSON(){return this.toString()}};var h={vote:0,comment:1,transfer:2,transfer_to_vesting:3,withdraw_vesting:4,limit_order_create:5,limit_order_cancel:6,feed_publish:7,convert:8,account_create:9,account_update:10,witness_update:11,account_witness_vote:12,account_witness_proxy:13,custom:15,delete_comment:17,custom_json:18,comment_options:19,set_withdraw_vesting_route:20,limit_order_create2:21,claim_account:22,create_claimed_account:23,request_account_recovery:24,recover_account:25,change_recovery_account:26,escrow_transfer:27,escrow_dispute:28,escrow_release:29,escrow_approve:31,transfer_to_savings:32,transfer_from_savings:33,cancel_transfer_from_savings:34,decline_voting_rights:36,reset_account:37,set_reset_account:38,claim_reward_balance:39,delegate_vesting_shares:40,account_create_with_delegation:41,witness_set_properties:42,account_update2:43,create_proposal:44,update_proposal_votes:45,remove_proposal:46,update_proposal:47,collateralized_convert:48,recurrent_transfer:49},I=()=>{throw new Error("Void can not be serialized")},o=(n,e)=>{n.writeVString(e);},dt=(n,e)=>{n.writeInt16(e);},Ae=(n,e)=>{n.writeInt64(e);},be=(n,e)=>{n.writeUint8(e);},P=(n,e)=>{n.writeUint16(e);},U=(n,e)=>{n.writeUint32(e);},Be=(n,e)=>{n.writeUint64(e);},C=(n,e)=>{n.writeByte(e?1:0);},ve=n=>(e,t)=>{let[r,i]=t;e.writeVarint32(r),n[r](e,i);},g=(n,e)=>{let t=Q.from(e),r=t.getPrecision();n.writeInt64(Math.round(t.amount*Math.pow(10,r))),n.writeUint8(r);for(let i=0;i<7;i++)n.writeUint8(t.symbol.charCodeAt(i)||0);},z=(n,e)=>{n.writeUint32(Math.floor(new Date(e+"Z").getTime()/1e3));},N=(n,e)=>{e===null||typeof e=="string"&&e.slice(-39)==="1111111111111111111111111111111114T1Anm"?n.append(new Uint8Array(33).fill(0)):n.append(S.from(e).key);},xe=(n=null)=>(e,t)=>{t=X.from(t);let r=t.buffer.length;if(n){if(r!==n)throw new Error(`Unable to serialize binary. Expected ${n} bytes, got ${r}`)}else e.writeVarint32(r);e.append(t.buffer);},Se=xe(),se=(n,e)=>(t,r)=>{t.writeVarint32(r.length);for(let[i,s]of r)n(t,i),e(t,s);},A=n=>(e,t)=>{e.writeVarint32(t.length);for(let r of t)n(e,r);},k=n=>(e,t)=>{for(let[r,i]of n)try{i(e,t[r]);}catch(s){throw s.message=`${r}: ${s.message}`,s}},K=n=>(e,t)=>{t!==void 0?(e.writeByte(1),n(e,t)):e.writeByte(0);},x=k([["weight_threshold",U],["account_auths",se(o,P)],["key_auths",se(N,P)]]),ht=k([["account",o],["weight",P]]),oe=k([["base",g],["quote",g]]),mt=k([["account_creation_fee",g],["maximum_block_size",U],["hbd_interest_rate",P]]),m=(n,e)=>{let t=k(e);return (r,i)=>{r.writeVarint32(n),t(r,i);}},d={};d.account_create=m(h.account_create,[["fee",g],["creator",o],["new_account_name",o],["owner",x],["active",x],["posting",x],["memo_key",N],["json_metadata",o]]);d.account_create_with_delegation=m(h.account_create_with_delegation,[["fee",g],["delegation",g],["creator",o],["new_account_name",o],["owner",x],["active",x],["posting",x],["memo_key",N],["json_metadata",o],["extensions",A(I)]]);d.account_update=m(h.account_update,[["account",o],["owner",K(x)],["active",K(x)],["posting",K(x)],["memo_key",N],["json_metadata",o]]);d.account_witness_proxy=m(h.account_witness_proxy,[["account",o],["proxy",o]]);d.account_witness_vote=m(h.account_witness_vote,[["account",o],["witness",o],["approve",C]]);d.cancel_transfer_from_savings=m(h.cancel_transfer_from_savings,[["from",o],["request_id",U]]);d.change_recovery_account=m(h.change_recovery_account,[["account_to_recover",o],["new_recovery_account",o],["extensions",A(I)]]);d.claim_account=m(h.claim_account,[["creator",o],["fee",g],["extensions",A(I)]]);d.claim_reward_balance=m(h.claim_reward_balance,[["account",o],["reward_hive",g],["reward_hbd",g],["reward_vests",g]]);d.comment=m(h.comment,[["parent_author",o],["parent_permlink",o],["author",o],["permlink",o],["title",o],["body",o],["json_metadata",o]]);d.comment_options=m(h.comment_options,[["author",o],["permlink",o],["max_accepted_payout",g],["percent_hbd",P],["allow_votes",C],["allow_curation_rewards",C],["extensions",A(ve([k([["beneficiaries",A(ht)]])]))]]);d.convert=m(h.convert,[["owner",o],["requestid",U],["amount",g]]);d.create_claimed_account=m(h.create_claimed_account,[["creator",o],["new_account_name",o],["owner",x],["active",x],["posting",x],["memo_key",N],["json_metadata",o],["extensions",A(I)]]);d.custom=m(h.custom,[["required_auths",A(o)],["id",P],["data",Se]]);d.custom_json=m(h.custom_json,[["required_auths",A(o)],["required_posting_auths",A(o)],["id",o],["json",o]]);d.decline_voting_rights=m(h.decline_voting_rights,[["account",o],["decline",C]]);d.delegate_vesting_shares=m(h.delegate_vesting_shares,[["delegator",o],["delegatee",o],["vesting_shares",g]]);d.delete_comment=m(h.delete_comment,[["author",o],["permlink",o]]);d.escrow_approve=m(h.escrow_approve,[["from",o],["to",o],["agent",o],["who",o],["escrow_id",U],["approve",C]]);d.escrow_dispute=m(h.escrow_dispute,[["from",o],["to",o],["agent",o],["who",o],["escrow_id",U]]);d.escrow_release=m(h.escrow_release,[["from",o],["to",o],["agent",o],["who",o],["receiver",o],["escrow_id",U],["hbd_amount",g],["hive_amount",g]]);d.escrow_transfer=m(h.escrow_transfer,[["from",o],["to",o],["hbd_amount",g],["hive_amount",g],["escrow_id",U],["agent",o],["fee",g],["json_meta",o],["ratification_deadline",z],["escrow_expiration",z]]);d.feed_publish=m(h.feed_publish,[["publisher",o],["exchange_rate",oe]]);d.limit_order_cancel=m(h.limit_order_cancel,[["owner",o],["orderid",U]]);d.limit_order_create=m(h.limit_order_create,[["owner",o],["orderid",U],["amount_to_sell",g],["min_to_receive",g],["fill_or_kill",C],["expiration",z]]);d.limit_order_create2=m(h.limit_order_create2,[["owner",o],["orderid",U],["amount_to_sell",g],["exchange_rate",oe],["fill_or_kill",C],["expiration",z]]);d.recover_account=m(h.recover_account,[["account_to_recover",o],["new_owner_authority",x],["recent_owner_authority",x],["extensions",A(I)]]);d.request_account_recovery=m(h.request_account_recovery,[["recovery_account",o],["account_to_recover",o],["new_owner_authority",x],["extensions",A(I)]]);d.reset_account=m(h.reset_account,[["reset_account",o],["account_to_reset",o],["new_owner_authority",x]]);d.set_reset_account=m(h.set_reset_account,[["account",o],["current_reset_account",o],["reset_account",o]]);d.set_withdraw_vesting_route=m(h.set_withdraw_vesting_route,[["from_account",o],["to_account",o],["percent",P],["auto_vest",C]]);d.transfer=m(h.transfer,[["from",o],["to",o],["amount",g],["memo",o]]);d.transfer_from_savings=m(h.transfer_from_savings,[["from",o],["request_id",U],["to",o],["amount",g],["memo",o]]);d.transfer_to_savings=m(h.transfer_to_savings,[["from",o],["to",o],["amount",g],["memo",o]]);d.transfer_to_vesting=m(h.transfer_to_vesting,[["from",o],["to",o],["amount",g]]);d.vote=m(h.vote,[["voter",o],["author",o],["permlink",o],["weight",dt]]);d.withdraw_vesting=m(h.withdraw_vesting,[["account",o],["vesting_shares",g]]);d.witness_update=m(h.witness_update,[["owner",o],["url",o],["block_signing_key",N],["props",mt],["fee",g]]);d.witness_set_properties=m(h.witness_set_properties,[["owner",o],["props",se(o,Se)],["extensions",A(I)]]);d.account_update2=m(h.account_update2,[["account",o],["owner",K(x)],["active",K(x)],["posting",K(x)],["memo_key",K(N)],["json_metadata",o],["posting_json_metadata",o],["extensions",A(I)]]);d.create_proposal=m(h.create_proposal,[["creator",o],["receiver",o],["start_date",z],["end_date",z],["daily_pay",g],["subject",o],["permlink",o],["extensions",A(I)]]);d.update_proposal_votes=m(h.update_proposal_votes,[["voter",o],["proposal_ids",A(Ae)],["approve",C],["extensions",A(I)]]);d.remove_proposal=m(h.remove_proposal,[["proposal_owner",o],["proposal_ids",A(Ae)],["extensions",A(I)]]);var yt=k([["end_date",z]]);d.update_proposal=m(h.update_proposal,[["proposal_id",Be],["creator",o],["daily_pay",g],["subject",o],["permlink",o],["extensions",A(ve([I,yt]))]]);d.collateralized_convert=m(h.collateralized_convert,[["owner",o],["requestid",U],["amount",g]]);d.recurrent_transfer=m(h.recurrent_transfer,[["from",o],["to",o],["amount",g],["memo",o],["recurrence",P],["executions",P],["extensions",A(k([["type",be],["value",k([["pair_id",be]])]]))]]);var pt=(n,e)=>{let t=d[e[0]];if(!t)throw new Error(`No serializer for operation: ${e[0]}`);try{t(n,e[1]);}catch(r){throw r.message=`${e[0]}: ${r.message}`,r}},gt=k([["ref_block_num",P],["ref_block_prefix",U],["expiration",z],["operations",A(pt)],["extensions",A(o)]]),_t=k([["from",N],["to",N],["nonce",Be],["check",U],["encrypted",xe()]]),L={Asset:g,Memo:_t,Price:oe,PublicKey:N,String:o,Transaction:gt,UInt16:P,UInt32:U};var j=n=>new Promise(e=>setTimeout(e,n));var D=class extends Error{constructor(t){super(t.message);y(this,"name","RPCError");y(this,"data");y(this,"code");y(this,"stack");this.code=t.code,"data"in t&&(this.data=t.data);}},V=class extends Error{constructor(t,r,i=0){super(r);y(this,"node");y(this,"rateLimitMs");this.node=t,this.rateLimitMs=i;}},wt=["ECONNREFUSED","ENOTFOUND","EHOSTUNREACH","EAI_AGAIN"],bt=["Failed to fetch","NetworkError when attempting to fetch","Load failed","fetch failed"];function At(n){if(!n)return "";let e=[String(n.name||""),String(n.message||""),String(n.code||"")],t=n.cause;for(let r=0;t&&r<5;r++)e.push(String(t.code||""),String(t.message||"")),t=t.cause;return e.join(" ")}function Bt(n){if(!n)return false;if(n instanceof V)return true;if(n instanceof D)return false;let e=At(n);return !!(wt.some(t=>e.includes(t))||bt.some(t=>e.includes(t))||n instanceof SyntaxError||/Unexpected token|JSON\.parse|Unexpected end of JSON/i.test(e))}function vt(n,e){return !!(n===-32603||n<=-32e3&&n>=-32099||n===-32601||n===-32602&&/unable to parse|endpoint data|internal/i.test(e))}function Ie(n){let e=n.indexOf(".");return e>0?n.slice(0,e):n}var xt=2,St=6e4,Ue=12e4,Ut=30,Ee=.3,Et=3,Te=5*6e4,Tt=6e4,It=1e3,Pt=2e3,kt=700,Lt=2.5,Nt=new Set(["hapi.ecency.com","api.ecency.com"]);function Dt(n){try{return Nt.has(new URL(n).hostname)}catch{return false}}var Z=class{constructor(){y(this,"health",new Map);}getOrCreate(e){let t=this.health.get(e);return t||(t={consecutiveFailures:0,lastFailureTime:0,rateLimitedUntil:0,apiFailures:new Map,headBlock:0,headBlockUpdatedAt:0,ewmaLatencyMs:void 0,latencySampleCount:0,latencyUpdatedAt:0,lastProbeAt:0},this.health.set(e,t)),t}recordSuccess(e,t,r){let i=this.getOrCreate(e);i.consecutiveFailures=0,t&&i.apiFailures.delete(t),typeof r=="number"&&Number.isFinite(r)&&r>=0&&this.recordLatency(i,r);}recordSlowFailure(e,t){!Number.isFinite(t)||t<Pt||this.recordLatency(this.getOrCreate(e),t);}recordLatency(e,t){let r=Date.now();e.latencyUpdatedAt>0&&r-e.latencyUpdatedAt>Te&&(e.ewmaLatencyMs=void 0,e.latencySampleCount=0),e.ewmaLatencyMs=e.ewmaLatencyMs===void 0?t:Ee*t+(1-Ee)*e.ewmaLatencyMs,e.latencySampleCount++,e.latencyUpdatedAt=r;}recordFailure(e,t){let r=this.getOrCreate(e);if(t){let i=Date.now(),s=r.apiFailures.get(t)??{count:0,cooldownUntil:0,lastFailureTime:0};(s.cooldownUntil>0&&s.cooldownUntil<=i||s.lastFailureTime>0&&i-s.lastFailureTime>3e4)&&(s.count=0,s.cooldownUntil=0),s.count++,s.lastFailureTime=i,s.count>=xt&&(s.cooldownUntil=i+St),r.apiFailures.set(t,s);}else r.consecutiveFailures++,r.lastFailureTime=Date.now();}recordRateLimit(e,t=1e4){let r=this.getOrCreate(e);r.rateLimitedUntil=Date.now()+t,r.consecutiveFailures++,r.lastFailureTime=Date.now();}recordHeadBlock(e,t){if(!t||!Number.isFinite(t))return;let r=this.getOrCreate(e);r.headBlock=t,r.headBlockUpdatedAt=Date.now();}consensusHeadBlock(){let e=Date.now(),t=[];for(let r of this.health.values())r.headBlock>0&&e-r.headBlockUpdatedAt<=Ue&&t.push(r.headBlock);return t.length<2?0:(t.sort((r,i)=>r-i),t[Math.floor((t.length-1)/2)])}isNodeHealthy(e,t){let r=this.health.get(e);if(!r)return true;let i=Date.now();if(r.rateLimitedUntil>i||r.consecutiveFailures>=3&&i-r.lastFailureTime<3e4)return false;if(t){let a=r.apiFailures.get(t);if(a&&a.cooldownUntil>i)return false}let s=this.consensusHeadBlock();return !(s>0&&r.headBlock>0&&i-r.headBlockUpdatedAt<=Ue&&s-r.headBlock>Ut)}getOrderedNodes(e,t){let r=[],i=[];for(let f of e)this.isNodeHealthy(f,t)?r.push(f):i.push(f);if(r.length<=1)return [...r,...i];let s=Date.now(),a=this.fastestUsableLatency(r,s),u=r.map((f,l)=>({node:f,i:l,score:this.scoreNode(f,a,s)})).sort((f,l)=>f.score-l.score||f.i-l.i).map(f=>f.node),c=this.pickReprobeCandidate(r,s);return c&&u[0]!==c?[c,...u.filter(f=>f!==c),...i]:[...u,...i]}isLatencyUsable(e,t){return !!e&&e.ewmaLatencyMs!==void 0&&e.latencySampleCount>=Et&&t-e.latencyUpdatedAt<=Te}fastestUsableLatency(e,t){let r=1/0;for(let i of e){let s=this.health.get(i);this.isLatencyUsable(s,t)&&(r=Math.min(r,s.ewmaLatencyMs));}return r}scoreNode(e,t,r){let i=this.health.get(e);if(!this.isLatencyUsable(i,r))return It;let s=i.ewmaLatencyMs;return Dt(e)?t>0&&t!==1/0&&s>Lt*t?s:Math.max(s-kt,0):s}pickReprobeCandidate(e,t){let r=t-Tt,i,s=1/0;for(let a of e){let u=this.getOrCreate(a),c=Math.max(u.latencyUpdatedAt,u.lastProbeAt);c<=r&&c<s&&(i=a,s=c);}return i&&(this.getOrCreate(i).lastProbeAt=t),i}},F=new Z,H=new Z;function Pe(n,e,t,r){t instanceof V?t.rateLimitMs>0?n.recordRateLimit(e,t.rateLimitMs):n.recordFailure(e,r):t instanceof D?n.recordFailure(e,r):n.recordFailure(e);}function Ot(n,e,t,r){if(!r||typeof r!="object"||!t.includes("get_dynamic_global_properties"))return;let i=r.head_block_number;typeof i=="number"&&n.recordHeadBlock(e,i);}function Ct(){if(typeof DOMException<"u")return new DOMException("The operation was aborted due to timeout","TimeoutError");let n=new Error("The operation was aborted due to timeout");return n.name="TimeoutError",n}function ke(n){if(typeof AbortSignal.timeout=="function")return {signal:AbortSignal.timeout(n),cleanup:()=>{}};let e=new AbortController,t=setTimeout(()=>e.abort(Ct()),n);return {signal:e.signal,cleanup:()=>clearTimeout(t)}}function Le(n,e){if(!e)return {signal:n,cleanup:()=>{}};if(typeof AbortSignal.any=="function")return {signal:AbortSignal.any([n,e]),cleanup:()=>{}};let t=new AbortController;if(n.aborted)return t.abort(n.reason),{signal:t.signal,cleanup:()=>{}};if(e.aborted)return t.abort(e.reason),{signal:t.signal,cleanup:()=>{}};let r=()=>t.abort(n.reason),i=()=>t.abort(e.reason);n.addEventListener("abort",r,{once:true}),e.addEventListener("abort",i,{once:true});let s=()=>{n.removeEventListener("abort",r),e.removeEventListener("abort",i);};return {signal:t.signal,cleanup:s}}var ee=async(n,e,t,r=w.timeout,i=false,s)=>{let a=Math.floor(Math.random()*1e8),u={jsonrpc:"2.0",method:e,params:t,id:a},{signal:c,cleanup:f}=ke(r),{signal:l,cleanup:E}=Le(c,s),p=()=>{f(),E();};try{let v=await fetch(n,{method:"POST",body:JSON.stringify(u),headers:{"Content-Type":"application/json"},signal:l});if(v.status===429){let O=v.headers.get("Retry-After"),Y=O?parseInt(O,10)*1e3:1e4;throw new V(n,"HTTP 429 Rate Limited",Y)}if(v.status>=500&&v.status<600)throw new V(n,`HTTP ${v.status} from ${n}`);let T=await v.json();if(!T||typeof T.id>"u"||T.id!==a||T.jsonrpc!=="2.0")throw new Error("JSONRPC id mismatch");if("result"in T)return T.result;if("error"in T){let O=T.error;throw "message"in O&&"code"in O?new D(O):T.error}throw T}catch(v){if(v instanceof D||v instanceof V||s?.aborted)throw v;if(i)return ee(n,e,t,r,false,s);throw v}finally{p();}};function Ne(){return j(50+Math.random()*50)}var te=async(n,e=[],t=w.timeout,r=w.retry,i)=>{if(!Array.isArray(w.nodes))throw new Error("config.nodes is not an array");if(w.nodes.length===0)throw new Error("config.nodes is empty");let s=Ie(n),a=new Set,u;for(let c=0;c<=r;c++){let f=F.getOrderedNodes(w.nodes,s),l=f.find(p=>!a.has(p));l||(a.clear(),l=f[0]),a.add(l);let E=Date.now();try{let p=await ee(l,n,e,t,!1,i);return F.recordSuccess(l,s,Date.now()-E),Ot(F,l,n,p),p}catch(p){if(p instanceof D&&!vt(p.code,p.message)||i?.aborted)throw p;Pe(F,l,p,s),F.recordSlowFailure(l,Date.now()-E),u=p,c<r&&await Ne();}}throw u},ae=async(n,e=[],t=w.broadcastTimeout,r)=>{if(!Array.isArray(w.nodes))throw new Error("config.nodes is not an array");if(w.nodes.length===0)throw new Error("config.nodes is empty");let i=Ie(n),s=new Set,a;for(let u=0;u<w.nodes.length;u++){let f=F.getOrderedNodes(w.nodes,i).find(l=>!s.has(l));if(!f)break;if(s.add(f),r?.aborted)throw new Error("Aborted");try{let l=await ee(f,n,e,t,!1,r);return F.recordSuccess(f,i),l}catch(l){if(l instanceof D||r?.aborted||(Pe(F,f,l,i),a=l,!Bt(l)))throw l}}throw a},Rt={balance:"/balance-api",hafah:"/hafah-api",hafbe:"/hafbe-api",hivemind:"/hivemind-api",hivesense:"/hivesense-api",reputation:"/reputation-api","nft-tracker":"/nft-tracker-api",hafsql:"/hafsql",status:"/status-api"};async function zt(n,e,t,r=w.timeout,i=w.retry,s){if(!Array.isArray(w.restNodes))throw new Error("config.restNodes is not an array");if(w.restNodes.length===0)throw new Error("config.restNodes is empty");let a=w.restNodesByApi?.[n]?.length?w.restNodesByApi[n]:w.restNodes,u=new Set,c,f=false;for(let l=0;l<=i;l++){let E=H.getOrderedNodes(a,n),p=E.find(B=>!u.has(B));p||(u.clear(),p=E[0]),u.add(p);let v=p+Rt[n],T=e,O=t||{},Y=new Set;Object.entries(O).forEach(([B,R])=>{T.includes(`{${B}}`)&&(T=T.replace(`{${B}}`,encodeURIComponent(String(R))),Y.add(B));});let ne=new URL(v+T);if(Object.entries(O).forEach(([B,R])=>{Y.has(B)||(Array.isArray(R)?R.forEach(ie=>ne.searchParams.append(B,String(ie))):ne.searchParams.set(B,String(R)));}),s?.aborted)throw new Error("Aborted");f=false;let{signal:Ze,cleanup:et}=ke(r),{signal:tt,cleanup:rt}=Le(Ze,s),nt=()=>{et(),rt();},le=Date.now();try{let B=await fetch(ne.toString(),{signal:tt});if(B.status===404)throw new Error("HTTP 404 - Hint: can happen on wrong params");if(B.status===429){let R=B.headers.get("Retry-After"),ie=R?parseInt(R,10)*1e3:1e4;throw H.recordRateLimit(p,ie),f=!0,new Error(`HTTP 429 Rate Limited by ${p}`)}if(B.status===503)throw H.recordFailure(p,n),f=!0,new Error(`HTTP 503 Service Unavailable from ${p}`);if(!B.ok)throw H.recordFailure(p,n),f=!0,new Error(`HTTP ${B.status} from ${p}`);return H.recordSuccess(p,n,Date.now()-le),B.json()}catch(B){if(B?.message?.includes("HTTP 404"))throw B;f||H.recordFailure(p,n),H.recordSlowFailure(p,Date.now()-le),c=B,l<i&&await Ne();}finally{nt();}}throw c}var Ft=async(n,e=[],t=2,r)=>{if(!Array.isArray(w.nodes))throw new Error("config.nodes is not an Array");if(t>w.nodes.length)throw new Error("quorum > config.nodes.length");let s=(c=>{let f=[...c];for(let l=f.length-1;l>0;l--){let E=Math.floor(Math.random()*(l+1));[f[l],f[E]]=[f[E],f[l]];}return f})(w.nodes),a=Math.min(t,s.length),u=[];for(;a>0&&s.length>0;){let c=s.splice(0,a),f=[],l=[];for(let p=0;p<c.length;p++)f.push(ee(c[p],n,e,void 0,true,r).then(v=>l.push(v)).catch(()=>{}));await Promise.all(f),u.push(...l);let E=Mt(u,t);if(E)return E;if(a=Math.min(t,s.length),a===0)throw new Error("No more nodes available.")}throw new Error("Couldn't reach quorum.")};function Mt(n,e){let t=new Map;for(let i of n){let s=JSON.stringify(i);t.has(s)||t.set(s,[]),t.get(s).push(i);}let r=Array.from(t.values()).find(i=>i.length>=e);return r?r[0]:null}var Ht=hexToBytes(w.chain_id),ce=class n{constructor(e){y(this,"transaction");y(this,"expiration",6e4);y(this,"txId");y(this,"createTransaction",async e=>{let t=await te("condenser_api.get_dynamic_global_properties",[]),r=hexToBytes(t.head_block_id),i=Number(new Uint32Array(r.buffer,r.byteOffset+4,1)[0]),s=new Date(Date.now()+e).toISOString().slice(0,-5);this.transaction={expiration:s,extensions:[],operations:[],ref_block_num:t.head_block_number&65535,ref_block_prefix:i,signatures:[]};});e?.transaction&&(e.transaction instanceof n?(this.transaction=e.transaction.transaction,this.expiration=e.transaction.expiration):this.transaction=e.transaction,this.txId=this.digest().txId),e?.expiration&&(this.expiration=e.expiration);}async addOperation(e,t){this.transaction||await this.createTransaction(this.expiration),this.transaction.operations.push([e,t]);}sign(e){if(!this.transaction)throw new Error("First create a transaction by .addOperation()");if(this.transaction){let{digest:t,txId:r}=this.digest();Array.isArray(e)||(e=[e]);for(let i of e){let s=i.sign(t);this.transaction.signatures.push(s.customToString());}return this.txId=r,this.transaction}else throw new Error("No transaction to sign")}async broadcast(e=false){if(!this.transaction)throw new Error("Attempted to broadcast an empty transaction. Add operations by .addOperation()");if(this.transaction.signatures.length===0)throw new Error("Attempted to broadcast a transaction with no signatures. Sign using .sign(keys)");try{await ae("condenser_api.broadcast_transaction",[this.transaction]);}catch(s){if(!(s instanceof D&&s.message.includes("Duplicate transaction check failed")))throw s}if(this.txId||(this.txId=this.digest().txId),!e)return {tx_id:this.txId,status:"unknown"};let t=60;await j(1e3);let r=await this.checkStatus(),i=1;for(;r?.status!=="within_irreversible_block"&&r?.status!=="expired_irreversible"&&r?.status!=="too_old"&&i<t;)await j(1e3+i*300),r=await this.checkStatus(),i++;return {tx_id:this.txId,status:r?.status??"unknown"}}digest(){if(!this.transaction)throw new Error("First create a transaction by .addOperation()");let e=new _(_.DEFAULT_CAPACITY,_.LITTLE_ENDIAN),t={...this.transaction};try{L.Transaction(e,t);}catch(a){throw new Error("Unable to serialize transaction: "+a)}e.flip();let r=new Uint8Array(e.toBuffer()),i=bytesToHex(sha256(r)).slice(0,40);return {digest:sha256(new Uint8Array([...Ht,...r])),txId:i}}addSignature(e){if(!this.transaction)throw new Error("First create a transaction by .create(operations)");if(typeof e!="string")throw new Error("Signature must be string");if(e.length!==130)throw new Error("Signature must be 130 characters long");return this.transaction.signatures.push(e),this.transaction}async checkStatus(){return this.txId||(this.txId=this.digest().txId),te("transaction_status_api.find_transaction",{transaction_id:this.txId,expiration:this.transaction?.expiration})}};var Fe=new Uint8Array([128]),q=class n{constructor(e){y(this,"key");this.key=e;try{secp256k1.getPublicKey(e);}catch{throw new Error("invalid private key")}}static from(e){return typeof e=="string"?n.fromString(e):new n(e)}static fromString(e){return new n(qt(e).subarray(1))}static fromSeed(e){if(typeof e=="string")if(/^[0-9a-fA-F]+$/.test(e))e=hexToBytes(e);else {let r=[];for(let i=0;i<e.length;i++){let s=e.charCodeAt(i);if(s<128)r.push(s);else if(s<2048)r.push(192|s>>6,128|s&63);else if(s>=55296&&s<=56319&&i+1<e.length){let a=e.charCodeAt(++i);s=65536+((s&1023)<<10)+(a&1023),r.push(240|s>>18,128|s>>12&63,128|s>>6&63,128|s&63);}else r.push(224|s>>12,128|s>>6&63,128|s&63);}e=new Uint8Array(r);}return new n(sha256(e))}static fromLogin(e,t,r="active"){let i=e+r+t;return n.fromSeed(i)}sign(e){let t=secp256k1.sign(e,this.key,{extraEntropy:true,format:"recovered",prehash:false}),r=parseInt(bytesToHex(t.subarray(0,1)),16);return M.from((r+31).toString(16)+bytesToHex(t.subarray(1)))}createPublic(e){return new S(secp256k1.getPublicKey(this.key),e)}toString(){return $t(new Uint8Array([...Fe,...this.key]))}inspect(){let e=this.toString();return `PrivateKey: ${e.slice(0,6)}...${e.slice(-6)}`}getSharedSecret(e){let t=secp256k1.getSharedSecret(this.key,e.key);return sha512(t.subarray(1))}static randomKey(){return new n(secp256k1.keygen().secretKey)}},Me=n=>sha256(sha256(n)),$t=n=>{let e=Me(n);return we.encode(new Uint8Array([...n,...e.slice(0,4)]))},qt=n=>{let e=we.decode(n);if(!Re(e.slice(0,1),Fe))throw new Error("Private key network id mismatch");let t=e.slice(-4),r=e.slice(0,-4),i=Me(r).slice(0,4);if(!Re(t,i))throw new Error("Private key checksum mismatch");return r},Re=(n,e)=>{if(n===e)return true;if(n.byteLength!==e.byteLength)return false;let t=n.byteLength,r=0;for(;r<t&&n[r]===e[r];)r++;return r===t};var He=(n,e,t,r=Xt())=>je(n,e,r,t),Ve=(n,e,t,r,i)=>je(n,e,t,r,i).message,je=(n,e,t,r,i)=>{let s=t,a=n.getSharedSecret(e),u=new _(_.DEFAULT_CAPACITY,_.LITTLE_ENDIAN);u.writeUint64(s),u.append(a),u.flip();let c=sha512(new Uint8Array(u.toBuffer())),f=c.subarray(32,48),l=c.subarray(0,32),E=sha256(c).subarray(0,4),p=new _(_.DEFAULT_CAPACITY,_.LITTLE_ENDIAN);p.append(E),p.flip();let v=p.readUint32();if(i!==void 0){if(v!==i)throw new Error("Invalid key");r=Gt(r,l,f);}else r=Qt(r,l,f);return {nonce:s,message:r,checksum:v}},Gt=(n,e,t)=>{let r=n;return r=cbc(e,t).decrypt(r),r},Qt=(n,e,t)=>{let r=n;return r=cbc(e,t).encrypt(r),r},fe=null,Xt=()=>{if(fe===null){let t=secp256k1.utils.randomSecretKey();fe=t[0]<<8|t[1];}let n=BigInt(Date.now()),e=++fe%65536;return n=n<<BigInt(16)|BigInt(e),n};var $e=n=>{let e=ir(n,33);return new S(e)},er=n=>n.readUint64(),tr=n=>n.readUint32(),rr=n=>{let e=n.readVarint32(),t=n.copy(n.offset,n.offset+e);return n.skip(e),new Uint8Array(t.toBuffer())},nr=n=>e=>{let t={},r=new _(_.DEFAULT_CAPACITY,_.LITTLE_ENDIAN);r.append(e),r.flip();for(let[i,s]of n)try{t[i]=s(r);}catch(a){throw a.message=`${i}: ${a.message}`,a}return t};function ir(n,e){if(n){let t=n.copy(n.offset,n.offset+e);return n.skip(e),new Uint8Array(t.toBuffer())}else throw Error("No buffer found on first parameter")}var sr=nr([["from",$e],["to",$e],["nonce",er],["check",tr],["encrypted",rr]]),qe={Memo:sr};var We=(n,e,t,r)=>{if(!t.startsWith("#"))return t;t=t.substring(1),Ge(),n=Qe(n),e=or(e);let i=new _(_.DEFAULT_CAPACITY,_.LITTLE_ENDIAN);i.writeVString(t);let s=new Uint8Array(i.copy(0,i.offset).toBuffer()),{nonce:a,message:u,checksum:c}=He(n,e,s,r),f=new _(_.DEFAULT_CAPACITY,_.LITTLE_ENDIAN);L.Memo(f,{check:c,encrypted:u,from:n.createPublic(),nonce:a,to:e}),f.flip();let l=new Uint8Array(f.toBuffer());return "#"+we.encode(l)},Je=(n,e)=>{if(!e.startsWith("#"))return e;e=e.substring(1),Ge(),n=Qe(n);let t=qe.Memo(we.decode(e)),{from:r,to:i,nonce:s,check:a,encrypted:u}=t,f=n.createPublic().toString()===new S(r.key).toString()?new S(i.key):new S(r.key);t=Ve(n,f,s,u,a);let l=new _(_.DEFAULT_CAPACITY,_.LITTLE_ENDIAN);return l.append(t),l.flip(),"#"+l.readVString()},re,Ge=()=>{if(re===void 0){let n;re=true;try{let e="5JdeC9P7Pbd1uGdFVEsJ41EkEnADbbHGq6p1BwFxm6txNBsQnsw",r=We(e,"STM8m5UgaFAAYQRuaNejYdS8FVLVp9Ss3K1qAVk5de6F8s3HnVbvA","#memo\u7231");n=Je(e,r);}finally{re=n==="#memo\u7231";}}if(re===false)throw new Error("This environment does not support encryption.")},Qe=n=>typeof n=="string"?q.fromString(n):n,or=n=>typeof n=="string"?S.fromString(n):n,ar={decode:Je,encode:We};var Xe={};st(Xe,{buildWitnessSetProperties:()=>hr,makeBitMaskFilter:()=>lr,operations:()=>fr,validateUsername:()=>ur});var ur=n=>{let e="Account name should ";if(!n)return e+"not be empty.";let t=n.length;if(t<3)return e+"be longer.";if(t>16)return e+"be shorter.";/\./.test(n)&&(e="Each account segment should ");let r=n.split("."),i=r.length;for(let s=0;s<i;s++){let a=r[s];if(!/^[a-z]/.test(a))return e+"start with a lowercase letter.";if(!/^[a-z0-9-]*$/.test(a))return e+"have only lowercase letters, digits, or dashes.";if(!/[a-z0-9]$/.test(a))return e+"end with a lowercase letter or digit.";if(a.length<3)return e+"be longer."}return null},fr={vote:0,comment:1,transfer:2,transfer_to_vesting:3,withdraw_vesting:4,limit_order_create:5,limit_order_cancel:6,feed_publish:7,convert:8,account_create:9,account_update:10,witness_update:11,account_witness_vote:12,account_witness_proxy:13,pow:14,custom:15,report_over_production:16,delete_comment:17,custom_json:18,comment_options:19,set_withdraw_vesting_route:20,limit_order_create2:21,claim_account:22,create_claimed_account:23,request_account_recovery:24,recover_account:25,change_recovery_account:26,escrow_transfer:27,escrow_dispute:28,escrow_release:29,pow2:30,escrow_approve:31,transfer_to_savings:32,transfer_from_savings:33,cancel_transfer_from_savings:34,custom_binary:35,decline_voting_rights:36,reset_account:37,set_reset_account:38,claim_reward_balance:39,delegate_vesting_shares:40,account_create_with_delegation:41,witness_set_properties:42,account_update2:43,create_proposal:44,update_proposal_votes:45,remove_proposal:46,update_proposal:47,collateralized_convert:48,recurrent_transfer:49,fill_convert_request:50,author_reward:51,curation_reward:52,comment_reward:53,liquidity_reward:54,interest:55,fill_vesting_withdraw:56,fill_order:57,shutdown_witness:58,fill_transfer_from_savings:59,hardfork:60,comment_payout_update:61,return_vesting_delegation:62,comment_benefactor_reward:63,producer_reward:64,clear_null_account_balance:65,proposal_pay:66,sps_fund:67,hardfork_hive:68,hardfork_hive_restore:69,delayed_voting:70,consolidate_treasury_balance:71,effective_comment_vote:72,ineffective_delete_comment:73,sps_convert:74,expired_account_notification:75,changed_recovery_account:76,transfer_to_vesting_completed:77,pow_reward:78,vesting_shares_split:79,account_created:80,fill_collateralized_convert_request:81,system_warning:82,fill_recurrent_transfer:83,failed_recurrent_transfer:84,limit_order_cancelled:85,producer_missed:86,proposal_fee:87,collateralized_convert_immediate_conversion:88,escrow_approved:89,escrow_rejected:90,proxy_cleared:91,declined_voting_rights:92},lr=n=>n.reduce(dr,[BigInt(0),BigInt(0)]).map(e=>e!==BigInt(0)?e.toString():null),dr=([n,e],t)=>t<64?[n|BigInt(1)<<BigInt(t),e]:[n,e|BigInt(1)<<BigInt(t-64)],hr=(n,e)=>{let t={extensions:[],owner:n,props:[]};for(let r of Object.keys(e)){if(e[r]===void 0)continue;let i;switch(r){case "key":case "new_signing_key":i=L.PublicKey;break;case "account_subsidy_budget":case "account_subsidy_decay":case "maximum_block_size":i=L.UInt32;break;case "hbd_interest_rate":i=L.UInt16;break;case "url":i=L.String;break;case "hbd_exchange_rate":i=L.Price;break;case "account_creation_fee":i=L.Asset;break;default:throw new Error(`Unknown witness prop: ${r}`)}t.props.push([r,mr(i,e[r])]);}return t.props.sort((r,i)=>r[0].localeCompare(i[0])),["witness_set_properties",t]},mr=(n,e)=>{let t=new _(_.DEFAULT_CAPACITY,_.LITTLE_ENDIAN);return n(t,e),t.flip(),bytesToHex(new Uint8Array(t.toBuffer()))};/**
|
|
1
|
+
import {hexToBytes,bytesToHex}from'@noble/hashes/utils.js';import {ripemd160}from'@noble/hashes/legacy.js';import Ae from'bs58';import {secp256k1}from'@noble/curves/secp256k1.js';import {sha256,sha512}from'@noble/hashes/sha2.js';import {cbc}from'@noble/ciphers/aes.js';var me=Object.defineProperty;var ft=(n,e,t)=>e in n?me(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t;var lt=(n,e)=>{for(var t in e)me(n,t,{get:e[t],enumerable:true});};var y=(n,e,t)=>ft(n,typeof e!="symbol"?e+"":e,t);var W=new ArrayBuffer(0),J=null,G=null;function dt(){return J||(typeof TextEncoder<"u"?J=new TextEncoder:J={encode(n){let e=[];for(let t=0;t<n.length;t++){let r=n.charCodeAt(t);if(r<128)e.push(r);else if(r<2048)e.push(192|r>>6,128|r&63);else if(r>=55296&&r<=56319&&t+1<n.length){let i=n.charCodeAt(++t);r=65536+((r&1023)<<10)+(i&1023),e.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|r&63);}else e.push(224|r>>12,128|r>>6&63,128|r&63);}return new Uint8Array(e)}}),J}function ye(){return G||(typeof TextDecoder<"u"?G=new TextDecoder:G={decode(n){let e=n instanceof ArrayBuffer?new Uint8Array(n):new Uint8Array(n.buffer,n.byteOffset,n.byteLength),t="";for(let r=0;r<e.length;){let i=e[r],o;i<128?(o=i,r+=1):(i&224)===192?(o=(i&31)<<6|e[r+1]&63,r+=2):(i&240)===224?(o=(i&15)<<12|(e[r+1]&63)<<6|e[r+2]&63,r+=3):(o=(i&7)<<18|(e[r+1]&63)<<12|(e[r+2]&63)<<6|e[r+3]&63,r+=4),o<=65535?t+=String.fromCharCode(o):(o-=65536,t+=String.fromCharCode(55296+(o>>10),56320+(o&1023)));}return t}}),G}var A=class A{constructor(e=A.DEFAULT_CAPACITY,t=A.DEFAULT_ENDIAN){y(this,"buffer");y(this,"view");y(this,"offset");y(this,"markedOffset");y(this,"limit");y(this,"littleEndian");y(this,"readUInt32",this.readUint32);this.buffer=e===0?W:new ArrayBuffer(e),this.view=e===0?new DataView(W):new DataView(this.buffer),this.offset=0,this.markedOffset=-1,this.limit=e,this.littleEndian=t;}static allocate(e,t){return new A(e,t)}static concat(e,t){let r=0;for(let u=0;u<e.length;++u){let c=e[u];if(c instanceof A)r+=c.limit-c.offset;else if(c instanceof Uint8Array)r+=c.length;else if(c instanceof ArrayBuffer)r+=c.byteLength;else if(Array.isArray(c))r+=c.length;else throw TypeError("Illegal buffer")}if(r===0)return new A(0,t);let i=new A(r,t),o=new Uint8Array(i.buffer),a=0;for(let u=0;u<e.length;++u){let c=e[u];c instanceof A?(o.set(new Uint8Array(c.buffer,c.offset,c.limit-c.offset),a),a+=c.limit-c.offset):c instanceof Uint8Array?(o.set(c,a),a+=c.length):c instanceof ArrayBuffer?(o.set(new Uint8Array(c),a),a+=c.byteLength):(o.set(c,a),a+=c.length);}return i.limit=i.offset=a,i.offset=0,i}static wrap(e,t){if(e instanceof A){let i=e.clone();return i.markedOffset=-1,i}let r;if(e instanceof Uint8Array)r=new A(0,t),e.length>0&&(r.buffer=e.buffer,r.offset=e.byteOffset,r.limit=e.byteOffset+e.byteLength,r.view=new DataView(e.buffer));else if(e instanceof ArrayBuffer)r=new A(0,t),e.byteLength>0&&(r.buffer=e,r.offset=0,r.limit=e.byteLength,r.view=e.byteLength>0?new DataView(e):new DataView(W));else if(Array.isArray(e))r=new A(e.length,t),r.limit=e.length,new Uint8Array(r.buffer).set(e);else throw TypeError("Illegal buffer");return r}writeBytes(e,t){return this.append(e,t)}writeInt8(e,t){let r=typeof t>"u";return r?t=this.offset:t=t,t+1>this.buffer.byteLength&&this.resize(t+1),this.view.setInt8(t,e),r&&(this.offset+=1),this}writeByte(e,t){return this.writeInt8(e,t)}writeUint8(e,t){let r=typeof t>"u";return r?t=this.offset:t=t,t+1>this.buffer.byteLength&&this.resize(t+1),this.view.setUint8(t,e),r&&(this.offset+=1),this}writeUInt8(e,t){return this.writeUint8(e,t)}readUint8(e){let t=typeof e>"u";t?e=this.offset:e=e;let r=this.view.getUint8(e);return t&&(this.offset+=1),r}readUInt8(e){return this.readUint8(e)}writeInt16(e,t){let r=typeof t>"u";return r?t=this.offset:t=t,t+2>this.buffer.byteLength&&this.resize(t+2),this.view.setInt16(t,e,this.littleEndian),r&&(this.offset+=2),this}writeShort(e,t){return this.writeInt16(e,t)}writeUint16(e,t){let r=typeof t>"u";return r?t=this.offset:t=t,t+2>this.buffer.byteLength&&this.resize(t+2),this.view.setUint16(t,e,this.littleEndian),r&&(this.offset+=2),this}writeUInt16(e,t){return this.writeUint16(e,t)}writeInt32(e,t){let r=typeof t>"u";return r?t=this.offset:t=t,t+4>this.buffer.byteLength&&this.resize(t+4),this.view.setInt32(t,e,this.littleEndian),r&&(this.offset+=4),this}writeInt(e,t){return this.writeInt32(e,t)}writeUint32(e,t){let r=typeof t>"u";return r?t=this.offset:t=t,t+4>this.buffer.byteLength&&this.resize(t+4),this.view.setUint32(t,e,this.littleEndian),r&&(this.offset+=4),this}writeUInt32(e,t){return this.writeUint32(e,t)}readUint32(e){let t=typeof e>"u";t?e=this.offset:e=e;let r=this.view.getUint32(e,this.littleEndian);return t&&(this.offset+=4),r}append(e,t){let r=typeof t>"u";r?t=this.offset:t=t;let i;return e instanceof A?(i=new Uint8Array(e.buffer,e.offset,e.limit-e.offset),e.offset+=i.length):e instanceof Uint8Array?i=e:e instanceof ArrayBuffer?i=new Uint8Array(e):i=new Uint8Array(e),i.length<=0?this:(t+i.length>this.buffer.byteLength&&this.resize(t+i.length),new Uint8Array(this.buffer).set(i,t),r&&(this.offset+=i.length),this)}clone(e){let t=new A(0,this.littleEndian);return e?(t.buffer=new ArrayBuffer(this.buffer.byteLength),new Uint8Array(t.buffer).set(new Uint8Array(this.buffer)),t.view=new DataView(t.buffer)):(t.buffer=this.buffer,t.view=this.view),t.offset=this.offset,t.markedOffset=this.markedOffset,t.limit=this.limit,t}copy(e,t){if(e===void 0&&(e=this.offset),t===void 0&&(t=this.limit),e===t)return new A(0,this.littleEndian);let r=t-e,i=new A(r,this.littleEndian);return i.offset=0,i.limit=r,new Uint8Array(i.buffer).set(new Uint8Array(this.buffer).subarray(e,t),0),i}copyTo(e,t,r,i){let o=typeof t>"u",a=typeof r>"u";t=o?e.offset:t,r=a?this.offset:r,i=i===void 0?this.limit:i;let u=i-r;return u===0?e:(e.ensureCapacity(t+u),new Uint8Array(e.buffer).set(new Uint8Array(this.buffer).subarray(r,i),t),a&&(this.offset+=u),o&&(e.offset+=u),this)}ensureCapacity(e){let t=this.buffer.byteLength;return t<e?this.resize((t*=2)>e?t:e):this}flip(){return this.limit=this.offset,this.offset=0,this}resize(e){if(this.buffer.byteLength<e){let t=new ArrayBuffer(e);new Uint8Array(t).set(new Uint8Array(this.buffer)),this.buffer=t,this.view=new DataView(t);}return this}skip(e){return this.offset+=e,this}writeInt64(e,t){let r=typeof t>"u";return r?t=this.offset:t=t,typeof e=="number"&&(e=BigInt(e)),t+8>this.buffer.byteLength&&this.resize(t+8),this.view.setBigInt64(t,e,this.littleEndian),r&&(this.offset+=8),this}writeLong(e,t){return this.writeInt64(e,t)}readInt64(e){let t=typeof e>"u";t?e=this.offset:e=e;let r=this.view.getBigInt64(e,this.littleEndian);return t&&(this.offset+=8),r}readLong(e){return this.readInt64(e)}writeUint64(e,t){let r=typeof t>"u";return r?t=this.offset:t=t,typeof e=="number"&&(e=BigInt(e)),t+8>this.buffer.byteLength&&this.resize(t+8),this.view.setBigUint64(t,e,this.littleEndian),r&&(this.offset+=8),this}writeUInt64(e,t){return this.writeUint64(e,t)}readUint64(e){let t=typeof e>"u";t?e=this.offset:e=e;let r=this.view.getBigUint64(e,this.littleEndian);return t&&(this.offset+=8),r}readUInt64(e){return this.readUint64(e)}toBuffer(e){let t=this.offset,r=this.limit;return !e&&t===0&&r===this.buffer.byteLength?this.buffer:t===r?W:this.buffer.slice(t,r)}toArrayBuffer(e){return this.toBuffer(e)}writeVarint32(e,t){let r=typeof t>"u";r?t=this.offset:t=t;let i=this.calculateVarint32(e);for(t+i>this.buffer.byteLength&&this.resize(t+i),e>>>=0;e>=128;)this.view.setUint8(t++,e&127|128),e>>>=7;return this.view.setUint8(t++,e),r?(this.offset=t,this):i}readVarint32(e){let t=typeof e>"u";typeof e>"u"&&(e=this.offset);let r=0,i=0,o;do o=this.view.getUint8(e++),r<5&&(i|=(o&127)<<7*r),++r;while((o&128)!==0);return i|=0,t?(this.offset=e,i):{value:i,length:r}}calculateVarint32(e){return e=e>>>0,e<128?1:e<16384?2:e<1<<21?3:e<1<<28?4:5}writeVString(e,t){let r=typeof t>"u",i=r?this.offset:t,o=dt().encode(e),a=o.length,u=this.calculateVarint32(a);return i+u+a>this.buffer.byteLength&&this.resize(i+u+a),this.writeVarint32(a,i),i+=u,new Uint8Array(this.buffer).set(o,i),i+=a,r?(this.offset=i,this):i-(t||0)}readVString(e){let t=typeof e>"u";t?e=this.offset:e=e;let r=e,i=this.readVarint32(e),o=i.value,a=i.length;e+=a;let u=ye().decode(new Uint8Array(this.buffer,e,o));return e+=o,t?(this.offset=e,u):{string:u,length:e-r}}readUTF8String(e,t){let r=typeof t>"u";r?t=this.offset:t=t;let i=ye().decode(new Uint8Array(this.buffer,t,e));return r?(this.offset+=e,i):{string:i,length:e}}};y(A,"LITTLE_ENDIAN",true),y(A,"BIG_ENDIAN",false),y(A,"DEFAULT_CAPACITY",16),y(A,"DEFAULT_ENDIAN",A.BIG_ENDIAN);var g=A;var w={nodes:["https://api.hive.blog","https://api.deathwing.me","https://api.openhive.network","https://techcoderx.com","https://api.syncad.com","https://rpc.mahdiyari.info"],restNodes:["https://hapi.ecency.com","https://api.hive.blog","https://rpc.mahdiyari.info","https://techcoderx.com","https://hiveapi.actifit.io","https://api.c0ff33a.uk"],restNodesByApi:{hivesense:["https://api.hive.blog","https://api.syncad.com"]},chain_id:"beeab0de00000000000000000000000000000000000000000000000000000000",address_prefix:"STM",timeout:5e3,broadcastTimeout:15e3,retry:5},ht=n=>{let e=[...new Set(n.map(t=>t.trim()).filter(t=>t.length>0&&/^https?:\/\/.+/.test(t)))];e.length&&(w.nodes=e);};var F=class n{constructor(e,t,r){y(this,"data");y(this,"recovery");y(this,"compressed");this.data=e,this.recovery=t,this.compressed=r??true;}static from(e){if(typeof e=="string"){let t=hexToBytes(e),r=parseInt(bytesToHex(t.subarray(0,1)),16)-31,i=true;r<0&&(i=false,r=r+4);let o=t.subarray(1);return new n(o,r,i)}else throw new Error("Expected string for data")}toBuffer(){let e=new Uint8Array(65).fill(0);return this.compressed?e[0]=this.recovery+31&255:e[0]=this.recovery+27&255,e.set(this.data,1),e}customToString(){return bytesToHex(this.toBuffer())}toString(){return this.customToString()}getPublicKey(e){if(e instanceof Uint8Array&&e.length!==32||typeof e=="string"&&e.length!==64)throw new Error("Expected a valid sha256 hash as message");typeof e=="string"&&(e=hexToBytes(e));let t=secp256k1.Signature.fromBytes(this.data,"compact"),r=new secp256k1.Signature(t.r,t.s,this.recovery);return new S(r.recoverPublicKey(e).toBytes())}};var S=class n{constructor(e,t){y(this,"key");y(this,"prefix");this.key=e,this.prefix=t??w.address_prefix;}static fromString(e){let t=w.address_prefix;if(typeof e!="string"||e.length<=t.length)throw new Error("Invalid public key");let r=e.slice(0,t.length);if(r!==t)throw new Error(`Public key must start with ${t}`);let i;try{i=Ae.decode(e.slice(t.length));}catch{throw new Error("Invalid public key encoding")}if(i.length!==37)throw new Error("Invalid public key length");let o=i.subarray(0,33),a=i.subarray(33,37),u=ripemd160(o).subarray(0,4);if(!yt(a,u))throw new Error("Public key checksum mismatch");try{secp256k1.Point.fromBytes(o);}catch{throw new Error("Invalid public key")}return new n(o,r)}static from(e){return e instanceof n?e:n.fromString(e)}verify(e,t){return typeof t=="string"&&(t=F.from(t)),secp256k1.verify(t.data,e,this.key,{prehash:false,format:"compact"})}toString(){return mt(this.key,this.prefix)}toJSON(){return this.toString()}inspect(){return `PublicKey: ${this.toString()}`}},mt=(n,e)=>{let t=ripemd160(n);return e+Ae.encode(new Uint8Array([...n,...t.subarray(0,4)]))},yt=(n,e)=>{if(n.byteLength!==e.byteLength)return false;for(let t=0;t<n.byteLength;t++)if(n[t]!==e[t])return false;return true};var Q=class n{constructor(e,t){y(this,"amount");y(this,"symbol");this.amount=e,this.symbol=t==="HIVE"?"STEEM":t==="HBD"?"SBD":t;}static fromString(e,t=null){let[r,i]=e.split(" ");if(["STEEM","VESTS","SBD","TESTS","TBD","HIVE","HBD"].indexOf(i)===-1)throw new Error(`Invalid asset symbol: ${i}`);if(t&&i!==t)throw new Error(`Invalid asset, expected symbol: ${t} got: ${i}`);let o=Number.parseFloat(r);if(!Number.isFinite(o))throw new Error(`Invalid asset amount: ${r}`);return new n(o,i)}static from(e,t){if(e instanceof n){if(t&&e.symbol!==t)throw new Error(`Invalid asset, expected symbol: ${t} got: ${e.symbol}`);return e}else {if(typeof e=="number"&&Number.isFinite(e))return new n(e,t||"STEEM");if(typeof e=="string")return n.fromString(e,t);throw new Error(`Invalid asset '${String(e)}'`)}}getPrecision(){switch(this.symbol){case "TESTS":case "TBD":case "STEEM":case "SBD":case "HBD":case "HIVE":return 3;case "VESTS":return 6;default:return 3}}toString(){return `${this.amount.toFixed(this.getPrecision())} ${this.symbol}`}toJSON(){return this.toString()}};var X=class n{constructor(e){y(this,"buffer");this.buffer=e;}static from(e){return e instanceof n?e:e instanceof Uint8Array?new n(e):typeof e=="string"?new n(hexToBytes(e)):new n(new Uint8Array(e))}toString(){return bytesToHex(this.buffer)}toJSON(){return this.toString()}};var h={vote:0,comment:1,transfer:2,transfer_to_vesting:3,withdraw_vesting:4,limit_order_create:5,limit_order_cancel:6,feed_publish:7,convert:8,account_create:9,account_update:10,witness_update:11,account_witness_vote:12,account_witness_proxy:13,custom:15,delete_comment:17,custom_json:18,comment_options:19,set_withdraw_vesting_route:20,limit_order_create2:21,claim_account:22,create_claimed_account:23,request_account_recovery:24,recover_account:25,change_recovery_account:26,escrow_transfer:27,escrow_dispute:28,escrow_release:29,escrow_approve:31,transfer_to_savings:32,transfer_from_savings:33,cancel_transfer_from_savings:34,decline_voting_rights:36,reset_account:37,set_reset_account:38,claim_reward_balance:39,delegate_vesting_shares:40,account_create_with_delegation:41,witness_set_properties:42,account_update2:43,create_proposal:44,update_proposal_votes:45,remove_proposal:46,update_proposal:47,collateralized_convert:48,recurrent_transfer:49},I=()=>{throw new Error("Void can not be serialized")},s=(n,e)=>{n.writeVString(e);},gt=(n,e)=>{n.writeInt16(e);},ve=(n,e)=>{n.writeInt64(e);},Be=(n,e)=>{n.writeUint8(e);},P=(n,e)=>{n.writeUint16(e);},U=(n,e)=>{n.writeUint32(e);},xe=(n,e)=>{n.writeUint64(e);},C=(n,e)=>{n.writeByte(e?1:0);},Se=n=>(e,t)=>{let[r,i]=t;e.writeVarint32(r),n[r](e,i);},_=(n,e)=>{let t=Q.from(e),r=t.getPrecision();n.writeInt64(Math.round(t.amount*Math.pow(10,r))),n.writeUint8(r);for(let i=0;i<7;i++)n.writeUint8(t.symbol.charCodeAt(i)||0);},z=(n,e)=>{n.writeUint32(Math.floor(new Date(e+"Z").getTime()/1e3));},N=(n,e)=>{e===null||typeof e=="string"&&e.slice(-39)==="1111111111111111111111111111111114T1Anm"?n.append(new Uint8Array(33).fill(0)):n.append(S.from(e).key);},Ue=(n=null)=>(e,t)=>{t=X.from(t);let r=t.buffer.length;if(n){if(r!==n)throw new Error(`Unable to serialize binary. Expected ${n} bytes, got ${r}`)}else e.writeVarint32(r);e.append(t.buffer);},Ee=Ue(),oe=(n,e)=>(t,r)=>{t.writeVarint32(r.length);for(let[i,o]of r)n(t,i),e(t,o);},B=n=>(e,t)=>{e.writeVarint32(t.length);for(let r of t)n(e,r);},k=n=>(e,t)=>{for(let[r,i]of n)try{i(e,t[r]);}catch(o){throw o.message=`${r}: ${o.message}`,o}},K=n=>(e,t)=>{t!==void 0?(e.writeByte(1),n(e,t)):e.writeByte(0);},x=k([["weight_threshold",U],["account_auths",oe(s,P)],["key_auths",oe(N,P)]]),wt=k([["account",s],["weight",P]]),se=k([["base",_],["quote",_]]),bt=k([["account_creation_fee",_],["maximum_block_size",U],["hbd_interest_rate",P]]),m=(n,e)=>{let t=k(e);return (r,i)=>{r.writeVarint32(n),t(r,i);}},d={};d.account_create=m(h.account_create,[["fee",_],["creator",s],["new_account_name",s],["owner",x],["active",x],["posting",x],["memo_key",N],["json_metadata",s]]);d.account_create_with_delegation=m(h.account_create_with_delegation,[["fee",_],["delegation",_],["creator",s],["new_account_name",s],["owner",x],["active",x],["posting",x],["memo_key",N],["json_metadata",s],["extensions",B(I)]]);d.account_update=m(h.account_update,[["account",s],["owner",K(x)],["active",K(x)],["posting",K(x)],["memo_key",N],["json_metadata",s]]);d.account_witness_proxy=m(h.account_witness_proxy,[["account",s],["proxy",s]]);d.account_witness_vote=m(h.account_witness_vote,[["account",s],["witness",s],["approve",C]]);d.cancel_transfer_from_savings=m(h.cancel_transfer_from_savings,[["from",s],["request_id",U]]);d.change_recovery_account=m(h.change_recovery_account,[["account_to_recover",s],["new_recovery_account",s],["extensions",B(I)]]);d.claim_account=m(h.claim_account,[["creator",s],["fee",_],["extensions",B(I)]]);d.claim_reward_balance=m(h.claim_reward_balance,[["account",s],["reward_hive",_],["reward_hbd",_],["reward_vests",_]]);d.comment=m(h.comment,[["parent_author",s],["parent_permlink",s],["author",s],["permlink",s],["title",s],["body",s],["json_metadata",s]]);d.comment_options=m(h.comment_options,[["author",s],["permlink",s],["max_accepted_payout",_],["percent_hbd",P],["allow_votes",C],["allow_curation_rewards",C],["extensions",B(Se([k([["beneficiaries",B(wt)]])]))]]);d.convert=m(h.convert,[["owner",s],["requestid",U],["amount",_]]);d.create_claimed_account=m(h.create_claimed_account,[["creator",s],["new_account_name",s],["owner",x],["active",x],["posting",x],["memo_key",N],["json_metadata",s],["extensions",B(I)]]);d.custom=m(h.custom,[["required_auths",B(s)],["id",P],["data",Ee]]);d.custom_json=m(h.custom_json,[["required_auths",B(s)],["required_posting_auths",B(s)],["id",s],["json",s]]);d.decline_voting_rights=m(h.decline_voting_rights,[["account",s],["decline",C]]);d.delegate_vesting_shares=m(h.delegate_vesting_shares,[["delegator",s],["delegatee",s],["vesting_shares",_]]);d.delete_comment=m(h.delete_comment,[["author",s],["permlink",s]]);d.escrow_approve=m(h.escrow_approve,[["from",s],["to",s],["agent",s],["who",s],["escrow_id",U],["approve",C]]);d.escrow_dispute=m(h.escrow_dispute,[["from",s],["to",s],["agent",s],["who",s],["escrow_id",U]]);d.escrow_release=m(h.escrow_release,[["from",s],["to",s],["agent",s],["who",s],["receiver",s],["escrow_id",U],["hbd_amount",_],["hive_amount",_]]);d.escrow_transfer=m(h.escrow_transfer,[["from",s],["to",s],["hbd_amount",_],["hive_amount",_],["escrow_id",U],["agent",s],["fee",_],["json_meta",s],["ratification_deadline",z],["escrow_expiration",z]]);d.feed_publish=m(h.feed_publish,[["publisher",s],["exchange_rate",se]]);d.limit_order_cancel=m(h.limit_order_cancel,[["owner",s],["orderid",U]]);d.limit_order_create=m(h.limit_order_create,[["owner",s],["orderid",U],["amount_to_sell",_],["min_to_receive",_],["fill_or_kill",C],["expiration",z]]);d.limit_order_create2=m(h.limit_order_create2,[["owner",s],["orderid",U],["amount_to_sell",_],["exchange_rate",se],["fill_or_kill",C],["expiration",z]]);d.recover_account=m(h.recover_account,[["account_to_recover",s],["new_owner_authority",x],["recent_owner_authority",x],["extensions",B(I)]]);d.request_account_recovery=m(h.request_account_recovery,[["recovery_account",s],["account_to_recover",s],["new_owner_authority",x],["extensions",B(I)]]);d.reset_account=m(h.reset_account,[["reset_account",s],["account_to_reset",s],["new_owner_authority",x]]);d.set_reset_account=m(h.set_reset_account,[["account",s],["current_reset_account",s],["reset_account",s]]);d.set_withdraw_vesting_route=m(h.set_withdraw_vesting_route,[["from_account",s],["to_account",s],["percent",P],["auto_vest",C]]);d.transfer=m(h.transfer,[["from",s],["to",s],["amount",_],["memo",s]]);d.transfer_from_savings=m(h.transfer_from_savings,[["from",s],["request_id",U],["to",s],["amount",_],["memo",s]]);d.transfer_to_savings=m(h.transfer_to_savings,[["from",s],["to",s],["amount",_],["memo",s]]);d.transfer_to_vesting=m(h.transfer_to_vesting,[["from",s],["to",s],["amount",_]]);d.vote=m(h.vote,[["voter",s],["author",s],["permlink",s],["weight",gt]]);d.withdraw_vesting=m(h.withdraw_vesting,[["account",s],["vesting_shares",_]]);d.witness_update=m(h.witness_update,[["owner",s],["url",s],["block_signing_key",N],["props",bt],["fee",_]]);d.witness_set_properties=m(h.witness_set_properties,[["owner",s],["props",oe(s,Ee)],["extensions",B(I)]]);d.account_update2=m(h.account_update2,[["account",s],["owner",K(x)],["active",K(x)],["posting",K(x)],["memo_key",K(N)],["json_metadata",s],["posting_json_metadata",s],["extensions",B(I)]]);d.create_proposal=m(h.create_proposal,[["creator",s],["receiver",s],["start_date",z],["end_date",z],["daily_pay",_],["subject",s],["permlink",s],["extensions",B(I)]]);d.update_proposal_votes=m(h.update_proposal_votes,[["voter",s],["proposal_ids",B(ve)],["approve",C],["extensions",B(I)]]);d.remove_proposal=m(h.remove_proposal,[["proposal_owner",s],["proposal_ids",B(ve)],["extensions",B(I)]]);var At=k([["end_date",z]]);d.update_proposal=m(h.update_proposal,[["proposal_id",xe],["creator",s],["daily_pay",_],["subject",s],["permlink",s],["extensions",B(Se([I,At]))]]);d.collateralized_convert=m(h.collateralized_convert,[["owner",s],["requestid",U],["amount",_]]);d.recurrent_transfer=m(h.recurrent_transfer,[["from",s],["to",s],["amount",_],["memo",s],["recurrence",P],["executions",P],["extensions",B(k([["type",Be],["value",k([["pair_id",Be]])]]))]]);var Bt=(n,e)=>{let t=d[e[0]];if(!t)throw new Error(`No serializer for operation: ${e[0]}`);try{t(n,e[1]);}catch(r){throw r.message=`${e[0]}: ${r.message}`,r}},vt=k([["ref_block_num",P],["ref_block_prefix",U],["expiration",z],["operations",B(Bt)],["extensions",B(s)]]),xt=k([["from",N],["to",N],["nonce",xe],["check",U],["encrypted",Ue()]]),L={Asset:_,Memo:xt,Price:se,PublicKey:N,String:s,Transaction:vt,UInt16:P,UInt32:U};var j=n=>new Promise(e=>setTimeout(e,n));var O=class extends Error{constructor(t){super(t.message);y(this,"name","RPCError");y(this,"data");y(this,"code");y(this,"stack");this.code=t.code,"data"in t&&(this.data=t.data);}},V=class extends Error{constructor(t,r,i=0){super(r);y(this,"node");y(this,"rateLimitMs");this.node=t,this.rateLimitMs=i;}},St=["ECONNREFUSED","ENOTFOUND","EHOSTUNREACH","EAI_AGAIN"],Ut=["Failed to fetch","NetworkError when attempting to fetch","Load failed","fetch failed"];function Et(n){if(!n)return "";let e=[String(n.name||""),String(n.message||""),String(n.code||"")],t=n.cause;for(let r=0;t&&r<5;r++)e.push(String(t.code||""),String(t.message||"")),t=t.cause;return e.join(" ")}function Tt(n){if(!n)return false;if(n instanceof V)return true;if(n instanceof O)return false;let e=Et(n);return !!(St.some(t=>e.includes(t))||Ut.some(t=>e.includes(t))||n instanceof SyntaxError||/Unexpected token|JSON\.parse|Unexpected end of JSON/i.test(e))}function It(n,e){return !!(n===-32603||n<=-32e3&&n>=-32099||n===-32601||n===-32602&&/unable to parse|endpoint data|internal/i.test(e))}function Ie(n){let e=n.indexOf(".");return e>0?n.slice(0,e):n}var Pt=2,kt=6e4,Te=12e4,Lt=30,ae=.3,Pe=3,ce=5*6e4,ke=6e4,Le=1e3,Ne=2e3,Oe=700,De=2.5,Nt=new Set(["hapi.ecency.com","api.ecency.com"]);function Ot(n){try{return Nt.has(new URL(n).hostname)}catch{return false}}var Z=class{constructor(){y(this,"health",new Map);}getOrCreate(e){let t=this.health.get(e);return t||(t={consecutiveFailures:0,lastFailureTime:0,rateLimitedUntil:0,apiFailures:new Map,headBlock:0,headBlockUpdatedAt:0,ewmaLatencyMs:void 0,latencySampleCount:0,latencyUpdatedAt:0,lastProbeAt:Date.now()},this.health.set(e,t)),t}recordSuccess(e,t,r){let i=this.getOrCreate(e);i.consecutiveFailures=0,t&&i.apiFailures.delete(t),typeof r=="number"&&Number.isFinite(r)&&r>=0&&this.recordLatency(i,r);}recordSlowFailure(e,t){!Number.isFinite(t)||t<Ne||this.recordLatency(this.getOrCreate(e),t);}recordLatency(e,t){let r=Date.now();e.latencyUpdatedAt>0&&r-e.latencyUpdatedAt>ce&&(e.ewmaLatencyMs=void 0,e.latencySampleCount=0),e.ewmaLatencyMs=e.ewmaLatencyMs===void 0?t:ae*t+(1-ae)*e.ewmaLatencyMs,e.latencySampleCount++,e.latencyUpdatedAt=r;}recordFailure(e,t){let r=this.getOrCreate(e);if(t){let i=Date.now(),o=r.apiFailures.get(t)??{count:0,cooldownUntil:0,lastFailureTime:0};(o.cooldownUntil>0&&o.cooldownUntil<=i||o.lastFailureTime>0&&i-o.lastFailureTime>3e4)&&(o.count=0,o.cooldownUntil=0),o.count++,o.lastFailureTime=i,o.count>=Pt&&(o.cooldownUntil=i+kt),r.apiFailures.set(t,o);}else r.consecutiveFailures++,r.lastFailureTime=Date.now();}recordRateLimit(e,t=1e4){let r=this.getOrCreate(e);r.rateLimitedUntil=Date.now()+t,r.consecutiveFailures++,r.lastFailureTime=Date.now();}recordHeadBlock(e,t){if(!t||!Number.isFinite(t))return;let r=this.getOrCreate(e);r.headBlock=t,r.headBlockUpdatedAt=Date.now();}consensusHeadBlock(){let e=Date.now(),t=[];for(let r of this.health.values())r.headBlock>0&&e-r.headBlockUpdatedAt<=Te&&t.push(r.headBlock);return t.length<2?0:(t.sort((r,i)=>r-i),t[Math.floor((t.length-1)/2)])}isNodeHealthy(e,t){let r=this.health.get(e);if(!r)return true;let i=Date.now();if(r.rateLimitedUntil>i||r.consecutiveFailures>=3&&i-r.lastFailureTime<3e4)return false;if(t){let a=r.apiFailures.get(t);if(a&&a.cooldownUntil>i)return false}let o=this.consensusHeadBlock();return !(o>0&&r.headBlock>0&&i-r.headBlockUpdatedAt<=Te&&o-r.headBlock>Lt)}getOrderedNodes(e,t){let r=[],i=[];for(let f of e)this.isNodeHealthy(f,t)?r.push(f):i.push(f);if(r.length<=1)return [...r,...i];let o=Date.now(),a=this.fastestUsableLatency(r,o),u=r.map((f,l)=>({node:f,i:l,score:this.scoreNode(f,a,o)})).sort((f,l)=>f.score-l.score||f.i-l.i).map(f=>f.node),c=this.pickReprobeCandidate(r,o);return c&&u[0]!==c?[c,...u.filter(f=>f!==c),...i]:[...u,...i]}isLatencyUsable(e,t){return !!e&&e.ewmaLatencyMs!==void 0&&e.latencySampleCount>=Pe&&t-e.latencyUpdatedAt<=ce}fastestUsableLatency(e,t){let r=1/0;for(let i of e){let o=this.health.get(i);this.isLatencyUsable(o,t)&&(r=Math.min(r,o.ewmaLatencyMs));}return r}scoreNode(e,t,r){let i=this.health.get(e);if(!this.isLatencyUsable(i,r))return Le;let o=i.ewmaLatencyMs;return Ot(e)?t>0&&t!==1/0&&o>De*t?o:Math.max(o-Oe,0):o}pickReprobeCandidate(e,t){let r=t-ke,i,o=1/0;for(let a of e){let u=this.getOrCreate(a),c=Math.max(u.latencyUpdatedAt,u.lastProbeAt);c<=r&&c<o&&(i=a,o=c);}return i&&(this.getOrCreate(i).lastProbeAt=t),i}},M=new Z,H=new Z;function Ce(n,e,t,r){t instanceof V?t.rateLimitMs>0?n.recordRateLimit(e,t.rateLimitMs):n.recordFailure(e,r):t instanceof O?n.recordFailure(e,r):n.recordFailure(e);}function Dt(n,e,t,r){if(!r||typeof r!="object"||!t.includes("get_dynamic_global_properties"))return;let i=r.head_block_number;typeof i=="number"&&n.recordHeadBlock(e,i);}function Ct(){if(typeof DOMException<"u")return new DOMException("The operation was aborted due to timeout","TimeoutError");let n=new Error("The operation was aborted due to timeout");return n.name="TimeoutError",n}function Re(n){if(typeof AbortSignal.timeout=="function")return {signal:AbortSignal.timeout(n),cleanup:()=>{}};let e=new AbortController,t=setTimeout(()=>e.abort(Ct()),n);return {signal:e.signal,cleanup:()=>clearTimeout(t)}}function ze(n,e){if(!e)return {signal:n,cleanup:()=>{}};if(typeof AbortSignal.any=="function")return {signal:AbortSignal.any([n,e]),cleanup:()=>{}};let t=new AbortController;if(n.aborted)return t.abort(n.reason),{signal:t.signal,cleanup:()=>{}};if(e.aborted)return t.abort(e.reason),{signal:t.signal,cleanup:()=>{}};let r=()=>t.abort(n.reason),i=()=>t.abort(e.reason);n.addEventListener("abort",r,{once:true}),e.addEventListener("abort",i,{once:true});let o=()=>{n.removeEventListener("abort",r),e.removeEventListener("abort",i);};return {signal:t.signal,cleanup:o}}var ee=async(n,e,t,r=w.timeout,i=false,o)=>{let a=Math.floor(Math.random()*1e8),u={jsonrpc:"2.0",method:e,params:t,id:a},{signal:c,cleanup:f}=Re(r),{signal:l,cleanup:E}=ze(c,o),p=()=>{f(),E();};try{let v=await fetch(n,{method:"POST",body:JSON.stringify(u),headers:{"Content-Type":"application/json"},signal:l});if(v.status===429){let D=v.headers.get("Retry-After"),Y=D?parseInt(D,10)*1e3:1e4;throw new V(n,"HTTP 429 Rate Limited",Y)}if(v.status>=500&&v.status<600)throw new V(n,`HTTP ${v.status} from ${n}`);let T=await v.json();if(!T||typeof T.id>"u"||T.id!==a||T.jsonrpc!=="2.0")throw new Error("JSONRPC id mismatch");if("result"in T)return T.result;if("error"in T){let D=T.error;throw "message"in D&&"code"in D?new O(D):T.error}throw T}catch(v){if(v instanceof O||v instanceof V||o?.aborted)throw v;if(i)return ee(n,e,t,r,false,o);throw v}finally{p();}};function Me(){return j(50+Math.random()*50)}var te=async(n,e=[],t=w.timeout,r=w.retry,i)=>{if(!Array.isArray(w.nodes))throw new Error("config.nodes is not an array");if(w.nodes.length===0)throw new Error("config.nodes is empty");let o=Ie(n),a=new Set,u;for(let c=0;c<=r;c++){let f=M.getOrderedNodes(w.nodes,o),l=f.find(p=>!a.has(p));l||(a.clear(),l=f[0]),a.add(l);let E=Date.now();try{let p=await ee(l,n,e,t,!1,i);return M.recordSuccess(l,o,Date.now()-E),Dt(M,l,n,p),p}catch(p){if(p instanceof O&&!It(p.code,p.message)||i?.aborted)throw p;Ce(M,l,p,o),M.recordSlowFailure(l,Date.now()-E),u=p,c<r&&await Me();}}throw u},ue=async(n,e=[],t=w.broadcastTimeout,r)=>{if(!Array.isArray(w.nodes))throw new Error("config.nodes is not an array");if(w.nodes.length===0)throw new Error("config.nodes is empty");let i=Ie(n),o=new Set,a;for(let u=0;u<w.nodes.length;u++){let f=M.getOrderedNodes(w.nodes,i).find(l=>!o.has(l));if(!f)break;if(o.add(f),r?.aborted)throw new Error("Aborted");try{let l=await ee(f,n,e,t,!1,r);return M.recordSuccess(f,i),l}catch(l){if(l instanceof O||r?.aborted||(Ce(M,f,l,i),a=l,!Tt(l)))throw l}}throw a},Rt={balance:"/balance-api",hafah:"/hafah-api",hafbe:"/hafbe-api",hivemind:"/hivemind-api",hivesense:"/hivesense-api",reputation:"/reputation-api","nft-tracker":"/nft-tracker-api",hafsql:"/hafsql",status:"/status-api"};async function zt(n,e,t,r=w.timeout,i=w.retry,o){if(!Array.isArray(w.restNodes))throw new Error("config.restNodes is not an array");if(w.restNodes.length===0)throw new Error("config.restNodes is empty");let a=w.restNodesByApi?.[n]?.length?w.restNodesByApi[n]:w.restNodes,u=new Set,c,f=false;for(let l=0;l<=i;l++){let E=H.getOrderedNodes(a,n),p=E.find(b=>!u.has(b));p||(u.clear(),p=E[0]),u.add(p);let v=p+Rt[n],T=e,D=t||{},Y=new Set;Object.entries(D).forEach(([b,R])=>{T.includes(`{${b}}`)&&(T=T.replace(`{${b}}`,encodeURIComponent(String(R))),Y.add(b));});let ne=new URL(v+T);if(Object.entries(D).forEach(([b,R])=>{Y.has(b)||(Array.isArray(R)?R.forEach(ie=>ne.searchParams.append(b,String(ie))):ne.searchParams.set(b,String(R)));}),o?.aborted)throw new Error("Aborted");f=false;let{signal:ot,cleanup:st}=Re(r),{signal:at,cleanup:ct}=ze(ot,o),ut=()=>{st(),ct();},he=Date.now();try{let b=await fetch(ne.toString(),{signal:at});if(b.status===404)throw new Error("HTTP 404 - Hint: can happen on wrong params");if(b.status===429){let R=b.headers.get("Retry-After"),ie=R?parseInt(R,10)*1e3:1e4;throw H.recordRateLimit(p,ie),f=!0,new Error(`HTTP 429 Rate Limited by ${p}`)}if(b.status===503)throw H.recordFailure(p,n),f=!0,new Error(`HTTP 503 Service Unavailable from ${p}`);if(!b.ok)throw H.recordFailure(p,n),f=!0,new Error(`HTTP ${b.status} from ${p}`);return H.recordSuccess(p,n,Date.now()-he),b.json()}catch(b){if(b?.message?.includes("HTTP 404")||o?.aborted)throw b;f||H.recordFailure(p,n),H.recordSlowFailure(p,Date.now()-he),c=b,l<i&&await Me();}finally{ut();}}throw c}var Mt=async(n,e=[],t=2,r)=>{if(!Array.isArray(w.nodes))throw new Error("config.nodes is not an Array");if(t>w.nodes.length)throw new Error("quorum > config.nodes.length");let o=(c=>{let f=[...c];for(let l=f.length-1;l>0;l--){let E=Math.floor(Math.random()*(l+1));[f[l],f[E]]=[f[E],f[l]];}return f})(w.nodes),a=Math.min(t,o.length),u=[];for(;a>0&&o.length>0;){let c=o.splice(0,a),f=[],l=[];for(let p=0;p<c.length;p++)f.push(ee(c[p],n,e,void 0,true,r).then(v=>l.push(v)).catch(()=>{}));await Promise.all(f),u.push(...l);let E=Ft(u,t);if(E)return E;if(a=Math.min(t,o.length),a===0)throw new Error("No more nodes available.")}throw new Error("Couldn't reach quorum.")};function Ft(n,e){let t=new Map;for(let i of n){let o=JSON.stringify(i);t.has(o)||t.set(o,[]),t.get(o).push(i);}let r=Array.from(t.values()).find(i=>i.length>=e);return r?r[0]:null}var Ht=hexToBytes(w.chain_id),fe=class n{constructor(e){y(this,"transaction");y(this,"expiration",6e4);y(this,"txId");y(this,"createTransaction",async e=>{let t=await te("condenser_api.get_dynamic_global_properties",[]),r=hexToBytes(t.head_block_id),i=Number(new Uint32Array(r.buffer,r.byteOffset+4,1)[0]),o=new Date(Date.now()+e).toISOString().slice(0,-5);this.transaction={expiration:o,extensions:[],operations:[],ref_block_num:t.head_block_number&65535,ref_block_prefix:i,signatures:[]};});e?.transaction&&(e.transaction instanceof n?(this.transaction=e.transaction.transaction,this.expiration=e.transaction.expiration):this.transaction=e.transaction,this.txId=this.digest().txId),e?.expiration&&(this.expiration=e.expiration);}async addOperation(e,t){this.transaction||await this.createTransaction(this.expiration),this.transaction.operations.push([e,t]);}sign(e){if(!this.transaction)throw new Error("First create a transaction by .addOperation()");if(this.transaction){let{digest:t,txId:r}=this.digest();Array.isArray(e)||(e=[e]);for(let i of e){let o=i.sign(t);this.transaction.signatures.push(o.customToString());}return this.txId=r,this.transaction}else throw new Error("No transaction to sign")}async broadcast(e=false){if(!this.transaction)throw new Error("Attempted to broadcast an empty transaction. Add operations by .addOperation()");if(this.transaction.signatures.length===0)throw new Error("Attempted to broadcast a transaction with no signatures. Sign using .sign(keys)");try{await ue("condenser_api.broadcast_transaction",[this.transaction]);}catch(o){if(!(o instanceof O&&o.message.includes("Duplicate transaction check failed")))throw o}if(this.txId||(this.txId=this.digest().txId),!e)return {tx_id:this.txId,status:"unknown"};let t=60;await j(1e3);let r=await this.checkStatus(),i=1;for(;r?.status!=="within_irreversible_block"&&r?.status!=="expired_irreversible"&&r?.status!=="too_old"&&i<t;)await j(1e3+i*300),r=await this.checkStatus(),i++;return {tx_id:this.txId,status:r?.status??"unknown"}}digest(){if(!this.transaction)throw new Error("First create a transaction by .addOperation()");let e=new g(g.DEFAULT_CAPACITY,g.LITTLE_ENDIAN),t={...this.transaction};try{L.Transaction(e,t);}catch(a){throw new Error("Unable to serialize transaction: "+a)}e.flip();let r=new Uint8Array(e.toBuffer()),i=bytesToHex(sha256(r)).slice(0,40);return {digest:sha256(new Uint8Array([...Ht,...r])),txId:i}}addSignature(e){if(!this.transaction)throw new Error("First create a transaction by .create(operations)");if(typeof e!="string")throw new Error("Signature must be string");if(e.length!==130)throw new Error("Signature must be 130 characters long");return this.transaction.signatures.push(e),this.transaction}async checkStatus(){return this.txId||(this.txId=this.digest().txId),te("transaction_status_api.find_transaction",{transaction_id:this.txId,expiration:this.transaction?.expiration})}};var $e=new Uint8Array([128]),q=class n{constructor(e){y(this,"key");this.key=e;try{secp256k1.getPublicKey(e);}catch{throw new Error("invalid private key")}}static from(e){return typeof e=="string"?n.fromString(e):new n(e)}static fromString(e){return new n(qt(e).subarray(1))}static fromSeed(e){if(typeof e=="string")if(/^[0-9a-fA-F]+$/.test(e))e=hexToBytes(e);else {let r=[];for(let i=0;i<e.length;i++){let o=e.charCodeAt(i);if(o<128)r.push(o);else if(o<2048)r.push(192|o>>6,128|o&63);else if(o>=55296&&o<=56319&&i+1<e.length){let a=e.charCodeAt(++i);o=65536+((o&1023)<<10)+(a&1023),r.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|o&63);}else r.push(224|o>>12,128|o>>6&63,128|o&63);}e=new Uint8Array(r);}return new n(sha256(e))}static fromLogin(e,t,r="active"){let i=e+r+t;return n.fromSeed(i)}sign(e){let t=secp256k1.sign(e,this.key,{extraEntropy:true,format:"recovered",prehash:false}),r=parseInt(bytesToHex(t.subarray(0,1)),16);return F.from((r+31).toString(16)+bytesToHex(t.subarray(1)))}createPublic(e){return new S(secp256k1.getPublicKey(this.key),e)}toString(){return $t(new Uint8Array([...$e,...this.key]))}inspect(){let e=this.toString();return `PrivateKey: ${e.slice(0,6)}...${e.slice(-6)}`}getSharedSecret(e){let t=secp256k1.getSharedSecret(this.key,e.key);return sha512(t.subarray(1))}static randomKey(){return new n(secp256k1.keygen().secretKey)}},qe=n=>sha256(sha256(n)),$t=n=>{let e=qe(n);return Ae.encode(new Uint8Array([...n,...e.slice(0,4)]))},qt=n=>{let e=Ae.decode(n);if(!Ve(e.slice(0,1),$e))throw new Error("Private key network id mismatch");let t=e.slice(-4),r=e.slice(0,-4),i=qe(r).slice(0,4);if(!Ve(t,i))throw new Error("Private key checksum mismatch");return r},Ve=(n,e)=>{if(n===e)return true;if(n.byteLength!==e.byteLength)return false;let t=n.byteLength,r=0;for(;r<t&&n[r]===e[r];)r++;return r===t};var We=(n,e,t,r=Xt())=>Ge(n,e,r,t),Je=(n,e,t,r,i)=>Ge(n,e,t,r,i).message,Ge=(n,e,t,r,i)=>{let o=t,a=n.getSharedSecret(e),u=new g(g.DEFAULT_CAPACITY,g.LITTLE_ENDIAN);u.writeUint64(o),u.append(a),u.flip();let c=sha512(new Uint8Array(u.toBuffer())),f=c.subarray(32,48),l=c.subarray(0,32),E=sha256(c).subarray(0,4),p=new g(g.DEFAULT_CAPACITY,g.LITTLE_ENDIAN);p.append(E),p.flip();let v=p.readUint32();if(i!==void 0){if(v!==i)throw new Error("Invalid key");r=Gt(r,l,f);}else r=Qt(r,l,f);return {nonce:o,message:r,checksum:v}},Gt=(n,e,t)=>{let r=n;return r=cbc(e,t).decrypt(r),r},Qt=(n,e,t)=>{let r=n;return r=cbc(e,t).encrypt(r),r},de=null,Xt=()=>{if(de===null){let t=secp256k1.utils.randomSecretKey();de=t[0]<<8|t[1];}let n=BigInt(Date.now()),e=++de%65536;return n=n<<BigInt(16)|BigInt(e),n};var Qe=n=>{let e=ir(n,33);return new S(e)},er=n=>n.readUint64(),tr=n=>n.readUint32(),rr=n=>{let e=n.readVarint32(),t=n.copy(n.offset,n.offset+e);return n.skip(e),new Uint8Array(t.toBuffer())},nr=n=>e=>{let t={},r=new g(g.DEFAULT_CAPACITY,g.LITTLE_ENDIAN);r.append(e),r.flip();for(let[i,o]of n)try{t[i]=o(r);}catch(a){throw a.message=`${i}: ${a.message}`,a}return t};function ir(n,e){if(n){let t=n.copy(n.offset,n.offset+e);return n.skip(e),new Uint8Array(t.toBuffer())}else throw Error("No buffer found on first parameter")}var or=nr([["from",Qe],["to",Qe],["nonce",er],["check",tr],["encrypted",rr]]),Xe={Memo:or};var et=(n,e,t,r)=>{if(!t.startsWith("#"))return t;t=t.substring(1),rt(),n=nt(n),e=sr(e);let i=new g(g.DEFAULT_CAPACITY,g.LITTLE_ENDIAN);i.writeVString(t);let o=new Uint8Array(i.copy(0,i.offset).toBuffer()),{nonce:a,message:u,checksum:c}=We(n,e,o,r),f=new g(g.DEFAULT_CAPACITY,g.LITTLE_ENDIAN);L.Memo(f,{check:c,encrypted:u,from:n.createPublic(),nonce:a,to:e}),f.flip();let l=new Uint8Array(f.toBuffer());return "#"+Ae.encode(l)},tt=(n,e)=>{if(!e.startsWith("#"))return e;e=e.substring(1),rt(),n=nt(n);let t=Xe.Memo(Ae.decode(e)),{from:r,to:i,nonce:o,check:a,encrypted:u}=t,f=n.createPublic().toString()===new S(r.key).toString()?new S(i.key):new S(r.key);t=Je(n,f,o,u,a);let l=new g(g.DEFAULT_CAPACITY,g.LITTLE_ENDIAN);return l.append(t),l.flip(),"#"+l.readVString()},re,rt=()=>{if(re===void 0){let n;re=true;try{let e="5JdeC9P7Pbd1uGdFVEsJ41EkEnADbbHGq6p1BwFxm6txNBsQnsw",r=et(e,"STM8m5UgaFAAYQRuaNejYdS8FVLVp9Ss3K1qAVk5de6F8s3HnVbvA","#memo\u7231");n=tt(e,r);}finally{re=n==="#memo\u7231";}}if(re===false)throw new Error("This environment does not support encryption.")},nt=n=>typeof n=="string"?q.fromString(n):n,sr=n=>typeof n=="string"?S.fromString(n):n,ar={decode:tt,encode:et};var it={};lt(it,{buildWitnessSetProperties:()=>hr,makeBitMaskFilter:()=>lr,operations:()=>fr,validateUsername:()=>ur});var ur=n=>{let e="Account name should ";if(!n)return e+"not be empty.";let t=n.length;if(t<3)return e+"be longer.";if(t>16)return e+"be shorter.";/\./.test(n)&&(e="Each account segment should ");let r=n.split("."),i=r.length;for(let o=0;o<i;o++){let a=r[o];if(!/^[a-z]/.test(a))return e+"start with a lowercase letter.";if(!/^[a-z0-9-]*$/.test(a))return e+"have only lowercase letters, digits, or dashes.";if(!/[a-z0-9]$/.test(a))return e+"end with a lowercase letter or digit.";if(a.length<3)return e+"be longer."}return null},fr={vote:0,comment:1,transfer:2,transfer_to_vesting:3,withdraw_vesting:4,limit_order_create:5,limit_order_cancel:6,feed_publish:7,convert:8,account_create:9,account_update:10,witness_update:11,account_witness_vote:12,account_witness_proxy:13,pow:14,custom:15,report_over_production:16,delete_comment:17,custom_json:18,comment_options:19,set_withdraw_vesting_route:20,limit_order_create2:21,claim_account:22,create_claimed_account:23,request_account_recovery:24,recover_account:25,change_recovery_account:26,escrow_transfer:27,escrow_dispute:28,escrow_release:29,pow2:30,escrow_approve:31,transfer_to_savings:32,transfer_from_savings:33,cancel_transfer_from_savings:34,custom_binary:35,decline_voting_rights:36,reset_account:37,set_reset_account:38,claim_reward_balance:39,delegate_vesting_shares:40,account_create_with_delegation:41,witness_set_properties:42,account_update2:43,create_proposal:44,update_proposal_votes:45,remove_proposal:46,update_proposal:47,collateralized_convert:48,recurrent_transfer:49,fill_convert_request:50,author_reward:51,curation_reward:52,comment_reward:53,liquidity_reward:54,interest:55,fill_vesting_withdraw:56,fill_order:57,shutdown_witness:58,fill_transfer_from_savings:59,hardfork:60,comment_payout_update:61,return_vesting_delegation:62,comment_benefactor_reward:63,producer_reward:64,clear_null_account_balance:65,proposal_pay:66,sps_fund:67,hardfork_hive:68,hardfork_hive_restore:69,delayed_voting:70,consolidate_treasury_balance:71,effective_comment_vote:72,ineffective_delete_comment:73,sps_convert:74,expired_account_notification:75,changed_recovery_account:76,transfer_to_vesting_completed:77,pow_reward:78,vesting_shares_split:79,account_created:80,fill_collateralized_convert_request:81,system_warning:82,fill_recurrent_transfer:83,failed_recurrent_transfer:84,limit_order_cancelled:85,producer_missed:86,proposal_fee:87,collateralized_convert_immediate_conversion:88,escrow_approved:89,escrow_rejected:90,proxy_cleared:91,declined_voting_rights:92},lr=n=>n.reduce(dr,[BigInt(0),BigInt(0)]).map(e=>e!==BigInt(0)?e.toString():null),dr=([n,e],t)=>t<64?[n|BigInt(1)<<BigInt(t),e]:[n,e|BigInt(1)<<BigInt(t-64)],hr=(n,e)=>{let t={extensions:[],owner:n,props:[]};for(let r of Object.keys(e)){if(e[r]===void 0)continue;let i;switch(r){case "key":case "new_signing_key":i=L.PublicKey;break;case "account_subsidy_budget":case "account_subsidy_decay":case "maximum_block_size":i=L.UInt32;break;case "hbd_interest_rate":i=L.UInt16;break;case "url":i=L.String;break;case "hbd_exchange_rate":i=L.Price;break;case "account_creation_fee":i=L.Asset;break;default:throw new Error(`Unknown witness prop: ${r}`)}t.props.push([r,mr(i,e[r])]);}return t.props.sort((r,i)=>r[0].localeCompare(i[0])),["witness_set_properties",t]},mr=(n,e)=>{let t=new g(g.DEFAULT_CAPACITY,g.LITTLE_ENDIAN);return n(t,e),t.flip(),bytesToHex(new Uint8Array(t.toBuffer()))};/**
|
|
2
2
|
* @license bytebuffer.ts (c) 2015 Daniel Wirtz <dcode@dcode.io>
|
|
3
3
|
* Backing buffer: ArrayBuffer, Accessor: DataView
|
|
4
4
|
* Released under the Apache License, Version 2.0
|
|
5
5
|
* see: https://github.com/dcodeIO/bytebuffer.ts for details
|
|
6
6
|
* modified by @xmcl/bytebuffer
|
|
7
7
|
* And customized for hive-tx
|
|
8
|
-
*/export{ar as Memo,q as PrivateKey,S as PublicKey,
|
|
8
|
+
*/export{ar as Memo,q as PrivateKey,S as PublicKey,F as Signature,fe as Transaction,zt as callREST,te as callRPC,ue as callRPCBroadcast,Mt as callWithQuorum,w as config,ht as setNodes,it as utils};//# sourceMappingURL=hive.js.map
|
|
9
9
|
//# sourceMappingURL=hive.js.map
|