wative 1.1.15 → 1.1.17
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/lib/account.d.ts +14 -0
- package/lib/account.d.ts.map +1 -0
- package/lib/assets.d.ts +11 -0
- package/lib/assets.d.ts.map +1 -0
- package/lib/chain.d.ts +6 -0
- package/lib/chain.d.ts.map +1 -0
- package/lib/config.d.ts +23 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/daemon-watcher.js +181 -0
- package/lib/home_page.d.ts +4 -0
- package/lib/home_page.d.ts.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.esm.js +1 -1
- package/lib/index.umd.js +1 -1
- package/lib/network.d.ts +28 -0
- package/lib/network.d.ts.map +1 -0
- package/lib/ssh/client.d.ts +120 -0
- package/lib/ssh/client.d.ts.map +1 -0
- package/lib/ssh/client_example.d.ts +19 -0
- package/lib/ssh/client_example.d.ts.map +1 -0
- package/lib/ssh/client_test.d.ts +27 -0
- package/lib/ssh/client_test.d.ts.map +1 -0
- package/lib/ssh/config_manager.d.ts +55 -0
- package/lib/ssh/config_manager.d.ts.map +1 -0
- package/lib/ssh/config_template.d.ts +52 -0
- package/lib/ssh/config_template.d.ts.map +1 -0
- package/lib/ssh/index.d.ts +7 -0
- package/lib/ssh/index.d.ts.map +1 -0
- package/lib/ssh/remote_server_example.d.ts +16 -0
- package/lib/ssh/remote_server_example.d.ts.map +1 -0
- package/lib/ssh/service_manager.d.ts +119 -0
- package/lib/ssh/service_manager.d.ts.map +1 -0
- package/lib/ssh/types.d.ts +45 -0
- package/lib/ssh/types.d.ts.map +1 -0
- package/lib/ssh/utils.d.ts +11 -0
- package/lib/ssh/utils.d.ts.map +1 -0
- package/lib/ssh/wative_server.d.ts +26 -0
- package/lib/ssh/wative_server.d.ts.map +1 -0
- package/lib/tools.d.ts +6 -0
- package/lib/tools.d.ts.map +1 -0
- package/lib/tx_gas_utils.d.ts +18 -0
- package/lib/tx_gas_utils.d.ts.map +1 -0
- package/lib/utils.d.ts +49 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/wative.d.ts +2 -0
- package/lib/wative.d.ts.map +1 -0
- package/lib/wative.esm.js +1 -1
- package/lib/wative.umd.js +1 -1
- package/lib/web3.d.ts +59 -0
- package/lib/web3.d.ts.map +1 -0
- package/package.json +9 -5
- package/src/assets.ts +1 -10
- package/src/daemon-watcher.js +181 -0
- package/src/ssh/client.rs +221 -0
- package/src/ssh/client.ts +389 -0
- package/src/ssh/config_manager.ts +317 -0
- package/src/ssh/index.ts +49 -36
- package/src/ssh/service_manager.ts +684 -0
- package/src/ssh/types.ts +35 -1
- package/src/ssh/wative_server.ts +1 -2
- package/src/wative.ts +560 -122
- package/bin/wative-ssh.sh +0 -44
- package/lib/wative-ssh.esm.js +0 -1
- package/lib/wative-ssh.umd.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wative.d.ts","sourceRoot":"","sources":["../src/wative.ts"],"names":[],"mappings":""}
|
package/lib/wative.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"path";import{Command as t}from"commander";import{execSync as r}from"child_process";import*as i from"fs";import*as o from"ini";import"figlet";import"inquirer";import"web3";import"@solana/web3.js";import"@solana/spl-token";import"@metaplex-foundation/js";import"bignumber.js";function n(e,t,r,i){return new(r||(r=Promise))(function(o,n){function s(e){try{c(i.next(e))}catch(e){n(e)}}function a(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(s,a)}c((i=i.apply(e,t||[])).next())})}function s(e,t){var r,i,o,n={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(n=0)),n;)try{if(r=1,i&&(o=2&a[0]?i.return:a[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,a[1])).done)return o;switch(i=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return n.label++,{value:a[1],done:!1};case 5:n.label++,i=a[1],a=[0];continue;case 7:a=n.ops.pop(),n.trys.pop();continue;default:if(!(o=n.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){n=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){n.label=a[1];break}if(6===a[0]&&n.label<o[1]){n.label=o[1],o=a;break}if(o&&n.label<o[2]){n.label=o[2],n.ops.push(a);break}o[2]&&n.ops.pop(),n.trys.pop();continue}a=t.call(e,n)}catch(e){a=[6,e],i=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}"function"==typeof SuppressedError&&SuppressedError,require("chalk"),require("chalk"),require("chalk"),process.env.HOME||process.env.USERPROFILE;var a=function(e){return e=(e=(e=(e=e.trim()).toLocaleLowerCase()).replace(/\s+/g,"-").trim()).replace(/\-+/g,"-").trim()};require("bn.js").BN,require("ethereumjs-util").stripHexPrefix,require("bignumber.js").BigNumber,require("chalk"),require("wative-core").WativeCore,require("chalk"),require("dotenv").config(),require("cli-progress"),require("wative-core").WativeCore;var c=function(t){return n(void 0,void 0,void 0,function(){var c,l,u,v,d,p,f;return s(this,function(h){switch(h.label){case 0:return c="/etc/wative",i.existsSync(c)||i.mkdirSync(c),[4,n(void 0,void 0,void 0,function(){var t,o,n,a,c;return s(this,function(s){return t="/etc/wative",o=e.join(t,"id_rsa_server.pub"),n=e.join(t,"id_rsa_server"),i.existsSync(o)&&i.existsSync(n)||(console.log("Generating SSH key pair..."),r("ssh-keygen -t rsa -f ".concat(n," -N 'wative_server'"),{stdio:"inherit"})),a=e.join(t,"id_rsa_detake.pub"),c=e.join(t,"id_rsa_detake"),i.existsSync(a)&&i.existsSync(c)||(console.log("Generating SSH key pair..."),r("ssh-keygen -t rsa -f ".concat(c," -N 'wative_detake'"),{stdio:"inherit"})),[2]})})];case 1:return h.sent(),l=e.join(c,"config.ini"),i.existsSync(l)||(m=t,y=e.resolve(m,"network.json"),u=JSON.parse(i.readFileSync(y,"utf8")),v=u.accounts,d=function(e){for(var t=[],r=0;r<e.length;r++)t.push(a(e[r]));return t}(v),p={keystore:{path:t,allowed_keystores:d},ssh:{listen:"127.0.0.1",port:5678,log:{size:10485760,backups:3}}},f=o.stringify(p),i.writeFileSync(l,f)),[2,o.parse(i.readFileSync(l,"utf-8"))]}var m,y})})},l=require("os"),u=new t,v=require("../package.json"),d=function(){try{return r("systemctl --version",{stdio:"ignore"}),!0}catch(e){return!1}};u.version(v.version).description("Wative CLI Tool"),u.command("version").description("Show the version of wative").action(function(){console.log("Wative CLI Tool v".concat(v.version))});u.command("ssh").option("start","Start SSH service").option("stop","Stop SSH service").option("service add","Add SSH service").option("service remove","Remove SSH service").action(function(t,o){return n(void 0,void 0,void 0,function(){return s(this,function(a){switch(a.label){case 0:return"start"!==t?[3,2]:[4,n(void 0,void 0,void 0,function(){var t,o,n;return s(this,function(s){switch(s.label){case 0:return d()?(t="/var/log/wative",i.existsSync(t)||i.mkdirSync(t),o=l.homedir(),n=e.join(o,".wative"),[4,c(n)]):(console.log("Systemd is not available."),[2]);case 1:s.sent(),console.log("Starting SSH service...");try{r("wative-ssh --daemon",{stdio:"inherit"})}catch(e){}return console.log("SSH service started."),[2]}})})];case 1:return a.sent(),[2];case 2:return"stop"===t?(function(){if(d()){try{r("ps aux | grep wative-ssh | grep -v grep | awk '{print $2}' | sudo xargs kill",{stdio:"inherit"})}catch(e){}console.log("SSH service stopped.")}else console.log("Systemd is not available.")}(),[2]):"service"===t&&"add"===o?(n(void 0,void 0,void 0,function(){var t,o,n;return s(this,function(s){switch(s.label){case 0:return d()?(t="/var/log/wative",i.existsSync(t)||i.mkdirSync(t),o=l.homedir(),n=e.join(o,".wative"),[4,c(n)]):(console.log("Systemd is not available."),[2]);case 1:s.sent(),console.log("Adding SSH service...");try{r("sudo echo '".concat("\n[Unit]\nDescription=Wative SSH Server\nAfter=network.target\n\n[Service]\nExecStart=/usr/local/bin/wative-ssh\nUser=root\nGroup=root\nStandardOutput=append:/var/log/wative/wative.log\nStandardError=append:/var/log/wative/wative.err\n\n[Install]\nWantedBy=multi-user.target\n ","' > ").concat("/etc/systemd/system/wative.service"),{stdio:"inherit"}),r("sudo systemctl daemon-reload",{stdio:"inherit"}),r("sudo systemctl enable wative",{stdio:"inherit"}),r("sudo systemctl start wative",{stdio:"inherit"})}catch(e){}return console.log("SSH service added."),[2]}})}),[2]):"service"===t&&"remove"===o?(function(){if(d()){console.log("Removing SSH service...");try{r("sudo systemctl stop wative",{stdio:"inherit"})}catch(e){}try{r("sudo systemctl disable wative",{stdio:"inherit"})}catch(e){}try{r("sudo rm -rf /etc/systemd/system/wative.service",{stdio:"inherit"})}catch(e){}try{r("sudo systemctl daemon-reload",{stdio:"inherit"})}catch(e){}console.log("SSH service removed.")}else console.log("Systemd is not available.")}(),[2]):[2]}})})}),u.command("cmd").description("Start wallet-cli shell").action(function(){return n(void 0,void 0,void 0,function(){return s(this,function(e){try{r("wallet-cli",{stdio:"inherit"})}catch(e){}return[2]})})}),u.parse(process.argv);
|
|
1
|
+
import*as e from"path";import t from"path";import{Command as r}from"commander";import{execSync as s,spawn as o}from"child_process";import*as n from"fs";import i,{readFileSync as a}from"fs";import*as c from"ini";import*as l from"crypto";import{timingSafeEqual as u}from"crypto";import{utils as p,Server as d}from"ssh2";import"figlet";import h from"inquirer";import g from"web3";import f from"@solana/web3.js";import"@solana/spl-token";import"@metaplex-foundation/js";import"bignumber.js";import*as m from"log4js";import{ethers as y}from"ethers";import v from"tweetnacl";import w from"bs58";import b from"bip39";import S from"@coral-xyz/anchor";import k from"crypto-js";import x from"ethereumjs-wallet";import _ from"micro-ed25519-hdkey";import*as P from"net";class I{constructor(t,r){this.configDir=t||e.join(require("os").homedir(),".wative/ssh"),this.keystorePath=r||e.join(require("os").homedir(),".wative"),n.existsSync(this.configDir)||n.mkdirSync(this.configDir,{recursive:!0});const s=e.join(this.configDir,"conf.d");n.existsSync(s)||n.mkdirSync(s,{recursive:!0})}getKeystorePath(){return this.keystorePath}getConfigDir(){return this.configDir}async createServiceConfig(e,t,r,s="default_client",o){if(!this.isValidServiceName(e))throw new Error("Invalid service name. Use only alphanumeric characters, hyphens, and underscores.");if(this.isPortInUse(t))throw new Error(`Port ${t} is already in use by another service.`);const n=await this.generateServiceKeyPair(e),i=await this.generateClientKeyPair(e,s),a={name:e,description:o||`Wative SSH Service - ${e}`,ssh:{listen:"127.0.0.1",port:t,log:{size:10485760,backups:3}},keystore:{path:this.keystorePath,allowed_keystores:r},clients:[{name:s,public_key_path:i.publicKey,allowed_keystores:r}],server_keys:{private_key_path:n.privateKey,passphrase:n.passphrase}};return this.saveServiceConfig(e,a),a}loadServiceConfig(e){const t=this.getServiceConfigPath(e);if(!n.existsSync(t))throw new Error(`Service configuration '${e}' not found.`);const r=c.parse(n.readFileSync(t,"utf-8"));return this.parseConfigData(r)}listServiceConfigs(){const t=e.join(this.configDir,"conf.d");if(!n.existsSync(t))return[];return n.readdirSync(t).filter(r=>{const s=e.join(t,r);return n.statSync(s).isDirectory()&&n.existsSync(e.join(s,"config.ini"))})}removeServiceConfig(e){const t=this.getServiceConfigPath(e);n.existsSync(t)&&n.unlinkSync(t),this.removeServiceKeys(e)}updateServiceConfig(e,t){const r={...this.loadServiceConfig(e),...t};this.saveServiceConfig(e,r)}async validateKeystorePasswords(e,t){const r={},{WativeCore:s}=require("wative-core");for(const o of e)try{const e=t[o];if(!e){r[o]=!1;continue}const n=new s(this.keystorePath,[o],[e]);r[o]=n.account.isLogin(o)}catch(e){r[o]=!1}return r}isValidServiceName(e){return/^[a-zA-Z0-9_-]+$/.test(e)&&e.length>0&&e.length<=50}isPortInUse(e){const t=this.listServiceConfigs();for(const r of t)try{if(this.loadServiceConfig(r).ssh.port===e)return!0}catch(e){}return!1}async generateServiceKeyPair(t){const r=this.generateSecurePassphrase(),o=e.join(this.configDir,"conf.d",t);n.existsSync(o)||n.mkdirSync(o,{recursive:!0});const i=e.join(o,"server_private_key"),a=e.join(o,"server_public_key.pub");return n.existsSync(i)||(console.log(`Generating SSH server key pair for service '${t}'...`),s(`ssh-keygen -t rsa -b 4096 -f ${i} -N '${r}' -C 'wative_${t}_server'`,{stdio:"inherit"})),{privateKey:i,publicKey:a,passphrase:r}}async generateClientKeyPair(t,r){const s=e.join(this.configDir,"conf.d",t);n.existsSync(s)||n.mkdirSync(s,{recursive:!0});return{privateKey:"",publicKey:e.join(s,`${r}.pub`),passphrase:""}}generateSecurePassphrase(){return l.randomBytes(32).toString("hex")}getServiceConfigPath(t){return e.join(this.configDir,"conf.d",t,"config.ini")}saveServiceConfig(t,r){const s=this.getServiceConfigPath(t),o=e.dirname(s);n.existsSync(o)||n.mkdirSync(o,{recursive:!0});const i=c.stringify(r);n.writeFileSync(s,i)}parseConfigData(e){return{name:e.name,description:e.description,ssh:{listen:e.ssh.listen,port:parseInt(e.ssh.port),log:{size:parseInt(e.ssh.log.size),backups:parseInt(e.ssh.log.backups)}},keystore:{path:e.keystore.path,allowed_keystores:Array.isArray(e.keystore.allowed_keystores)?e.keystore.allowed_keystores:e.keystore.allowed_keystores.split(",")},clients:Array.isArray(e.clients)?e.clients:[e.clients],server_keys:{private_key_path:e.server_keys.private_key_path,passphrase:e.server_keys.passphrase}}}removeServiceKeys(t){const r=[`id_rsa_${t}_server`,`id_rsa_${t}_server.pub`,`id_rsa_${t}_*`];for(const t of r){const r=e.join(this.configDir,t);n.existsSync(r)&&n.unlinkSync(r)}}}require("chalk"),require("chalk"),require("chalk"),process.env.HOME||process.env.USERPROFILE;const E=async e=>{const t=[{name:"password",type:"password",mask:"#",message:`${e}:`}];let{password:r}=await h.prompt(t);return r};require("bn.js"),require("ethereumjs-util"),require("bignumber.js"),require("chalk"),require("wative-core"),require("chalk"),require("dotenv").config(),require("cli-progress"),require("wative-core");const{WativeCore:A}=require("wative-core"),{Connection:j,PublicKey:$,VersionedTransaction:C,VersionedMessage:T}=require("@solana/web3.js"),K=require("bs58"),{Keypair:M,TransactionMessage:O,ComputeBudgetInstruction:D,TransactionInstruction:L,ComputeBudgetProgram:q}=require("@solana/web3.js"),{Wallet:H}=require("@coral-xyz/anchor");m.configure({appenders:{file:{type:"file",filename:process.env.HOME+"/.wative/logs/wative.log",maxLogSize:10485760,backups:3,compress:!0,keepFileExt:!0,layout:{type:"pattern",pattern:"%d{yyyy-MM-dd hh:mm:ss.SSS} [%p] %c - %m"},encoding:"utf-8"},console:{type:"console"}},categories:{default:{appenders:["file","console"],level:"info"}}});const z=m.getLogger("file");z.level="info";class N{constructor(e,t,r,s,o,i,c,l){if(this._allowedAppIds=[],this._allowedPubKeys=[],this._allowedKeystoreIds=[],this._sessionIdAppIdMap={},(e=>{if(e=e.trim(),!n.existsSync(e))throw new Error("File not exists")})(e),0===r.length||0===s.length||0===o.length||r.length!==s.length||r.length!==o.length)throw new Error("WativeWielderServer:: constructor: Invaild AllowedApp");for(let e=0;e<o.length;e++)for(let t=0;t<o[e].length;t++){const r=o[e][t];if(!c.includes(r))throw new Error("WativeWielderServer:: constructor: Invaild AllowedKeystoreIds")}for(let e of r)this._allowedAppIds.push(Buffer.from(e));for(let e of s){let t=p.parseKey(a(e));this._allowedPubKeys.push(t)}this.wativeCore=new A(i,c,l),this._idRsaPrivatePath=e,this._idRsaPassphrase=t,this._allowedKeystoreIds=o,this._keystoreDirectoryPath=i}listen(e,t){new d({hostKeys:[{key:a(this._idRsaPrivatePath),passphrase:this._idRsaPassphrase}]},e=>{e.on("authentication",t=>{let r=!0;if(this&&(this.checkValue(Buffer.from(t.username),"appId")||(r=!1)),"publickey"!==t.method||!r)return t.reject();{let e=this.getBytesIndex(Buffer.from(t.username),this._allowedAppIds),r=this._allowedPubKeys[e];if(t.key.algo!==r.type||!this.checkValue(t.key.data,"publicKey")||t.signature&&!0!==r.verify(t.blob,t.signature,t.hashAlgo))return t.reject()}if(r){const r=e._protocol._kex.sessionID.toString("hex");this._sessionIdAppIdMap[r]=Buffer.from(t.username),t.accept()}else t.reject()}).on("ready",()=>{e.on("session",(t,r)=>{t().once("exec",async(t,r,s)=>{const o=e._protocol._kex.sessionID.toString("hex"),n=await this.web3Request(o,s.command),i=t();i&&(JSON.stringify(n)?(i.write(JSON.stringify(n)),i.exit(0),i.end()):(i.write("ssh2 connect error"),i.exit(0),i.end()))})})}).on("close",()=>{z.info("Client disconnected")}).on("error",e=>{z.error("err: ",e.message)})}).listen(t,e,function(){z.info("Listening on port "+t)})}async web3Request(e,t){try{const r=this._sessionIdAppIdMap[e],s=this.getBytesIndex(r,this._allowedAppIds);if(s<0)return{status:!1,msg:"app not found"};let o=JSON.parse(t);z.info("sign message: ",t);let n=o.method,i=o.keystoreId||o.params.keystoreId,a=o.chainId||o.params.chainId;if(!this._allowedKeystoreIds[s].includes(i))return{status:!1,msg:"keystore not allowed"};let c;if("get_root_account"===n)c=this.getRootAccount(i,a);else if("get_sub_account"===n){let e=o.params;c=this.getSubAccount(i,e.chainId,null==e?void 0:e.startIndex,null==e?void 0:e.endIndex)}else if("sign"===n){let e=o.params;try{c=await this.wativeCore.account.signTransaction(e.txParams.from,e.txParams,e.rpcUrl)}catch(e){return z.error("sign error: ",e.message),{status:!1,msg:e.msg}}}else if("sign_and_send"===n){let e=o.params;try{c={transactionHash:await this.wativeCore.account.signAndSendTx(e.txParams,e.rpcUrl)}}catch(e){return{status:!1,msg:e.msg}}}else if("solana_sign"===n)try{let e=o.params;c=await this.signSolanaTransaction(e.txParams.from,e.txParams.data,e.txParams.lookup_tables,e.rpcUrl,e.priority_fee)}catch(e){return z.error("sign error: ",e.message),{status:!1,msg:e.msg}}else if("solana_send"===n)try{let e=o.params;c=await this.sendSignedSolanaTransaction(e.txParams.from,e.txParams.signature,e.txParams.data,e.rpcUrl)}catch(e){return z.error("sign error: ",e.message),{status:!1,msg:e.msg}}else if("sign_message"===n)try{let e=o.params;z.debug("sign message: ",e),c=await this.signMessage(e.account,e.message)}catch(e){return z.error("sign error: ",e.message),{status:!1,msg:e.msg}}else{if("sign_typed_data"!==n)return{status:!1,msg:"message method not find"};try{let e=o.params;z.debug("sign message: ",e),c=await this.signTypedData(e.account,e.domain,e.types_name,e.types,e.message)}catch(e){return z.error("sign error: ",e.message),{status:!1,msg:e.msg}}}return{status:!0,data:c}}catch(e){return z.error("sign error: ",e.message),{status:!1,msg:e.msg}}}checkValue(e,t){if("appId"!==t&&"publicKey"!==t)return!1;let r=this._allowedAppIds.length;for(let s=0;s<r;s++){let r;r="appId"===t?this._allowedAppIds[s]:this._allowedPubKeys[s].getPublicSSH();const o=e.length!==r.length;o&&(r=e);const n=u(e,r);if(!o&&n)return!0}}getBytesIndex(e,t){let r=t.length;for(let s=0;s<r;s++)if(e.length===t[s].length&&u(e,t[s]))return s;return-1}getRootAccount(t,r){const s=e.resolve(this._keystoreDirectoryPath,`accounts/${t}.json`);let o,n=a(s);return n=JSON.parse(n.toString()),o="SOLANA"===this.getChainType(r)?n.data[0].ciphertexts.solana.address:n.data[0].ciphertexts.evm.address,[{id:0,address:o,children:n.data.length,type:"M"}]}getChainType(e){return"901"===e||"902"===e||"903"===e?"SOLANA":"EVM"}getSubAccount(t,r,s,o){const n=e.resolve(this._keystoreDirectoryPath,`accounts/${t}.json`);let i=a(n);i=JSON.parse(i.toString());let c=i.data.length-1;o&&o<c&&(c=o);let l=0;if(s&&s>0&&(l=s),l>c)return[];let u=this.getChainType(r),p=[];for(let e=l;e<=c;e++)p.push(i.data[e].ciphertexts[u.toLocaleLowerCase()].address);return p}async signMessage(e,t){let r=await this.wativeCore.account.signMessage(e,t);return console.log(r),r}async signTypedData(e,t,r,s,o){let n=JSON.parse(t),i=JSON.parse(s),a=JSON.parse(o);console.log(n),console.log(i),console.log(a);let c=this.wativeCore.account.showPrivateKey(e),l=new y.Wallet(c),u=await l.signTypedData(n,{[r]:i},a);return console.log(u),{status:!0,output:u}}async signSolanaTransaction(e,t,r,s,o){let n=new j(s),i=[];if(r)for(let e of r){let t=(await n.getAddressLookupTable(new $(e))).value;i.push(t),await R(1e3)}let a=T.deserialize(Uint8Array.from(Buffer.from(t,"hex"))),c=O.decompile(a);c.instructions.push(q.setComputeUnitLimit({units:2e6})),c.instructions.push(q.setComputeUnitPrice({microLamports:1e3})),a=c.compileToV0Message(i),a.recentBlockhash=(await n.getLatestBlockhash()).blockhash,await R(3e3);let l=new C(a),u=this.wativeCore.account.showPrivateKey(e);const p=M.fromSecretKey(new Uint8Array(K.decode(u))),d=new H(p);let h=await n.simulateTransaction(l);if(!h||!h.value||0===h.value.unitsConsumed||h.value.err)return{status:!1,output:h.value.err};let g=c.instructions.length,f=Math.trunc(1.2*h.value.unitsConsumed);if(c.instructions[g-2]=q.setComputeUnitLimit({units:f}),!o||"null"==o)try{o=await this.getPrioritizationFee(s)}catch(e){o=2e5}o<1e4&&(o=1e4),o>5e5&&(o=5e5),c.instructions[g-1]=q.setComputeUnitPrice({microLamports:o}),a=c.compileToV0Message(i),await R(1e3),a.recentBlockhash=(await n.getLatestBlockhash()).blockhash,l=new C(a),l.feePayer=d.publicKey,await R(3e3);let m=await this.wativeCore.account.signTransaction(e,l,s),y=new C(m.output.message,m.output.signatures).message.serialize();return y=Buffer.from(y).toString("hex"),{status:!0,output:{transactionHash:K.encode(m.output.signatures[0]),message:y,compute_units:h.value.unitsConsumed.toString()}}}async sendSignedSolanaTransaction(e,t,r,s){let o=[K.decode(t)],n=T.deserialize(Uint8Array.from(Buffer.from(r,"hex"))),i=new C(n,o);return await this.wativeCore.account.sendSignedTransaction(e,i,s)}async getPrioritizationFee(e){let t=new $("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4");const r=new j(e,"confirmed");let s=await r.getSignaturesForAddress(t,{limit:5});await R(2e3);let o=[];for(let e=0;e<s.length;e++)o.push(s[e].signature);let n=await r.getParsedTransactions(o,{maxSupportedTransactionVersion:0}),i=0;for(let e=0;e<n.length;e++){let t=n[e].transaction.message.instructions;for(let e=0;e<t.length;e++)if("ComputeBudget111111111111111111111111111111"===t[e].programId.toBase58()){let r=t[e].data;try{let e=new L({keys:[],programId:new $("ComputeBudget111111111111111111111111111111"),data:Buffer.from(K.decode(r))}),{microLamports:t}=D.decodeSetComputeUnitPrice(e);i+=Number(t);continue}catch(e){}}}return Math.ceil(i/5)}}const R=e=>new Promise(t=>setTimeout(t,e));"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var F={exports:{}},B={name:"wative-core",version:"1.0.21",description:"An agile keystore management toolkit",main:"lib/index.umd.js",module:"lib/index.esm.js",types:"lib/index.d.ts",scripts:{test:"jest",compile:"tsc",build:"rollup --config"},repository:{type:"git",url:""},bugs:{url:"https://github.com"},homepage:"https://github.com",keywords:["keystore","wallet"],author:"",license:"ISC",files:["src/","lib/"],dependencies:{"@babel/plugin-transform-modules-commonjs":"7.24.1","@rollup/plugin-commonjs":"21.0.1","@solana/web3.js":"1.91.8","@types/bs58":"4.0.4","crypto-js":"4.2.0","ethereumjs-wallet":"1.0.2",jest:"27.5.1","micro-ed25519-hdkey":"0.1.2",rollup:"2.79.1","rollup-plugin-terser":"7.0.2","rollup-plugin-typescript2":"0.31.2",tslib:"2.6.2",typescript:"4.9.5",web3:"1.7.3","web3-core":"4.3.2","@coral-xyz/anchor":"0.30.1","@types/crypto-js":"4.2.2","nodejs-threadpool":"1.0.1",tweetnacl:"1.0.3","rpc-websockets":"7.10.0"}};!function(e,t,r,s,o,n,i,a,c,l,u,p){function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function h(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,s.get?s:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,Object.freeze(t)}var g=h(t),f=h(r),m=d(s),y=h(o),v=h(n),w=h(i),b=h(l),S=function(){return S=Object.assign||function(e){for(var t,r=1,s=arguments.length;r<s;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},S.apply(this,arguments)};function k(e,t,r,s){return new(r||(r=Promise))(function(o,n){function i(e){try{c(s.next(e))}catch(e){n(e)}}function a(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(i,a)}c((s=s.apply(e,t||[])).next())})}function x(e,t){var r,s,o,n={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(n=0)),n;)try{if(r=1,s&&(o=2&a[0]?s.return:a[0]?s.throw||((o=s.return)&&o.call(s),0):s.next)&&!(o=o.call(s,a[1])).done)return o;switch(s=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return n.label++,{value:a[1],done:!1};case 5:n.label++,s=a[1],a=[0];continue;case 7:a=n.ops.pop(),n.trys.pop();continue;default:if(!((o=(o=n.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){n=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){n.label=a[1];break}if(6===a[0]&&n.label<o[1]){n.label=o[1],o=a;break}if(o&&n.label<o[2]){n.label=o[2],n.ops.push(a);break}o[2]&&n.ops.pop(),n.trys.pop();continue}a=t.call(e,n)}catch(e){a=[6,e],s=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}"function"==typeof SuppressedError&&SuppressedError;var _=function(e,t){return k(void 0,void 0,void 0,function(){var r,s,o;return x(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,e.apply(void 0,t)];case 1:return s=n.sent(),r={status:!0,output:s},[3,3];case 2:return o=n.sent(),r={status:!1,output:o.toString()},[3,3];case 3:return[2,r]}})})},P=function(){function e(e){this.web3=new m.default(e)}return e.prototype.getEvmGasPrice=function(){return k(this,void 0,void 0,function(){return x(this,function(e){switch(e.label){case 0:return[4,_(this.web3.eth.getGasPrice,[])];case 1:return[2,e.sent()]}})})},e.prototype.getEvmGasLimit=function(e,t){return k(this,void 0,void 0,function(){return x(this,function(r){switch(r.label){case 0:return[4,_(this.web3.eth.estimateGas,[e,t])];case 1:return[2,r.sent()]}})})},e}(),I=function(e){return e=e.trim(),g.existsSync(e)},E=function(e,t){var r=t.length;if(0===r)return!0;for(var s=0;s<r;s++){var o=f.join(e,"accounts/".concat(t[s],".json"));if(!I(o))return!1}return!0},A=function(e){return(e=(e=(e=e.trim()).toLocaleLowerCase()).replace(/\s+/g,"-").trim()).replace(/\-+/g,"-").trim()},j=function(e,t){var r=[],s=f.join(e,"network.json");if(!I(s))throw new Error("network.json not found");for(var o=function(e){for(var t=[],r=0;r<e.length;r++)t.push(A(e[r]));return t}($(s).accounts),n=0;n<t.length;n++)o.includes(t[n])&&r.push(t[n]);return r},$=function(e){var t=g.readFileSync(e).toString();return JSON.parse(t)},C=function(e,t){var r=JSON.stringify(e);g.writeFileSync(t,r)},T=function(e,t){return b.AES.encrypt(e,t).toString()},K=function(e,t){return b.AES.decrypt(e,t).toString(b.enc.Utf8)},M=["abandon","ability","able","about","above","absent","absorb","abstract","absurd","abuse","access","accident","account","accuse","achieve","acid","acoustic","acquire","across","act","action","actor","actress","actual","adapt","add","addict","address","adjust","admit","adult","advance","advice","aerobic","affair","afford","afraid","again","age","agent","agree","ahead","aim","air","airport","aisle","alarm","album","alcohol","alert","alien","all","alley","allow","almost","alone","alpha","already","also","alter","always","amateur","amazing","among","amount","amused","analyst","anchor","ancient","anger","angle","angry","animal","ankle","announce","annual","another","answer","antenna","antique","anxiety","any","apart","apology","appear","apple","approve","april","arch","arctic","area","arena","argue","arm","armed","armor","army","around","arrange","arrest","arrive","arrow","art","artefact","artist","artwork","ask","aspect","assault","asset","assist","assume","asthma","athlete","atom","attack","attend","attitude","attract","auction","audit","august","aunt","author","auto","autumn","average","avocado","avoid","awake","aware","away","awesome","awful","awkward","axis","baby","bachelor","bacon","badge","bag","balance","balcony","ball","bamboo","banana","banner","bar","barely","bargain","barrel","base","basic","basket","battle","beach","bean","beauty","because","become","beef","before","begin","behave","behind","believe","below","belt","bench","benefit","best","betray","better","between","beyond","bicycle","bid","bike","bind","biology","bird","birth","bitter","black","blade","blame","blanket","blast","bleak","bless","blind","blood","blossom","blouse","blue","blur","blush","board","boat","body","boil","bomb","bone","bonus","book","boost","border","boring","borrow","boss","bottom","bounce","box","boy","bracket","brain","brand","brass","brave","bread","breeze","brick","bridge","brief","bright","bring","brisk","broccoli","broken","bronze","broom","brother","brown","brush","bubble","buddy","budget","buffalo","build","bulb","bulk","bullet","bundle","bunker","burden","burger","burst","bus","business","busy","butter","buyer","buzz","cabbage","cabin","cable","cactus","cage","cake","call","calm","camera","camp","can","canal","cancel","candy","cannon","canoe","canvas","canyon","capable","capital","captain","car","carbon","card","cargo","carpet","carry","cart","case","cash","casino","castle","casual","cat","catalog","catch","category","cattle","caught","cause","caution","cave","ceiling","celery","cement","census","century","cereal","certain","chair","chalk","champion","change","chaos","chapter","charge","chase","chat","cheap","check","cheese","chef","cherry","chest","chicken","chief","child","chimney","choice","choose","chronic","chuckle","chunk","churn","cigar","cinnamon","circle","citizen","city","civil","claim","clap","clarify","claw","clay","clean","clerk","clever","click","client","cliff","climb","clinic","clip","clock","clog","close","cloth","cloud","clown","club","clump","cluster","clutch","coach","coast","coconut","code","coffee","coil","coin","collect","color","column","combine","come","comfort","comic","common","company","concert","conduct","confirm","congress","connect","consider","control","convince","cook","cool","copper","copy","coral","core","corn","correct","cost","cotton","couch","country","couple","course","cousin","cover","coyote","crack","cradle","craft","cram","crane","crash","crater","crawl","crazy","cream","credit","creek","crew","cricket","crime","crisp","critic","crop","cross","crouch","crowd","crucial","cruel","cruise","crumble","crunch","crush","cry","crystal","cube","culture","cup","cupboard","curious","current","curtain","curve","cushion","custom","cute","cycle","dad","damage","damp","dance","danger","daring","dash","daughter","dawn","day","deal","debate","debris","decade","december","decide","decline","decorate","decrease","deer","defense","define","defy","degree","delay","deliver","demand","demise","denial","dentist","deny","depart","depend","deposit","depth","deputy","derive","describe","desert","design","desk","despair","destroy","detail","detect","develop","device","devote","diagram","dial","diamond","diary","dice","diesel","diet","differ","digital","dignity","dilemma","dinner","dinosaur","direct","dirt","disagree","discover","disease","dish","dismiss","disorder","display","distance","divert","divide","divorce","dizzy","doctor","document","dog","doll","dolphin","domain","donate","donkey","donor","door","dose","double","dove","draft","dragon","drama","drastic","draw","dream","dress","drift","drill","drink","drip","drive","drop","drum","dry","duck","dumb","dune","during","dust","dutch","duty","dwarf","dynamic","eager","eagle","early","earn","earth","easily","east","easy","echo","ecology","economy","edge","edit","educate","effort","egg","eight","either","elbow","elder","electric","elegant","element","elephant","elevator","elite","else","embark","embody","embrace","emerge","emotion","employ","empower","empty","enable","enact","end","endless","endorse","enemy","energy","enforce","engage","engine","enhance","enjoy","enlist","enough","enrich","enroll","ensure","enter","entire","entry","envelope","episode","equal","equip","era","erase","erode","erosion","error","erupt","escape","essay","essence","estate","eternal","ethics","evidence","evil","evoke","evolve","exact","example","excess","exchange","excite","exclude","excuse","execute","exercise","exhaust","exhibit","exile","exist","exit","exotic","expand","expect","expire","explain","expose","express","extend","extra","eye","eyebrow","fabric","face","faculty","fade","faint","faith","fall","false","fame","family","famous","fan","fancy","fantasy","farm","fashion","fat","fatal","father","fatigue","fault","favorite","feature","february","federal","fee","feed","feel","female","fence","festival","fetch","fever","few","fiber","fiction","field","figure","file","film","filter","final","find","fine","finger","finish","fire","firm","first","fiscal","fish","fit","fitness","fix","flag","flame","flash","flat","flavor","flee","flight","flip","float","flock","floor","flower","fluid","flush","fly","foam","focus","fog","foil","fold","follow","food","foot","force","forest","forget","fork","fortune","forum","forward","fossil","foster","found","fox","fragile","frame","frequent","fresh","friend","fringe","frog","front","frost","frown","frozen","fruit","fuel","fun","funny","furnace","fury","future","gadget","gain","galaxy","gallery","game","gap","garage","garbage","garden","garlic","garment","gas","gasp","gate","gather","gauge","gaze","general","genius","genre","gentle","genuine","gesture","ghost","giant","gift","giggle","ginger","giraffe","girl","give","glad","glance","glare","glass","glide","glimpse","globe","gloom","glory","glove","glow","glue","goat","goddess","gold","good","goose","gorilla","gospel","gossip","govern","gown","grab","grace","grain","grant","grape","grass","gravity","great","green","grid","grief","grit","grocery","group","grow","grunt","guard","guess","guide","guilt","guitar","gun","gym","habit","hair","half","hammer","hamster","hand","happy","harbor","hard","harsh","harvest","hat","have","hawk","hazard","head","health","heart","heavy","hedgehog","height","hello","helmet","help","hen","hero","hidden","high","hill","hint","hip","hire","history","hobby","hockey","hold","hole","holiday","hollow","home","honey","hood","hope","horn","horror","horse","hospital","host","hotel","hour","hover","hub","huge","human","humble","humor","hundred","hungry","hunt","hurdle","hurry","hurt","husband","hybrid","ice","icon","idea","identify","idle","ignore","ill","illegal","illness","image","imitate","immense","immune","impact","impose","improve","impulse","inch","include","income","increase","index","indicate","indoor","industry","infant","inflict","inform","inhale","inherit","initial","inject","injury","inmate","inner","innocent","input","inquiry","insane","insect","inside","inspire","install","intact","interest","into","invest","invite","involve","iron","island","isolate","issue","item","ivory","jacket","jaguar","jar","jazz","jealous","jeans","jelly","jewel","job","join","joke","journey","joy","judge","juice","jump","jungle","junior","junk","just","kangaroo","keen","keep","ketchup","key","kick","kid","kidney","kind","kingdom","kiss","kit","kitchen","kite","kitten","kiwi","knee","knife","knock","know","lab","label","labor","ladder","lady","lake","lamp","language","laptop","large","later","latin","laugh","laundry","lava","law","lawn","lawsuit","layer","lazy","leader","leaf","learn","leave","lecture","left","leg","legal","legend","leisure","lemon","lend","length","lens","leopard","lesson","letter","level","liar","liberty","library","license","life","lift","light","like","limb","limit","link","lion","liquid","list","little","live","lizard","load","loan","lobster","local","lock","logic","lonely","long","loop","lottery","loud","lounge","love","loyal","lucky","luggage","lumber","lunar","lunch","luxury","lyrics","machine","mad","magic","magnet","maid","mail","main","major","make","mammal","man","manage","mandate","mango","mansion","manual","maple","marble","march","margin","marine","market","marriage","mask","mass","master","match","material","math","matrix","matter","maximum","maze","meadow","mean","measure","meat","mechanic","medal","media","melody","melt","member","memory","mention","menu","mercy","merge","merit","merry","mesh","message","metal","method","middle","midnight","milk","million","mimic","mind","minimum","minor","minute","miracle","mirror","misery","miss","mistake","mix","mixed","mixture","mobile","model","modify","mom","moment","monitor","monkey","monster","month","moon","moral","more","morning","mosquito","mother","motion","motor","mountain","mouse","move","movie","much","muffin","mule","multiply","muscle","museum","mushroom","music","must","mutual","myself","mystery","myth","naive","name","napkin","narrow","nasty","nation","nature","near","neck","need","negative","neglect","neither","nephew","nerve","nest","net","network","neutral","never","news","next","nice","night","noble","noise","nominee","noodle","normal","north","nose","notable","note","nothing","notice","novel","now","nuclear","number","nurse","nut","oak","obey","object","oblige","obscure","observe","obtain","obvious","occur","ocean","october","odor","off","offer","office","often","oil","okay","old","olive","olympic","omit","once","one","onion","online","only","open","opera","opinion","oppose","option","orange","orbit","orchard","order","ordinary","organ","orient","original","orphan","ostrich","other","outdoor","outer","output","outside","oval","oven","over","own","owner","oxygen","oyster","ozone","pact","paddle","page","pair","palace","palm","panda","panel","panic","panther","paper","parade","parent","park","parrot","party","pass","patch","path","patient","patrol","pattern","pause","pave","payment","peace","peanut","pear","peasant","pelican","pen","penalty","pencil","people","pepper","perfect","permit","person","pet","phone","photo","phrase","physical","piano","picnic","picture","piece","pig","pigeon","pill","pilot","pink","pioneer","pipe","pistol","pitch","pizza","place","planet","plastic","plate","play","please","pledge","pluck","plug","plunge","poem","poet","point","polar","pole","police","pond","pony","pool","popular","portion","position","possible","post","potato","pottery","poverty","powder","power","practice","praise","predict","prefer","prepare","present","pretty","prevent","price","pride","primary","print","priority","prison","private","prize","problem","process","produce","profit","program","project","promote","proof","property","prosper","protect","proud","provide","public","pudding","pull","pulp","pulse","pumpkin","punch","pupil","puppy","purchase","purity","purpose","purse","push","put","puzzle","pyramid","quality","quantum","quarter","question","quick","quit","quiz","quote","rabbit","raccoon","race","rack","radar","radio","rail","rain","raise","rally","ramp","ranch","random","range","rapid","rare","rate","rather","raven","raw","razor","ready","real","reason","rebel","rebuild","recall","receive","recipe","record","recycle","reduce","reflect","reform","refuse","region","regret","regular","reject","relax","release","relief","rely","remain","remember","remind","remove","render","renew","rent","reopen","repair","repeat","replace","report","require","rescue","resemble","resist","resource","response","result","retire","retreat","return","reunion","reveal","review","reward","rhythm","rib","ribbon","rice","rich","ride","ridge","rifle","right","rigid","ring","riot","ripple","risk","ritual","rival","river","road","roast","robot","robust","rocket","romance","roof","rookie","room","rose","rotate","rough","round","route","royal","rubber","rude","rug","rule","run","runway","rural","sad","saddle","sadness","safe","sail","salad","salmon","salon","salt","salute","same","sample","sand","satisfy","satoshi","sauce","sausage","save","say","scale","scan","scare","scatter","scene","scheme","school","science","scissors","scorpion","scout","scrap","screen","script","scrub","sea","search","season","seat","second","secret","section","security","seed","seek","segment","select","sell","seminar","senior","sense","sentence","series","service","session","settle","setup","seven","shadow","shaft","shallow","share","shed","shell","sheriff","shield","shift","shine","ship","shiver","shock","shoe","shoot","shop","short","shoulder","shove","shrimp","shrug","shuffle","shy","sibling","sick","side","siege","sight","sign","silent","silk","silly","silver","similar","simple","since","sing","siren","sister","situate","six","size","skate","sketch","ski","skill","skin","skirt","skull","slab","slam","sleep","slender","slice","slide","slight","slim","slogan","slot","slow","slush","small","smart","smile","smoke","smooth","snack","snake","snap","sniff","snow","soap","soccer","social","sock","soda","soft","solar","soldier","solid","solution","solve","someone","song","soon","sorry","sort","soul","sound","soup","source","south","space","spare","spatial","spawn","speak","special","speed","spell","spend","sphere","spice","spider","spike","spin","spirit","split","spoil","sponsor","spoon","sport","spot","spray","spread","spring","spy","square","squeeze","squirrel","stable","stadium","staff","stage","stairs","stamp","stand","start","state","stay","steak","steel","stem","step","stereo","stick","still","sting","stock","stomach","stone","stool","story","stove","strategy","street","strike","strong","struggle","student","stuff","stumble","style","subject","submit","subway","success","such","sudden","suffer","sugar","suggest","suit","summer","sun","sunny","sunset","super","supply","supreme","sure","surface","surge","surprise","surround","survey","suspect","sustain","swallow","swamp","swap","swarm","swear","sweet","swift","swim","swing","switch","sword","symbol","symptom","syrup","system","table","tackle","tag","tail","talent","talk","tank","tape","target","task","taste","tattoo","taxi","teach","team","tell","ten","tenant","tennis","tent","term","test","text","thank","that","theme","then","theory","there","they","thing","this","thought","three","thrive","throw","thumb","thunder","ticket","tide","tiger","tilt","timber","time","tiny","tip","tired","tissue","title","toast","tobacco","today","toddler","toe","together","toilet","token","tomato","tomorrow","tone","tongue","tonight","tool","tooth","top","topic","topple","torch","tornado","tortoise","toss","total","tourist","toward","tower","town","toy","track","trade","traffic","tragic","train","transfer","trap","trash","travel","tray","treat","tree","trend","trial","tribe","trick","trigger","trim","trip","trophy","trouble","truck","true","truly","trumpet","trust","truth","try","tube","tuition","tumble","tuna","tunnel","turkey","turn","turtle","twelve","twenty","twice","twin","twist","two","type","typical","ugly","umbrella","unable","unaware","uncle","uncover","under","undo","unfair","unfold","unhappy","uniform","unique","unit","universe","unknown","unlock","until","unusual","unveil","update","upgrade","uphold","upon","upper","upset","urban","urge","usage","use","used","useful","useless","usual","utility","vacant","vacuum","vague","valid","valley","valve","van","vanish","vapor","various","vast","vault","vehicle","velvet","vendor","venture","venue","verb","verify","version","very","vessel","veteran","viable","vibrant","vicious","victory","video","view","village","vintage","violin","virtual","virus","visa","visit","visual","vital","vivid","vocal","voice","void","volcano","volume","vote","voyage","wage","wagon","wait","walk","wall","walnut","want","warfare","warm","warrior","wash","wasp","waste","water","wave","way","wealth","weapon","wear","weasel","weather","web","wedding","weekend","weird","welcome","west","wet","whale","what","wheat","wheel","when","where","whip","whisper","wide","width","wife","wild","will","win","window","wine","wing","wink","winner","winter","wire","wisdom","wise","wish","witness","wolf","woman","wonder","wood","wool","word","work","world","worry","worth","wrap","wreck","wrestle","wrist","write","wrong","yard","year","yellow","you","young","youth","zebra","zero","zone","zoo"],O=new m.default(m.default.givenProvider),D=function(){function e(e,t,r,s){if(this.account_passwords={},this.account_ciphertexts={},this.disable_address=!1,this.account_signatures="",this.setting_path=e,this.account_labels=t,0!==t.length){if(r){if(t.length!==r.length)throw new Error("account_labels should have same length for account_passwords");for(var o=0;o<t.length;o++){if(!this.checkPassword(t[o],r[o].trim()))throw new Error("account_passwords is not correct");this.account_passwords[t[o]]=r[o].trim()}}s&&(this.disable_address=s),this.reload()}}return e.prototype.isLogin=function(e){return e in this.account_passwords},e.prototype.reloadAccount=function(){this.reload()},e.prototype.getAccountLabel=function(e){var t=null;for(var r in this.account_ciphertexts)r.toLocaleLowerCase().includes(e.toLocaleLowerCase())&&(t=r);return null===t?null:{account_address:t,account_label:this.account_ciphertexts[t].account_label}},e.prototype.login=function(e,t){return this.checkPassword(e,t)?(this.account_passwords[e]=t,this.account_labels.push(e),this.reload(),{status:!0,output:"Login success"}):{status:!1,output:"Password is not correct"}},e.prototype.getAccounts=function(e){var t=this.getAccountSignature();t!==this.account_signatures&&(this.account_signatures=t,this.reload());for(var r=Object.keys(this.account_ciphertexts),s=[],o=0;o<r.length;o++)this.getAccountChainType(r[o])===e&&s.push(r[o]);return s},e.prototype.checkAccountLabelIsExist=function(e){return E(this.setting_path,[e])},e.prototype.checkAccountIsExist=function(e){return(e=this.getAccountChecksumAddress(e))in this.account_ciphertexts||(this.reload(),e in this.account_ciphertexts)},e.prototype.checkPassword=function(e,t){var r=f.join(this.setting_path,"accounts/".concat(e,".json"));if(!I(r))return!1;var s,o=$(r);s="PK"===o.account_type?S({salt:t},o.data[0].ciphertexts):{slat:t,data:o.pp_ciphertexts};var n=b.SHA256(JSON.stringify(s)).toString();return o.signature===n},e.prototype.showPrivateKey=function(e){if(!this.checkAccountIsExist(e))throw new Error("Account is not exist");e=this.getAccountChecksumAddress(e);var t=this.account_ciphertexts[e],r=this.account_passwords[t.account_label];return K(t.data,r)},e.prototype.getAccountChainType=function(e){return e.startsWith("0x")&&42===e.length?"evm":/^[A-HJ-NP-Za-km-z1-9]*$/.test(e)?"solana":"unknown"},e.prototype.generatePKAccount=function(e,t,r,s,o){if(o&&this.checkAccountLabelIsExist(e))throw new Error("Account labels already exist");if(!o&&!this.account_passwords[e])throw new Error("Password is not correct");o||(r=this.account_passwords[e]);var n,i=T(t,r);try{n=this.getAccountAddressByPrivateKey(t,s)}catch(e){return{status:!1,output:e.message}}var a={address:n,data:i},c=S({salt:r},a),l={signature:b.SHA256(JSON.stringify(c)).toString(),account_type:"PK",tag:"",ciphertexts:a};return o||(this.account_passwords[e]=r,this.account_labels.push(e)),{status:!0,output:l}},e.prototype.generatePPAccount=function(e,t,r){if(this.checkAccountLabelIsExist(e))return{status:!1,output:"Account labels already exist"};var s=T(t,r),o={slat:r,data:s},n=b.SHA256(JSON.stringify(o)).toString(),i=this.getSubAccount("evm",t,0);if(!1===i.status)return{status:!1,output:i.output};var a=this.getSubAccount("solana",t,0);if(!1===a.status)return{status:!1,output:a.output};var c={signature:n,account_type:"PP",pp_ciphertexts:s,tag:"",data:[{ciphertexts:{evm:{address:i.output.address,data:T(i.output.pk,r)},solana:{address:a.output.address,data:T(a.output.pk,r)}}}]};return this.account_passwords[e]=r,this.account_labels.push(e),{status:!0,output:c}},e.prototype.generateSubAccount=function(e,t){if(!this.checkAccountLabelIsExist(e))return{status:!1,output:"Account labels not exist"};var r=f.join(this.setting_path,"accounts/".concat(e,".json")),s=$(r).pp_ciphertexts,o=K(s,this.account_passwords[e]),n=this.getSubAccount("evm",o,t);if(!1===n.status)return{status:!1,output:n.output};var i=this.getSubAccount("solana",o,t);return!1===i.status?{status:!1,output:i.output}:{status:!0,output:{evm:{address:n.output.address,data:T(n.output.pk,this.account_passwords[e])},solana:{address:i.output.address,data:T(i.output.pk,this.account_passwords[e])}}}},e.prototype.resetPassword=function(e,t){if(!this.checkAccountLabelIsExist(e))return{status:!1,output:"Account labels not exist"};if(!this.checkPassword(e,this.account_passwords[e]))return{status:!1,output:"account passwords is not correct"};var r=f.join(this.setting_path,"accounts/".concat(e,".json")),s=$(r);if("PK"===s.account_type){for(var o=s.data,n=0;n<o.length;n++){var i=o[n].ciphertexts.data,a=K(i,this.account_passwords[e]);o[n].ciphertexts.data=T(a,t)}var c=S({salt:t},s.data[0].ciphertexts);return s.signature=b.SHA256(JSON.stringify(c)).toString(),C(s,r),delete this.account_passwords[e],{status:!0,output:"Password reset successfully"}}var l=K(s.pp_ciphertexts,this.account_passwords[e]);s.pp_ciphertexts=T(l,t);var u={slat:t,data:s.pp_ciphertexts};s.signature=b.SHA256(JSON.stringify(u)).toString();var p=s.data;for(n=0;n<p.length;n++){var d=K(p[n].ciphertexts.evm.data,this.account_passwords[e]);p[n].ciphertexts.evm.data=T(d,t);var h=K(p[n].ciphertexts.solana.data,this.account_passwords[e]);p[n].ciphertexts.solana.data=T(h,t)}return C(s,r),delete this.account_passwords[e],{status:!0,output:"Password reset successfully"}},e.prototype.signTransaction=function(e,t,r){return e=this.getAccountChecksumAddress(e),this.checkAccountIsExist(e)?"unknown"===this.getAccountChainType(e)?{status:!1,output:"Chain type unknown"}:"evm"===this.getAccountChainType(e)?this.signEvmTransaction(t,r):this.signSolanaTransaction(e,r,t):{status:!1,output:"Account is not exist"}},e.prototype.sendSignedTransaction=function(e,t,r){return e=this.getAccountChecksumAddress(e),this.checkAccountIsExist(e)?"unknown"===this.getAccountChainType(e)?{status:!1,output:"Chain type unknown"}:"evm"===this.getAccountChainType(e)?this.sendEvmTransaction(t,r):this.sendSolanaTransaction(t,r):{status:!1,output:"Account is not exist"}},e.prototype.signMessage=function(e,t){return e=this.getAccountChecksumAddress(e),this.checkAccountIsExist(e)?"unknown"===this.getAccountChainType(e)?{status:!1,output:"Chain type unknown"}:"evm"===this.getAccountChainType(e)?{status:!0,output:this.signEvmMessage(t,e)}:{status:!0,output:this.signSolanaMessage(t,e)}:{status:!1,output:"Account is not exist"}},e.prototype.simulateTransaction=function(e,t,r){return k(this,void 0,void 0,function(){var s,o,n;return x(this,function(i){switch(i.label){case 0:return s=new a.Connection(t),o=this.showPrivateKey(e),n=a.Keypair.fromSecretKey(v.decode(o)),[4,_(s.simulateTransaction.bind(s),[r,[n]])];case 1:return[2,i.sent()]}})})},e.prototype.signEvmTransaction=function(e,t){return k(this,void 0,void 0,function(){var r,s,o,n;return x(this,function(i){switch(i.label){case 0:return this.account_passwords?(r=e.from,e.gas?[3,2]:[4,new P(t).getEvmGasLimit(e,t)]):[2,{status:!1,output:"Please set password first"}];case 1:if(!(s=i.sent()).status)return[2,s];e.gas=s.output,i.label=2;case 2:return e.gasPrice?[3,4]:[4,new P(t).getEvmGasPrice()];case 3:if(!(s=i.sent()).status)return[2,s];e.gasPrice=s.output,i.label=4;case 4:return o=this.showPrivateKey(r),n=new m.default(t),[4,_(n.eth.accounts.signTransaction.bind(n.eth.accounts),[e,o])];case 5:return[2,i.sent()]}})})},e.prototype.sendEvmTransaction=function(e,t){return k(this,void 0,void 0,function(){var r;return x(this,function(s){switch(s.label){case 0:return r=new m.default(t),[4,_(r.eth.sendSignedTransaction.bind(r.eth),[e])];case 1:return[2,s.sent()]}})})},e.prototype.signSolanaTransaction=function(e,t,r){return k(this,void 0,void 0,function(){var s,o,n,i,l;return x(this,function(u){switch(u.label){case 0:return s=this.showPrivateKey(e),o=a.Keypair.fromSecretKey(v.decode(s)),n=new c.Wallet(o),"recentBlockhash"in r&&r.recentBlockhash?[3,2]:(i=new a.Connection(t),[4,_(i.getLatestBlockhash.bind(i),[])]);case 1:if(!(l=u.sent()).status)return[2,{status:!1,output:"Failed to get latest blockhash"}];r.recentBlockhash=l.output.blockhash,u.label=2;case 2:return r.feePayer=n.publicKey,[4,_(n.signTransaction.bind(n),[r])];case 3:return[2,u.sent()]}})})},e.prototype.sendSolanaTransaction=function(e,t){return k(this,void 0,void 0,function(){var r;return x(this,function(s){switch(s.label){case 0:return r=new a.Connection(t),[4,_(r.sendRawTransaction.bind(r),[e.serialize()])];case 1:return[2,s.sent()]}})})},e.prototype.signEvmMessage=function(e,t){var r=this.showPrivateKey(t);return O.eth.accounts.sign(e,r).signature},e.prototype.signSolanaMessage=function(e,t){var r=this.showPrivateKey(t),s=y.sign.detached(new Uint8Array(e.match(/.{1,2}/g).map(function(e){return parseInt(e,16)})),v.decode(r));return v.encode(s)},e.prototype.checkIsDisableAddress=function(e,t){if(!e||!this.disable_address)return!1;for(var r=e.length,s=0;s<r;s++){var o=e[s].from,n=e[s].to;if(t>=o&&t<=n)return!0}return!1},e.prototype.reload=function(){if(this.account_labels=j(this.setting_path,this.account_labels),!E(this.setting_path,this.account_labels))throw new Error("Account labels not exist");for(var e={},t=this.account_labels.length,r=0;r<t;r++){var s=f.join(this.setting_path,"accounts/".concat(this.account_labels[r],".json"));if(g.existsSync(s)){var o=JSON.parse(g.readFileSync(s,"utf8"));if("PK"!==o.account_type){var n=o.data.length,i=o.disabled_slots;for(l=0;l<n;l++)this.checkIsDisableAddress(i,l)||(e[o.data[l].ciphertexts.evm.address]={account_label:this.account_labels[r],data:o.data[l].ciphertexts.evm.data},e[o.data[l].ciphertexts.solana.address]={account_label:this.account_labels[r],data:o.data[l].ciphertexts.solana.data})}else{var a=o.data;if(!a)continue;for(var c=a.length,l=0;l<c;l++)e[a[l].ciphertexts.address]={account_label:this.account_labels[r],data:a[l].ciphertexts.data}}}}this.account_ciphertexts=e},e.prototype.getAccountChecksumAddress=function(e){return"evm"===this.getAccountChainType(e)&&(e=O.utils.toChecksumAddress(e)),e},e.prototype.getAccountAddressByPrivateKey=function(e,t){return"evm"===this.getNetworkTypeByChainId(t)?O.eth.accounts.privateKeyToAccount(e).address:a.Keypair.fromSecretKey(v.decode(e)).publicKey.toBase58()},e.prototype.getNetworkTypeByChainId=function(e){return"901"===e||"902"===e||"903"===e?"solana":"evm"},e.prototype.getSubAccount=function(e,t,r){if(!function(e){var t=e.split(/\s+/g),r=t.length;if(12!==r&&24!==r)return!1;for(var s=0;s<r;s++)if(!M.includes(t[s]))return!1;return!0}(t))return{status:!1,output:"Please set correct mnemonic"};if("solana"===e){var s=w.mnemonicToSeedSync(t),o=p.HDKey.fromMasterSeed(s),n=a.Keypair.fromSeed(o.derive("m/44'/501'/".concat(r,"'/0'")).privateKey);return{status:!0,output:{address:n.publicKey.toBase58(),pk:v.encode(n.secretKey)}}}if("evm"===e){s=w.mnemonicToSeedSync(t);var i=(o=u.hdkey.fromMasterSeed(s)).derivePath("m/44'/60'/0'/0").deriveChild(r).getWallet();return{status:!0,output:{address:O.utils.toChecksumAddress(i.getAddressString()),pk:i.getPrivateKeyString()}}}return{status:!1,output:"Unknown chain type"}},e.prototype.getAccountSignature=function(){for(var e=this.account_labels.length,t=[],r=0;r<e;r++){var s=f.join(this.setting_path,"accounts/".concat(this.account_labels[r],".json")),o=g.readFileSync(s,"utf8");t.push(o)}return b.MD5(JSON.stringify(t)).toString()},e}(),L=B,q=function(){function e(e,t,r,s){this.account=new D(e,t,r,s)}return e.version=L.version,e}();e.WativeCore=q,Object.defineProperty(e,"__esModule",{value:!0})}(F.exports,i,t,g,v,w,b,f,S,k,x,_);class W{constructor(t,r){this.runningServices=new Map,this.configManager=new I(t,r),this.pidDir=e.join(this.configManager.getKeystorePath(),"ssh","pids"),this.ensurePidDir(),this.setupLogger()}ensurePidDir(){n.existsSync(this.pidDir)||n.mkdirSync(this.pidDir,{recursive:!0})}async isPortInUse(e,t="127.0.0.1"){return new Promise(r=>{const s=P.createServer();s.listen(e,t,()=>{s.once("close",()=>{r(!1)}),s.close()}),s.on("error",e=>{"EADDRINUSE"===e.code?r(!0):r(!1)})})}getPidFilePath(t){return e.join(this.pidDir,`${t}.pid`)}writePidFile(e,t){const r=this.getPidFilePath(e);n.writeFileSync(r,t.toString())}readPidFile(e){const t=this.getPidFilePath(e);if(!n.existsSync(t))return null;try{const e=n.readFileSync(t,"utf8").trim();return parseInt(e,10)}catch(e){return null}}removePidFile(e){const t=this.getPidFilePath(e);n.existsSync(t)&&n.unlinkSync(t)}isProcessRunning(e){try{return process.kill(e,0),!0}catch(e){return!1}}async startService(e,t){if(this.runningServices.has(e))throw new Error(`Service '${e}' is already running.`);const r=this.configManager.loadServiceConfig(e);if(await this.isPortInUse(r.ssh.port,r.ssh.listen)){const t=`Port ${r.ssh.port} on ${r.ssh.listen} is already in use. Cannot start SSH service '${e}'.`;throw this.logger.error(t),console.error(`Error: ${t}`),new Error(t)}this.logger.info(`Port ${r.ssh.port} on ${r.ssh.listen} is available for service '${e}'`);const s=t||await this.promptForPasswords(r.keystore.allowed_keystores),o=await this.configManager.validateKeystorePasswords(r.keystore.allowed_keystores,s),n=Object.entries(o).filter(([e,t])=>!t).map(([e,t])=>e);if(n.length>0)throw new Error(`Invalid passwords for keystores: ${n.join(", ")}`);const i=this.createServerInstance(r,s);i.listen(r.ssh.listen,r.ssh.port),this.writePidFile(e,process.pid),this.logger.info(`SSH service '${e}' started on ${r.ssh.listen}:${r.ssh.port}`),console.log(`SSH service '${e}' is now running in the background on ${r.ssh.listen}:${r.ssh.port}`);const a={config:r,passwords:s,server:i};this.runningServices.set(e,a),this.setupServiceLogger(e)}async stopService(t){const r=this.runningServices.get(t),s=this.readPidFile(t),o=e.join(this.pidDir,`${t}-daemon.pid`),i=e.join(this.pidDir,`${t}-watcher.pid`);let a=null,c=null;if(n.existsSync(o)){const e=n.readFileSync(o,"utf8").trim();e&&(a=parseInt(e))}if(n.existsSync(i)){const e=n.readFileSync(i,"utf8").trim();e&&(c=parseInt(e))}if(r)r.server&&r.server.close&&r.server.close(),this.runningServices.delete(t);else if(c&&this.isProcessRunning(c))try{process.kill(c,"SIGTERM"),setTimeout(()=>{this.isProcessRunning(c)&&process.kill(c,"SIGKILL");try{n.existsSync(i)&&n.unlinkSync(i),n.existsSync(o)&&n.unlinkSync(o)}catch(e){}},5e3)}catch(e){if(a&&this.isProcessRunning(a))try{process.kill(a,"SIGTERM"),setTimeout(()=>{this.isProcessRunning(a)&&process.kill(a,"SIGKILL")},5e3)}catch(e){}try{n.existsSync(i)&&n.unlinkSync(i),n.existsSync(o)&&n.unlinkSync(o)}catch(e){}}else if(a&&this.isProcessRunning(a))try{process.kill(a,"SIGTERM"),setTimeout(()=>{this.isProcessRunning(a)&&process.kill(a,"SIGKILL")},5e3),n.existsSync(o)&&n.unlinkSync(o)}catch(e){}else{if(!s||!this.isProcessRunning(s))throw new Error(`Service '${t}' is not running.`);try{process.kill(s,"SIGTERM"),setTimeout(()=>{this.isProcessRunning(s)&&process.kill(s,"SIGKILL")},5e3)}catch(e){}}this.removePidFile(t),this.logger.info(`SSH service '${t}' stopped.`)}async restartService(e,t){this.runningServices.has(e)&&await this.stopService(e),await this.startService(e,t)}getRunningServices(){return Array.from(this.runningServices.keys())}getServiceConfig(e){return this.configManager.loadServiceConfig(e)}getServiceStatus(t){if(this.runningServices.has(t))return"running";try{this.configManager.loadServiceConfig(t);const r=e.join(this.pidDir,`${t}-daemon.pid`);if(n.existsSync(r)){const e=n.readFileSync(r,"utf8").trim();if(e){const t=parseInt(e);if(this.isProcessRunning(t))return"running";n.unlinkSync(r)}}const s=this.readPidFile(t);return s&&this.isProcessRunning(s)?"running":(s&&this.removePidFile(t),"stopped")}catch(e){return"not_found"}}async stopAllServices(){const e=Array.from(this.runningServices.keys());for(const t of e)await this.stopService(t)}async createService(e,t,r,s,o){return this.configManager.createServiceConfig(e,t,r,s,o)}async removeService(e){this.runningServices.has(e)&&await this.stopService(e),this.configManager.removeServiceConfig(e),this.logger.info(`Service '${e}' removed.`)}listServices(){return this.configManager.listServiceConfigs().map(e=>{const t=this.getServiceStatus(e);let r,s;try{const t=this.configManager.loadServiceConfig(e);r=t.ssh.port,s=t.description}catch(e){}return{name:e,status:t,port:r,description:s}})}updateServiceKeystores(e,t){this.configManager.updateServiceConfig(e,{keystore:{path:this.configManager.loadServiceConfig(e).keystore.path,allowed_keystores:t}})}async promptForPasswords(e){const t={};for(const r of e){let e,s=!1,o=0;const n=3;for(;!s&&o<n;){e=await E(`Enter password for keystore [${r}]`);try{const i=this.configManager.getKeystorePath();if(s=new F.exports.WativeCore(i,[r]).account.checkPassword(r,e),s){t[r]=e;break}if(o++,!(o<n))throw new Error(`Failed to authenticate keystore [${r}] after ${n} attempts.`);console.log(`Invalid password for ${r}`)}catch(e){if(o++,!(o<n))throw new Error(`Failed to authenticate keystore [${r}] after ${n} attempts: ${e.message}`);console.log("Error validating password for keystore")}}}return t}createServerInstance(e,t){const r=e.clients;if(0===r.length)throw new Error("No clients configured for service");if(r.length>1)throw new Error("Only one client is supported for this service");const s=JSON.parse(r[0]),o=[s.name],n=[s.public_key_path],i=[s.allowed_keystores],a=e.keystore.allowed_keystores;if(0===a.length)throw new Error("No keystores configured for service");let c=[];for(const e of a)c.push(t[e]);return new N(e.server_keys.private_key_path,e.server_keys.passphrase,o,n,i,e.keystore.path,a,c)}async showLogs(t,r=50,s=!1){const i=process.env.HOME+"/.wative/logs";let a;if(a=t?e.join(i,`${t}.log`):e.join(i,"service_manager.log"),!n.existsSync(a))throw new Error(`Log file not found: ${a}`);const c=o("tail",s?["-f",`-n${r}`,a]:[`-n${r}`,a],{stdio:["ignore","inherit","inherit"]});return s?(process.on("SIGINT",()=>{c.kill("SIGTERM"),process.exit(0)}),new Promise((e,t)=>{c.on("close",r=>{0===r?e():t(new Error(`tail process exited with code ${r}`))})})):new Promise((e,t)=>{c.on("close",r=>{0===r?e():t(new Error(`tail process exited with code ${r}`))})})}setupLogger(){const t=process.env.HOME+"/.wative/logs";n.existsSync(t)||n.mkdirSync(t,{recursive:!0}),m.configure({appenders:{file:{type:"file",filename:e.join(t,"service_manager.log"),maxLogSize:10485760,backups:3,compress:!0,keepFileExt:!0,layout:{type:"pattern",pattern:"%d{yyyy-MM-dd hh:mm:ss.SSS} [%p] %c - %m"},encoding:"utf-8"},console:{type:"console"}},categories:{default:{appenders:["file","console"],level:"info"}}}),this.logger=m.getLogger("service_manager"),this.logger.level="info"}setupServiceLogger(t){const r=process.env.HOME+"/.wative/logs";n.existsSync(r)||n.mkdirSync(r,{recursive:!0});const s=e.join(r,`${t}.log`);this.cleanupOldLogs(r),m.configure({appenders:{file:{type:"file",filename:e.join(r,"service_manager.log"),maxLogSize:10485760,backups:3,compress:!0,keepFileExt:!0,layout:{type:"pattern",pattern:"%d{yyyy-MM-dd hh:mm:ss.SSS} [%p] %c - %m"},encoding:"utf-8"},console:{type:"console"},[`${t}_file`]:{type:"file",filename:s,maxLogSize:10485760,backups:3,compress:!0,keepFileExt:!0,layout:{type:"pattern",pattern:"%d{yyyy-MM-dd hh:mm:ss.SSS} [%p] %c - %m"},encoding:"utf-8"}},categories:{default:{appenders:["file","console"],level:"info"},[t]:{appenders:[`${t}_file`],level:"info"}}})}cleanupOldLogs(t){try{const r=n.readdirSync(t),s=new Date;s.setDate(s.getDate()-3),r.forEach(r=>{const o=e.join(t,r);n.statSync(o).mtime<s&&r.endsWith(".log")&&(n.unlinkSync(o),this.logger.info(`Deleted old log file: ${r}`))})}catch(e){this.logger.warn(`Failed to cleanup old logs: ${e}`)}}}const U=new r,G=require("../package.json");let J;U.version(G.version).description("Wative CLI Tool"),U.command("version").description("Show the version of wative").action(()=>{console.log(`Wative CLI Tool v${G.version}`)});const V=()=>{if(!J){const t=e.join(process.env.HOME||"",".wative","ssh");J=new W(t)}return J},Z=U.command("ssh").description("Manage SSH services");Z.command("start").description("Start SSH service").option("-c, --config <name>","Specify service configuration name").option("-d, --daemon","Run service in daemon mode").action(async t=>{const r=V();try{t.config||(console.error("Error: Configuration name is required. Use -c or --config to specify a service configuration."),process.exit(1));const s=t.config,i=r.getServiceConfig(s),a=require("net"),c=async(e,t="127.0.0.1")=>new Promise(r=>{const s=a.createServer();s.listen(e,t,()=>{s.once("close",()=>{r(!1)}),s.close()}),s.on("error",e=>{"EADDRINUSE"===e.code?r(!0):r(!1)})});if(await c(i.ssh.port,i.ssh.listen)){const e=`Port ${i.ssh.port} on ${i.ssh.listen} is already in use. Cannot start SSH service '${s}'.`;console.error(`Error: ${e}`),process.exit(1)}if(console.log(`Port ${i.ssh.port} on ${i.ssh.listen} is available for service '${s}'`),t.daemon){console.log(`Starting SSH service '${s}' in daemon mode...`);const t=await r.promptForPasswords(i.keystore.allowed_keystores),a=require("crypto"),c=a.randomBytes(32),l=a.randomBytes(16),u=a.createCipheriv("aes-256-cbc",c,l);let p=u.update(JSON.stringify(t),"utf8","hex");p+=u.final("hex");const d=l.toString("hex")+":"+c.toString("hex")+":"+p;return void((t,r)=>{const s=e.join(process.env.HOME||"",".wative","logs"),i=e.join(process.env.HOME||"",".wative","ssh","pids");n.existsSync(s)||n.mkdirSync(s,{recursive:!0}),n.existsSync(i)||n.mkdirSync(i,{recursive:!0});const a=e.join(s,`${t}-daemon.log`),c=e.join(i,`${t}-daemon.pid`),l=e.join(i,`${t}-watcher.pid`),u=o("node",[e.resolve(__dirname,"daemon-watcher.js"),t,a,c,l,e.resolve(__dirname,"..")],{detached:!0,stdio:"ignore",env:{...process.env,WATIVE_ENCRYPTED_PASSWORDS:r}});n.writeFileSync(l,u.pid.toString()),u.unref(),console.log(`SSH service '${t}' daemon watcher started with PID: ${u.pid}`),console.log(`Daemon log file: ${a}`),console.log(`Watcher PID file: ${l}`)})(s,d)}if(process.env.WATIVE_DAEMON_PASSWORDS&&process.env.WATIVE_WORKER_MODE){const e=require("crypto"),t=process.env.WATIVE_DAEMON_PASSWORDS;delete process.env.WATIVE_DAEMON_PASSWORDS,delete process.env.WATIVE_WORKER_MODE;try{const r=t.split(":"),o=Buffer.from(r[0],"hex"),n=Buffer.from(r[1],"hex"),i=r[2],a=e.createDecipheriv("aes-256-cbc",n,o);let c=a.update(i,"hex","utf8");c+=a.final("utf8");const l=JSON.parse(c);console.log(`[${(new Date).toISOString()}] Worker process starting SSH service '${s}'...`);const u=V();await u.startService(s,l);for(const e in l)l[e]=null,delete l[e];console.log(`[${(new Date).toISOString()}] SSH service '${s}' started successfully`);const p=async e=>{console.log(`[${(new Date).toISOString()}] Worker received ${e}, stopping service...`);try{await u.stopService(s),console.log(`[${(new Date).toISOString()}] Service stopped successfully`)}catch(e){console.error(`[${(new Date).toISOString()}] Error stopping service:`,e)}process.exit(0)};process.on("SIGTERM",()=>p("SIGTERM")),process.on("SIGINT",()=>p("SIGINT"));const d=setInterval(async()=>{try{const e=await u.getServiceStatus(s);"running"!==e&&(console.log(`[${(new Date).toISOString()}] Service status changed to: ${e}`),"stopped"===e&&(console.log(`[${(new Date).toISOString()}] Service stopped unexpectedly, exiting worker...`),clearInterval(d),process.exit(1)))}catch(e){console.error(`[${(new Date).toISOString()}] Error checking service status:`,e)}},3e4),h=setInterval(()=>{},6e4),g=()=>{clearInterval(d),clearInterval(h)};process.on("exit",g)}catch(e){console.error(`[${(new Date).toISOString()}] Worker process error:`,e),process.exit(1)}return}{await r.startService(s),console.log(`SSH service '${s}' started successfully`),process.on("SIGINT",async()=>{console.log("\nReceived SIGINT, stopping services..."),await r.stopAllServices(),process.exit(0)}),process.on("SIGTERM",async()=>{console.log("\nReceived SIGTERM, stopping services..."),await r.stopAllServices(),process.exit(0)});const e=setInterval(()=>{"running"!==r.getServiceStatus(s)&&(console.log(`Service ${s} is no longer running, exiting...`),clearInterval(e),process.exit(1))},5e3);process.stdin.resume()}}catch(e){console.error(`Error: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}),Z.command("stop").description("Stop SSH service").option("-c, --config <name>","Specify service configuration name").action(async e=>{const t=V();try{e.config||(console.error("Error: Configuration name is required. Use -c or --config to specify a service configuration."),process.exit(1)),await t.stopService(e.config),console.log(`SSH service '${e.config}' stopped successfully`)}catch(e){console.error(`Error: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}),Z.command("restart").description("Restart SSH service").option("-c, --config <name>","Specify service configuration name").action(async e=>{const t=V();try{e.config||(console.error("Error: Configuration name is required. Use -c or --config to specify a service configuration."),process.exit(1)),await t.restartService(e.config),console.log(`SSH service '${e.config}' restarted successfully`)}catch(e){console.error(`Error: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}),Z.command("create").description("Create new SSH service configuration interactively").action(async()=>{const e=require("readline"),t=require("fs"),r=require("path"),{SSHConfigManager:s}=require("./ssh/config_manager"),o=e.createInterface({input:process.stdin,output:process.stdout}),n=e=>new Promise(t=>{o.question(e,t)});try{console.log("SSH create command started...");const e=r.join(process.env.HOME||"",".wative/ssh"),o=(await n(`SSH storage located in (default: ${e}): `)).trim()||e,i=r.join(process.env.HOME||"",".wative"),a=(await n(`Keystore storage located in (default: ${i}): `)).trim()||i,c=new s(o,a);let l,u,p,d;for(;;)if(l=await n("Enter service name: "),l.trim())try{c.loadServiceConfig(l),console.log("Service name already exists, please enter a different name")}catch(e){break}else console.log("Service name cannot be empty");for(;;){const e=await n("Enter port number: ");if(u=parseInt(e),isNaN(u)||u<1024||u>65535){console.log("Port number must be between 1024-65535");continue}const t=c.listServiceConfigs();let r=!1;for(const e of t)try{if(c.loadServiceConfig(e).ssh.port===u){r=!0;break}}catch(e){}if(!r)break;console.log(`Port ${u} is already in use by another service, please enter a different port`)}for(;;){const e=await n("Enter allowed keystore list (comma separated): ");if(!e.trim()){console.log("Keystore list cannot be empty");continue}if(p=e.split(",").map(e=>e.trim()).filter(e=>e),0===p.length){console.log("At least one valid keystore is required");continue}const s=r.join(a,"accounts");let o=!0;for(const e of p){const n=r.join(s,`${e}.json`);if(!t.existsSync(n)){console.log(`Keystore '${e}' does not exist`),o=!1;break}}if(o){console.log("All keystores verified to exist");break}console.log("Please re-enter valid keystore list")}for(;d=await n("Enter remote client name: "),!d.trim();)console.log("Client name cannot be empty");const h=r.join(o,"conf.d",l);t.existsSync(h)||t.mkdirSync(h,{recursive:!0});const g=r.join(h,`${d}.pub`);for(console.log("\nPlease place the remote client's public key file at the following path:"),console.log(`${g}`),console.log("\nPress Enter to continue after placing the file...");;){if(await n(""),t.existsSync(g)){console.log("Client public key file found");break}console.log("Client public key file not found, please confirm the file is correctly placed and press Enter again")}const f=await n("Enter service description (optional): ");console.log("\nCreating SSH service configuration...");const m=await c.createServiceConfig(l,u,p,d,f||void 0);console.log("\nNote: Passwords will be requested when starting the service."),console.log(`\nSSH service configuration '${l}' created successfully!`),console.log(`Port: ${u}`),console.log(`Allowed keystores: ${p.join(", ")}`),console.log(`Client name: ${d}`),console.log(`Server private key: ${m.server_keys.private_key_path}`),console.log(`Client public key: ${g}`)}catch(e){console.error(`Error: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}finally{o.close()}}),Z.command("remove").description("Remove SSH service configuration").option("-c, --config <name>","Service configuration name").action(async e=>{const t=V();try{e.config||(console.error("Error: Configuration name is required for remove command"),process.exit(1)),await t.removeService(e.config),console.log(`SSH service configuration '${e.config}' removed successfully`)}catch(e){console.error(`Error: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}),Z.command("list").description("List all SSH service configurations").action(async()=>{const e=new I,t=new W,r=e.listServiceConfigs();if(0!==r.length){console.log("SSH Service Configurations:");for(const s of r)try{const r=e.loadServiceConfig(s),o=t.getServiceStatus(s);console.log(` - ${s}: ${r.description||"No description"} (${o})`)}catch(e){const r=t.getServiceStatus(s);console.log(` - ${s}: Configuration error (${r})`)}}else console.log("No SSH service configurations found.")}),Z.command("status").description("Show SSH service status").option("-c, --config <name>","Service configuration name").action(async e=>{const t=V();try{if(e.config){const r=t.getServiceStatus(e.config);console.log(`SSH service '${e.config}' status: ${r}`)}else{const e=t.listServices();if(0===e.length)return void console.log("No SSH service configurations found");console.log("SSH Service Status:"),e.forEach(e=>{const r=t.getServiceStatus(e.name);console.log(` - ${e.name}: ${r}`)})}}catch(e){console.error(`Error: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}),Z.command("log").description("Show SSH service logs").option("-c, --config <name>","Service configuration name").option("-n, --lines <number>","Number of lines to show (default: 50)","50").option("-f, --follow","Follow log output").action(async e=>{const t=V();try{const r=parseInt(e.lines)||50;await t.showLogs(e.config,r,e.follow)}catch(e){console.error(`Error: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}),U.command("cmd").description("Start wallet-cli shell").action(async()=>{try{s("wallet-cli",{stdio:"inherit"})}catch(e){}}),U.parse(process.argv);
|
package/lib/wative.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("path"),require("commander"),require("child_process"),require("fs"),require("ini"),require("figlet"),require("inquirer"),require("web3"),require("@solana/web3.js"),require("@solana/spl-token"),require("@metaplex-foundation/js"),require("bignumber.js")):"function"==typeof define&&define.amd?define(["path","commander","child_process","fs","ini","figlet","inquirer","web3","@solana/web3.js","@solana/spl-token","@metaplex-foundation/js","bignumber.js"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).path,e.commander,e.child_process,e.fs,e.ini)}(this,function(e,t,r,n,i){"use strict";function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,Object.freeze(t)}var s=o(e),c=o(n),a=o(i);function u(e,t,r,n){return new(r||(r=Promise))(function(i,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(s,c)}a((n=n.apply(e,t||[])).next())})}function l(e,t){var r,n,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=c(0),s.throw=c(1),s.return=c(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function c(c){return function(a){return function(c){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,c[0]&&(o=0)),o;)try{if(r=1,n&&(i=2&c[0]?n.return:c[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,c[1])).done)return i;switch(n=0,i&&(c=[2&c[0],i.value]),c[0]){case 0:case 1:i=c;break;case 4:return o.label++,{value:c[1],done:!1};case 5:o.label++,n=c[1],c=[0];continue;case 7:c=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==c[0]&&2!==c[0])){o=0;continue}if(3===c[0]&&(!i||c[1]>i[0]&&c[1]<i[3])){o.label=c[1];break}if(6===c[0]&&o.label<i[1]){o.label=i[1],i=c;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(c);break}i[2]&&o.ops.pop(),o.trys.pop();continue}c=t.call(e,o)}catch(e){c=[6,e],n=0}finally{r=i=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}"function"==typeof SuppressedError&&SuppressedError,require("chalk"),require("chalk"),require("chalk"),process.env.HOME||process.env.USERPROFILE;var d=function(e){return e=(e=(e=(e=e.trim()).toLocaleLowerCase()).replace(/\s+/g,"-").trim()).replace(/\-+/g,"-").trim()};require("bn.js").BN,require("ethereumjs-util").stripHexPrefix,require("bignumber.js").BigNumber,require("chalk"),require("wative-core").WativeCore,require("chalk"),require("dotenv").config(),require("cli-progress"),require("wative-core").WativeCore;var v=function(e){return u(void 0,void 0,void 0,function(){var t,n,i,o,v,f,p;return l(this,function(y){switch(y.label){case 0:return t="/etc/wative",c.existsSync(t)||c.mkdirSync(t),[4,u(void 0,void 0,void 0,function(){var e,t,n,i,o;return l(this,function(a){return e="/etc/wative",t=s.join(e,"id_rsa_server.pub"),n=s.join(e,"id_rsa_server"),c.existsSync(t)&&c.existsSync(n)||(console.log("Generating SSH key pair..."),r.execSync("ssh-keygen -t rsa -f ".concat(n," -N 'wative_server'"),{stdio:"inherit"})),i=s.join(e,"id_rsa_detake.pub"),o=s.join(e,"id_rsa_detake"),c.existsSync(i)&&c.existsSync(o)||(console.log("Generating SSH key pair..."),r.execSync("ssh-keygen -t rsa -f ".concat(o," -N 'wative_detake'"),{stdio:"inherit"})),[2]})})];case 1:return y.sent(),n=s.join(t,"config.ini"),c.existsSync(n)||(h=e,S=s.resolve(h,"network.json"),i=JSON.parse(c.readFileSync(S,"utf8")),o=i.accounts,v=function(e){for(var t=[],r=0;r<e.length;r++)t.push(d(e[r]));return t}(o),f={keystore:{path:e,allowed_keystores:v},ssh:{listen:"127.0.0.1",port:5678,log:{size:10485760,backups:3}}},p=a.stringify(f),c.writeFileSync(n,p)),[2,a.parse(c.readFileSync(n,"utf-8"))]}var h,S})})},f=require("os"),p=new t.Command,y=require("../package.json"),h=function(){try{return r.execSync("systemctl --version",{stdio:"ignore"}),!0}catch(e){return!1}};p.version(y.version).description("Wative CLI Tool"),p.command("version").description("Show the version of wative").action(function(){console.log("Wative CLI Tool v".concat(y.version))});p.command("ssh").option("start","Start SSH service").option("stop","Stop SSH service").option("service add","Add SSH service").option("service remove","Remove SSH service").action(function(e,t){return u(void 0,void 0,void 0,function(){return l(this,function(n){switch(n.label){case 0:return"start"!==e?[3,2]:[4,u(void 0,void 0,void 0,function(){var e,t,n;return l(this,function(i){switch(i.label){case 0:return h()?(e="/var/log/wative",c.existsSync(e)||c.mkdirSync(e),t=f.homedir(),n=s.join(t,".wative"),[4,v(n)]):(console.log("Systemd is not available."),[2]);case 1:i.sent(),console.log("Starting SSH service...");try{r.execSync("wative-ssh --daemon",{stdio:"inherit"})}catch(e){}return console.log("SSH service started."),[2]}})})];case 1:return n.sent(),[2];case 2:return"stop"===e?(function(){if(h()){try{r.execSync("ps aux | grep wative-ssh | grep -v grep | awk '{print $2}' | sudo xargs kill",{stdio:"inherit"})}catch(e){}console.log("SSH service stopped.")}else console.log("Systemd is not available.")}(),[2]):"service"===e&&"add"===t?(u(void 0,void 0,void 0,function(){var e,t,n;return l(this,function(i){switch(i.label){case 0:return h()?(e="/var/log/wative",c.existsSync(e)||c.mkdirSync(e),t=f.homedir(),n=s.join(t,".wative"),[4,v(n)]):(console.log("Systemd is not available."),[2]);case 1:i.sent(),console.log("Adding SSH service...");try{r.execSync("sudo echo '".concat("\n[Unit]\nDescription=Wative SSH Server\nAfter=network.target\n\n[Service]\nExecStart=/usr/local/bin/wative-ssh\nUser=root\nGroup=root\nStandardOutput=append:/var/log/wative/wative.log\nStandardError=append:/var/log/wative/wative.err\n\n[Install]\nWantedBy=multi-user.target\n ","' > ").concat("/etc/systemd/system/wative.service"),{stdio:"inherit"}),r.execSync("sudo systemctl daemon-reload",{stdio:"inherit"}),r.execSync("sudo systemctl enable wative",{stdio:"inherit"}),r.execSync("sudo systemctl start wative",{stdio:"inherit"})}catch(e){}return console.log("SSH service added."),[2]}})}),[2]):"service"===e&&"remove"===t?(function(){if(h()){console.log("Removing SSH service...");try{r.execSync("sudo systemctl stop wative",{stdio:"inherit"})}catch(e){}try{r.execSync("sudo systemctl disable wative",{stdio:"inherit"})}catch(e){}try{r.execSync("sudo rm -rf /etc/systemd/system/wative.service",{stdio:"inherit"})}catch(e){}try{r.execSync("sudo systemctl daemon-reload",{stdio:"inherit"})}catch(e){}console.log("SSH service removed.")}else console.log("Systemd is not available.")}(),[2]):[2]}})})}),p.command("cmd").description("Start wallet-cli shell").action(function(){return u(void 0,void 0,void 0,function(){return l(this,function(e){try{r.execSync("wallet-cli",{stdio:"inherit"})}catch(e){}return[2]})})}),p.parse(process.argv)});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("path"),require("commander"),require("child_process"),require("fs"),require("ini"),require("crypto"),require("ssh2"),require("figlet"),require("inquirer"),require("web3"),require("@solana/web3.js"),require("@solana/spl-token"),require("@metaplex-foundation/js"),require("bignumber.js"),require("log4js"),require("ethers"),require("tweetnacl"),require("bs58"),require("bip39"),require("@coral-xyz/anchor"),require("crypto-js"),require("ethereumjs-wallet"),require("micro-ed25519-hdkey"),require("net")):"function"==typeof define&&define.amd?define(["path","commander","child_process","fs","ini","crypto","ssh2","figlet","inquirer","web3","@solana/web3.js","@solana/spl-token","@metaplex-foundation/js","bignumber.js","log4js","ethers","tweetnacl","bs58","bip39","@coral-xyz/anchor","crypto-js","ethereumjs-wallet","micro-ed25519-hdkey","net"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).path,e.commander,e.child_process,e.fs,e.ini,e.crypto,e.ssh2,null,e.inquirer,e.Web3,e.require$$6,null,null,null,e.log4js,e.ethers,e.require$$3,e.require$$4,e.require$$5,e.require$$7,e.require$$8,e.require$$9,e.require$$10,e.net)}(this,function(e,t,r,s,o,n,i,a,c,l,u,p,d,h,g,f,m,y,v,w,b,S,k,x){"use strict";function _(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function P(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,s.get?s:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,Object.freeze(t)}var j=P(e),$=_(e),E=P(s),I=_(s),A=P(o),C=P(n),q=_(c),T=_(l),O=_(u),K=P(g),M=_(m),D=_(y),L=_(v),H=_(w),z=_(b),N=_(S),R=_(k),F=P(x);class B{constructor(e,t){this.configDir=e||j.join(require("os").homedir(),".wative/ssh"),this.keystorePath=t||j.join(require("os").homedir(),".wative"),E.existsSync(this.configDir)||E.mkdirSync(this.configDir,{recursive:!0});const r=j.join(this.configDir,"conf.d");E.existsSync(r)||E.mkdirSync(r,{recursive:!0})}getKeystorePath(){return this.keystorePath}getConfigDir(){return this.configDir}async createServiceConfig(e,t,r,s="default_client",o){if(!this.isValidServiceName(e))throw new Error("Invalid service name. Use only alphanumeric characters, hyphens, and underscores.");if(this.isPortInUse(t))throw new Error(`Port ${t} is already in use by another service.`);const n=await this.generateServiceKeyPair(e),i=await this.generateClientKeyPair(e,s),a={name:e,description:o||`Wative SSH Service - ${e}`,ssh:{listen:"127.0.0.1",port:t,log:{size:10485760,backups:3}},keystore:{path:this.keystorePath,allowed_keystores:r},clients:[{name:s,public_key_path:i.publicKey,allowed_keystores:r}],server_keys:{private_key_path:n.privateKey,passphrase:n.passphrase}};return this.saveServiceConfig(e,a),a}loadServiceConfig(e){const t=this.getServiceConfigPath(e);if(!E.existsSync(t))throw new Error(`Service configuration '${e}' not found.`);const r=A.parse(E.readFileSync(t,"utf-8"));return this.parseConfigData(r)}listServiceConfigs(){const e=j.join(this.configDir,"conf.d");if(!E.existsSync(e))return[];return E.readdirSync(e).filter(t=>{const r=j.join(e,t);return E.statSync(r).isDirectory()&&E.existsSync(j.join(r,"config.ini"))})}removeServiceConfig(e){const t=this.getServiceConfigPath(e);E.existsSync(t)&&E.unlinkSync(t),this.removeServiceKeys(e)}updateServiceConfig(e,t){const r={...this.loadServiceConfig(e),...t};this.saveServiceConfig(e,r)}async validateKeystorePasswords(e,t){const r={},{WativeCore:s}=require("wative-core");for(const o of e)try{const e=t[o];if(!e){r[o]=!1;continue}const n=new s(this.keystorePath,[o],[e]);r[o]=n.account.isLogin(o)}catch(e){r[o]=!1}return r}isValidServiceName(e){return/^[a-zA-Z0-9_-]+$/.test(e)&&e.length>0&&e.length<=50}isPortInUse(e){const t=this.listServiceConfigs();for(const r of t)try{if(this.loadServiceConfig(r).ssh.port===e)return!0}catch(e){}return!1}async generateServiceKeyPair(e){const t=this.generateSecurePassphrase(),s=j.join(this.configDir,"conf.d",e);E.existsSync(s)||E.mkdirSync(s,{recursive:!0});const o=j.join(s,"server_private_key"),n=j.join(s,"server_public_key.pub");return E.existsSync(o)||(console.log(`Generating SSH server key pair for service '${e}'...`),r.execSync(`ssh-keygen -t rsa -b 4096 -f ${o} -N '${t}' -C 'wative_${e}_server'`,{stdio:"inherit"})),{privateKey:o,publicKey:n,passphrase:t}}async generateClientKeyPair(e,t){const r=j.join(this.configDir,"conf.d",e);E.existsSync(r)||E.mkdirSync(r,{recursive:!0});return{privateKey:"",publicKey:j.join(r,`${t}.pub`),passphrase:""}}generateSecurePassphrase(){return C.randomBytes(32).toString("hex")}getServiceConfigPath(e){return j.join(this.configDir,"conf.d",e,"config.ini")}saveServiceConfig(e,t){const r=this.getServiceConfigPath(e),s=j.dirname(r);E.existsSync(s)||E.mkdirSync(s,{recursive:!0});const o=A.stringify(t);E.writeFileSync(r,o)}parseConfigData(e){return{name:e.name,description:e.description,ssh:{listen:e.ssh.listen,port:parseInt(e.ssh.port),log:{size:parseInt(e.ssh.log.size),backups:parseInt(e.ssh.log.backups)}},keystore:{path:e.keystore.path,allowed_keystores:Array.isArray(e.keystore.allowed_keystores)?e.keystore.allowed_keystores:e.keystore.allowed_keystores.split(",")},clients:Array.isArray(e.clients)?e.clients:[e.clients],server_keys:{private_key_path:e.server_keys.private_key_path,passphrase:e.server_keys.passphrase}}}removeServiceKeys(e){const t=[`id_rsa_${e}_server`,`id_rsa_${e}_server.pub`,`id_rsa_${e}_*`];for(const e of t){const t=j.join(this.configDir,e);E.existsSync(t)&&E.unlinkSync(t)}}}require("chalk"),require("chalk"),require("chalk"),process.env.HOME||process.env.USERPROFILE;const W=async e=>{const t=[{name:"password",type:"password",mask:"#",message:`${e}:`}];let{password:r}=await q.default.prompt(t);return r};require("bn.js"),require("ethereumjs-util"),require("bignumber.js"),require("chalk"),require("wative-core"),require("chalk"),require("dotenv").config(),require("cli-progress"),require("wative-core");const{WativeCore:U}=require("wative-core"),{Connection:G,PublicKey:J,VersionedTransaction:V,VersionedMessage:Z}=require("@solana/web3.js"),Q=require("bs58"),{Keypair:Y,TransactionMessage:X,ComputeBudgetInstruction:ee,TransactionInstruction:te,ComputeBudgetProgram:re}=require("@solana/web3.js"),{Wallet:se}=require("@coral-xyz/anchor");K.configure({appenders:{file:{type:"file",filename:process.env.HOME+"/.wative/logs/wative.log",maxLogSize:10485760,backups:3,compress:!0,keepFileExt:!0,layout:{type:"pattern",pattern:"%d{yyyy-MM-dd hh:mm:ss.SSS} [%p] %c - %m"},encoding:"utf-8"},console:{type:"console"}},categories:{default:{appenders:["file","console"],level:"info"}}});const oe=K.getLogger("file");oe.level="info";class ne{constructor(e,t,r,o,n,a,c,l){if(this._allowedAppIds=[],this._allowedPubKeys=[],this._allowedKeystoreIds=[],this._sessionIdAppIdMap={},(e=>{if(e=e.trim(),!E.existsSync(e))throw new Error("File not exists")})(e),0===r.length||0===o.length||0===n.length||r.length!==o.length||r.length!==n.length)throw new Error("WativeWielderServer:: constructor: Invaild AllowedApp");for(let e=0;e<n.length;e++)for(let t=0;t<n[e].length;t++){const r=n[e][t];if(!c.includes(r))throw new Error("WativeWielderServer:: constructor: Invaild AllowedKeystoreIds")}for(let e of r)this._allowedAppIds.push(Buffer.from(e));for(let e of o){let t=i.utils.parseKey(s.readFileSync(e));this._allowedPubKeys.push(t)}this.wativeCore=new U(a,c,l),this._idRsaPrivatePath=e,this._idRsaPassphrase=t,this._allowedKeystoreIds=n,this._keystoreDirectoryPath=a}listen(e,t){new i.Server({hostKeys:[{key:s.readFileSync(this._idRsaPrivatePath),passphrase:this._idRsaPassphrase}]},e=>{e.on("authentication",t=>{let r=!0;if(this&&(this.checkValue(Buffer.from(t.username),"appId")||(r=!1)),"publickey"!==t.method||!r)return t.reject();{let e=this.getBytesIndex(Buffer.from(t.username),this._allowedAppIds),r=this._allowedPubKeys[e];if(t.key.algo!==r.type||!this.checkValue(t.key.data,"publicKey")||t.signature&&!0!==r.verify(t.blob,t.signature,t.hashAlgo))return t.reject()}if(r){const r=e._protocol._kex.sessionID.toString("hex");this._sessionIdAppIdMap[r]=Buffer.from(t.username),t.accept()}else t.reject()}).on("ready",()=>{e.on("session",(t,r)=>{t().once("exec",async(t,r,s)=>{const o=e._protocol._kex.sessionID.toString("hex"),n=await this.web3Request(o,s.command),i=t();i&&(JSON.stringify(n)?(i.write(JSON.stringify(n)),i.exit(0),i.end()):(i.write("ssh2 connect error"),i.exit(0),i.end()))})})}).on("close",()=>{oe.info("Client disconnected")}).on("error",e=>{oe.error("err: ",e.message)})}).listen(t,e,function(){oe.info("Listening on port "+t)})}async web3Request(e,t){try{const r=this._sessionIdAppIdMap[e],s=this.getBytesIndex(r,this._allowedAppIds);if(s<0)return{status:!1,msg:"app not found"};let o=JSON.parse(t);oe.info("sign message: ",t);let n=o.method,i=o.keystoreId||o.params.keystoreId,a=o.chainId||o.params.chainId;if(!this._allowedKeystoreIds[s].includes(i))return{status:!1,msg:"keystore not allowed"};let c;if("get_root_account"===n)c=this.getRootAccount(i,a);else if("get_sub_account"===n){let e=o.params;c=this.getSubAccount(i,e.chainId,null==e?void 0:e.startIndex,null==e?void 0:e.endIndex)}else if("sign"===n){let e=o.params;try{c=await this.wativeCore.account.signTransaction(e.txParams.from,e.txParams,e.rpcUrl)}catch(e){return oe.error("sign error: ",e.message),{status:!1,msg:e.msg}}}else if("sign_and_send"===n){let e=o.params;try{c={transactionHash:await this.wativeCore.account.signAndSendTx(e.txParams,e.rpcUrl)}}catch(e){return{status:!1,msg:e.msg}}}else if("solana_sign"===n)try{let e=o.params;c=await this.signSolanaTransaction(e.txParams.from,e.txParams.data,e.txParams.lookup_tables,e.rpcUrl,e.priority_fee)}catch(e){return oe.error("sign error: ",e.message),{status:!1,msg:e.msg}}else if("solana_send"===n)try{let e=o.params;c=await this.sendSignedSolanaTransaction(e.txParams.from,e.txParams.signature,e.txParams.data,e.rpcUrl)}catch(e){return oe.error("sign error: ",e.message),{status:!1,msg:e.msg}}else if("sign_message"===n)try{let e=o.params;oe.debug("sign message: ",e),c=await this.signMessage(e.account,e.message)}catch(e){return oe.error("sign error: ",e.message),{status:!1,msg:e.msg}}else{if("sign_typed_data"!==n)return{status:!1,msg:"message method not find"};try{let e=o.params;oe.debug("sign message: ",e),c=await this.signTypedData(e.account,e.domain,e.types_name,e.types,e.message)}catch(e){return oe.error("sign error: ",e.message),{status:!1,msg:e.msg}}}return{status:!0,data:c}}catch(e){return oe.error("sign error: ",e.message),{status:!1,msg:e.msg}}}checkValue(e,t){if("appId"!==t&&"publicKey"!==t)return!1;let r=this._allowedAppIds.length;for(let s=0;s<r;s++){let r;r="appId"===t?this._allowedAppIds[s]:this._allowedPubKeys[s].getPublicSSH();const o=e.length!==r.length;o&&(r=e);const i=n.timingSafeEqual(e,r);if(!o&&i)return!0}}getBytesIndex(e,t){let r=t.length;for(let s=0;s<r;s++)if(e.length===t[s].length&&n.timingSafeEqual(e,t[s]))return s;return-1}getRootAccount(e,t){const r=j.resolve(this._keystoreDirectoryPath,`accounts/${e}.json`);let o,n=s.readFileSync(r);return n=JSON.parse(n.toString()),o="SOLANA"===this.getChainType(t)?n.data[0].ciphertexts.solana.address:n.data[0].ciphertexts.evm.address,[{id:0,address:o,children:n.data.length,type:"M"}]}getChainType(e){return"901"===e||"902"===e||"903"===e?"SOLANA":"EVM"}getSubAccount(e,t,r,o){const n=j.resolve(this._keystoreDirectoryPath,`accounts/${e}.json`);let i=s.readFileSync(n);i=JSON.parse(i.toString());let a=i.data.length-1;o&&o<a&&(a=o);let c=0;if(r&&r>0&&(c=r),c>a)return[];let l=this.getChainType(t),u=[];for(let e=c;e<=a;e++)u.push(i.data[e].ciphertexts[l.toLocaleLowerCase()].address);return u}async signMessage(e,t){let r=await this.wativeCore.account.signMessage(e,t);return console.log(r),r}async signTypedData(e,t,r,s,o){let n=JSON.parse(t),i=JSON.parse(s),a=JSON.parse(o);console.log(n),console.log(i),console.log(a);let c=this.wativeCore.account.showPrivateKey(e),l=new f.ethers.Wallet(c),u=await l.signTypedData(n,{[r]:i},a);return console.log(u),{status:!0,output:u}}async signSolanaTransaction(e,t,r,s,o){let n=new G(s),i=[];if(r)for(let e of r){let t=(await n.getAddressLookupTable(new J(e))).value;i.push(t),await ie(1e3)}let a=Z.deserialize(Uint8Array.from(Buffer.from(t,"hex"))),c=X.decompile(a);c.instructions.push(re.setComputeUnitLimit({units:2e6})),c.instructions.push(re.setComputeUnitPrice({microLamports:1e3})),a=c.compileToV0Message(i),a.recentBlockhash=(await n.getLatestBlockhash()).blockhash,await ie(3e3);let l=new V(a),u=this.wativeCore.account.showPrivateKey(e);const p=Y.fromSecretKey(new Uint8Array(Q.decode(u))),d=new se(p);let h=await n.simulateTransaction(l);if(!h||!h.value||0===h.value.unitsConsumed||h.value.err)return{status:!1,output:h.value.err};let g=c.instructions.length,f=Math.trunc(1.2*h.value.unitsConsumed);if(c.instructions[g-2]=re.setComputeUnitLimit({units:f}),!o||"null"==o)try{o=await this.getPrioritizationFee(s)}catch(e){o=2e5}o<1e4&&(o=1e4),o>5e5&&(o=5e5),c.instructions[g-1]=re.setComputeUnitPrice({microLamports:o}),a=c.compileToV0Message(i),await ie(1e3),a.recentBlockhash=(await n.getLatestBlockhash()).blockhash,l=new V(a),l.feePayer=d.publicKey,await ie(3e3);let m=await this.wativeCore.account.signTransaction(e,l,s),y=new V(m.output.message,m.output.signatures).message.serialize();return y=Buffer.from(y).toString("hex"),{status:!0,output:{transactionHash:Q.encode(m.output.signatures[0]),message:y,compute_units:h.value.unitsConsumed.toString()}}}async sendSignedSolanaTransaction(e,t,r,s){let o=[Q.decode(t)],n=Z.deserialize(Uint8Array.from(Buffer.from(r,"hex"))),i=new V(n,o);return await this.wativeCore.account.sendSignedTransaction(e,i,s)}async getPrioritizationFee(e){let t=new J("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4");const r=new G(e,"confirmed");let s=await r.getSignaturesForAddress(t,{limit:5});await ie(2e3);let o=[];for(let e=0;e<s.length;e++)o.push(s[e].signature);let n=await r.getParsedTransactions(o,{maxSupportedTransactionVersion:0}),i=0;for(let e=0;e<n.length;e++){let t=n[e].transaction.message.instructions;for(let e=0;e<t.length;e++)if("ComputeBudget111111111111111111111111111111"===t[e].programId.toBase58()){let r=t[e].data;try{let e=new te({keys:[],programId:new J("ComputeBudget111111111111111111111111111111"),data:Buffer.from(Q.decode(r))}),{microLamports:t}=ee.decodeSetComputeUnitPrice(e);i+=Number(t);continue}catch(e){}}}return Math.ceil(i/5)}}const ie=e=>new Promise(t=>setTimeout(t,e));"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var ae={exports:{}},ce={name:"wative-core",version:"1.0.21",description:"An agile keystore management toolkit",main:"lib/index.umd.js",module:"lib/index.esm.js",types:"lib/index.d.ts",scripts:{test:"jest",compile:"tsc",build:"rollup --config"},repository:{type:"git",url:""},bugs:{url:"https://github.com"},homepage:"https://github.com",keywords:["keystore","wallet"],author:"",license:"ISC",files:["src/","lib/"],dependencies:{"@babel/plugin-transform-modules-commonjs":"7.24.1","@rollup/plugin-commonjs":"21.0.1","@solana/web3.js":"1.91.8","@types/bs58":"4.0.4","crypto-js":"4.2.0","ethereumjs-wallet":"1.0.2",jest:"27.5.1","micro-ed25519-hdkey":"0.1.2",rollup:"2.79.1","rollup-plugin-terser":"7.0.2","rollup-plugin-typescript2":"0.31.2",tslib:"2.6.2",typescript:"4.9.5",web3:"1.7.3","web3-core":"4.3.2","@coral-xyz/anchor":"0.30.1","@types/crypto-js":"4.2.2","nodejs-threadpool":"1.0.1",tweetnacl:"1.0.3","rpc-websockets":"7.10.0"}};!function(e,t){!function(e,t,r,s,o,n,i,a,c,l,u,p){function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function h(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,s.get?s:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,Object.freeze(t)}var g=h(t),f=h(r),m=d(s),y=h(o),v=h(n),w=h(i),b=h(l),S=function(){return S=Object.assign||function(e){for(var t,r=1,s=arguments.length;r<s;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},S.apply(this,arguments)};function k(e,t,r,s){return new(r||(r=Promise))(function(o,n){function i(e){try{c(s.next(e))}catch(e){n(e)}}function a(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(i,a)}c((s=s.apply(e,t||[])).next())})}function x(e,t){var r,s,o,n={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(n=0)),n;)try{if(r=1,s&&(o=2&a[0]?s.return:a[0]?s.throw||((o=s.return)&&o.call(s),0):s.next)&&!(o=o.call(s,a[1])).done)return o;switch(s=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return n.label++,{value:a[1],done:!1};case 5:n.label++,s=a[1],a=[0];continue;case 7:a=n.ops.pop(),n.trys.pop();continue;default:if(!((o=(o=n.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){n=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){n.label=a[1];break}if(6===a[0]&&n.label<o[1]){n.label=o[1],o=a;break}if(o&&n.label<o[2]){n.label=o[2],n.ops.push(a);break}o[2]&&n.ops.pop(),n.trys.pop();continue}a=t.call(e,n)}catch(e){a=[6,e],s=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}"function"==typeof SuppressedError&&SuppressedError;var _=function(e,t){return k(void 0,void 0,void 0,function(){var r,s,o;return x(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,e.apply(void 0,t)];case 1:return s=n.sent(),r={status:!0,output:s},[3,3];case 2:return o=n.sent(),r={status:!1,output:o.toString()},[3,3];case 3:return[2,r]}})})},P=function(){function e(e){this.web3=new m.default(e)}return e.prototype.getEvmGasPrice=function(){return k(this,void 0,void 0,function(){return x(this,function(e){switch(e.label){case 0:return[4,_(this.web3.eth.getGasPrice,[])];case 1:return[2,e.sent()]}})})},e.prototype.getEvmGasLimit=function(e,t){return k(this,void 0,void 0,function(){return x(this,function(r){switch(r.label){case 0:return[4,_(this.web3.eth.estimateGas,[e,t])];case 1:return[2,r.sent()]}})})},e}(),j=function(e){return e=e.trim(),g.existsSync(e)},$=function(e,t){var r=t.length;if(0===r)return!0;for(var s=0;s<r;s++){var o=f.join(e,"accounts/".concat(t[s],".json"));if(!j(o))return!1}return!0},E=function(e){return(e=(e=(e=e.trim()).toLocaleLowerCase()).replace(/\s+/g,"-").trim()).replace(/\-+/g,"-").trim()},I=function(e,t){var r=[],s=f.join(e,"network.json");if(!j(s))throw new Error("network.json not found");for(var o=function(e){for(var t=[],r=0;r<e.length;r++)t.push(E(e[r]));return t}(A(s).accounts),n=0;n<t.length;n++)o.includes(t[n])&&r.push(t[n]);return r},A=function(e){var t=g.readFileSync(e).toString();return JSON.parse(t)},C=function(e,t){var r=JSON.stringify(e);g.writeFileSync(t,r)},q=function(e,t){return b.AES.encrypt(e,t).toString()},T=function(e,t){return b.AES.decrypt(e,t).toString(b.enc.Utf8)},O=["abandon","ability","able","about","above","absent","absorb","abstract","absurd","abuse","access","accident","account","accuse","achieve","acid","acoustic","acquire","across","act","action","actor","actress","actual","adapt","add","addict","address","adjust","admit","adult","advance","advice","aerobic","affair","afford","afraid","again","age","agent","agree","ahead","aim","air","airport","aisle","alarm","album","alcohol","alert","alien","all","alley","allow","almost","alone","alpha","already","also","alter","always","amateur","amazing","among","amount","amused","analyst","anchor","ancient","anger","angle","angry","animal","ankle","announce","annual","another","answer","antenna","antique","anxiety","any","apart","apology","appear","apple","approve","april","arch","arctic","area","arena","argue","arm","armed","armor","army","around","arrange","arrest","arrive","arrow","art","artefact","artist","artwork","ask","aspect","assault","asset","assist","assume","asthma","athlete","atom","attack","attend","attitude","attract","auction","audit","august","aunt","author","auto","autumn","average","avocado","avoid","awake","aware","away","awesome","awful","awkward","axis","baby","bachelor","bacon","badge","bag","balance","balcony","ball","bamboo","banana","banner","bar","barely","bargain","barrel","base","basic","basket","battle","beach","bean","beauty","because","become","beef","before","begin","behave","behind","believe","below","belt","bench","benefit","best","betray","better","between","beyond","bicycle","bid","bike","bind","biology","bird","birth","bitter","black","blade","blame","blanket","blast","bleak","bless","blind","blood","blossom","blouse","blue","blur","blush","board","boat","body","boil","bomb","bone","bonus","book","boost","border","boring","borrow","boss","bottom","bounce","box","boy","bracket","brain","brand","brass","brave","bread","breeze","brick","bridge","brief","bright","bring","brisk","broccoli","broken","bronze","broom","brother","brown","brush","bubble","buddy","budget","buffalo","build","bulb","bulk","bullet","bundle","bunker","burden","burger","burst","bus","business","busy","butter","buyer","buzz","cabbage","cabin","cable","cactus","cage","cake","call","calm","camera","camp","can","canal","cancel","candy","cannon","canoe","canvas","canyon","capable","capital","captain","car","carbon","card","cargo","carpet","carry","cart","case","cash","casino","castle","casual","cat","catalog","catch","category","cattle","caught","cause","caution","cave","ceiling","celery","cement","census","century","cereal","certain","chair","chalk","champion","change","chaos","chapter","charge","chase","chat","cheap","check","cheese","chef","cherry","chest","chicken","chief","child","chimney","choice","choose","chronic","chuckle","chunk","churn","cigar","cinnamon","circle","citizen","city","civil","claim","clap","clarify","claw","clay","clean","clerk","clever","click","client","cliff","climb","clinic","clip","clock","clog","close","cloth","cloud","clown","club","clump","cluster","clutch","coach","coast","coconut","code","coffee","coil","coin","collect","color","column","combine","come","comfort","comic","common","company","concert","conduct","confirm","congress","connect","consider","control","convince","cook","cool","copper","copy","coral","core","corn","correct","cost","cotton","couch","country","couple","course","cousin","cover","coyote","crack","cradle","craft","cram","crane","crash","crater","crawl","crazy","cream","credit","creek","crew","cricket","crime","crisp","critic","crop","cross","crouch","crowd","crucial","cruel","cruise","crumble","crunch","crush","cry","crystal","cube","culture","cup","cupboard","curious","current","curtain","curve","cushion","custom","cute","cycle","dad","damage","damp","dance","danger","daring","dash","daughter","dawn","day","deal","debate","debris","decade","december","decide","decline","decorate","decrease","deer","defense","define","defy","degree","delay","deliver","demand","demise","denial","dentist","deny","depart","depend","deposit","depth","deputy","derive","describe","desert","design","desk","despair","destroy","detail","detect","develop","device","devote","diagram","dial","diamond","diary","dice","diesel","diet","differ","digital","dignity","dilemma","dinner","dinosaur","direct","dirt","disagree","discover","disease","dish","dismiss","disorder","display","distance","divert","divide","divorce","dizzy","doctor","document","dog","doll","dolphin","domain","donate","donkey","donor","door","dose","double","dove","draft","dragon","drama","drastic","draw","dream","dress","drift","drill","drink","drip","drive","drop","drum","dry","duck","dumb","dune","during","dust","dutch","duty","dwarf","dynamic","eager","eagle","early","earn","earth","easily","east","easy","echo","ecology","economy","edge","edit","educate","effort","egg","eight","either","elbow","elder","electric","elegant","element","elephant","elevator","elite","else","embark","embody","embrace","emerge","emotion","employ","empower","empty","enable","enact","end","endless","endorse","enemy","energy","enforce","engage","engine","enhance","enjoy","enlist","enough","enrich","enroll","ensure","enter","entire","entry","envelope","episode","equal","equip","era","erase","erode","erosion","error","erupt","escape","essay","essence","estate","eternal","ethics","evidence","evil","evoke","evolve","exact","example","excess","exchange","excite","exclude","excuse","execute","exercise","exhaust","exhibit","exile","exist","exit","exotic","expand","expect","expire","explain","expose","express","extend","extra","eye","eyebrow","fabric","face","faculty","fade","faint","faith","fall","false","fame","family","famous","fan","fancy","fantasy","farm","fashion","fat","fatal","father","fatigue","fault","favorite","feature","february","federal","fee","feed","feel","female","fence","festival","fetch","fever","few","fiber","fiction","field","figure","file","film","filter","final","find","fine","finger","finish","fire","firm","first","fiscal","fish","fit","fitness","fix","flag","flame","flash","flat","flavor","flee","flight","flip","float","flock","floor","flower","fluid","flush","fly","foam","focus","fog","foil","fold","follow","food","foot","force","forest","forget","fork","fortune","forum","forward","fossil","foster","found","fox","fragile","frame","frequent","fresh","friend","fringe","frog","front","frost","frown","frozen","fruit","fuel","fun","funny","furnace","fury","future","gadget","gain","galaxy","gallery","game","gap","garage","garbage","garden","garlic","garment","gas","gasp","gate","gather","gauge","gaze","general","genius","genre","gentle","genuine","gesture","ghost","giant","gift","giggle","ginger","giraffe","girl","give","glad","glance","glare","glass","glide","glimpse","globe","gloom","glory","glove","glow","glue","goat","goddess","gold","good","goose","gorilla","gospel","gossip","govern","gown","grab","grace","grain","grant","grape","grass","gravity","great","green","grid","grief","grit","grocery","group","grow","grunt","guard","guess","guide","guilt","guitar","gun","gym","habit","hair","half","hammer","hamster","hand","happy","harbor","hard","harsh","harvest","hat","have","hawk","hazard","head","health","heart","heavy","hedgehog","height","hello","helmet","help","hen","hero","hidden","high","hill","hint","hip","hire","history","hobby","hockey","hold","hole","holiday","hollow","home","honey","hood","hope","horn","horror","horse","hospital","host","hotel","hour","hover","hub","huge","human","humble","humor","hundred","hungry","hunt","hurdle","hurry","hurt","husband","hybrid","ice","icon","idea","identify","idle","ignore","ill","illegal","illness","image","imitate","immense","immune","impact","impose","improve","impulse","inch","include","income","increase","index","indicate","indoor","industry","infant","inflict","inform","inhale","inherit","initial","inject","injury","inmate","inner","innocent","input","inquiry","insane","insect","inside","inspire","install","intact","interest","into","invest","invite","involve","iron","island","isolate","issue","item","ivory","jacket","jaguar","jar","jazz","jealous","jeans","jelly","jewel","job","join","joke","journey","joy","judge","juice","jump","jungle","junior","junk","just","kangaroo","keen","keep","ketchup","key","kick","kid","kidney","kind","kingdom","kiss","kit","kitchen","kite","kitten","kiwi","knee","knife","knock","know","lab","label","labor","ladder","lady","lake","lamp","language","laptop","large","later","latin","laugh","laundry","lava","law","lawn","lawsuit","layer","lazy","leader","leaf","learn","leave","lecture","left","leg","legal","legend","leisure","lemon","lend","length","lens","leopard","lesson","letter","level","liar","liberty","library","license","life","lift","light","like","limb","limit","link","lion","liquid","list","little","live","lizard","load","loan","lobster","local","lock","logic","lonely","long","loop","lottery","loud","lounge","love","loyal","lucky","luggage","lumber","lunar","lunch","luxury","lyrics","machine","mad","magic","magnet","maid","mail","main","major","make","mammal","man","manage","mandate","mango","mansion","manual","maple","marble","march","margin","marine","market","marriage","mask","mass","master","match","material","math","matrix","matter","maximum","maze","meadow","mean","measure","meat","mechanic","medal","media","melody","melt","member","memory","mention","menu","mercy","merge","merit","merry","mesh","message","metal","method","middle","midnight","milk","million","mimic","mind","minimum","minor","minute","miracle","mirror","misery","miss","mistake","mix","mixed","mixture","mobile","model","modify","mom","moment","monitor","monkey","monster","month","moon","moral","more","morning","mosquito","mother","motion","motor","mountain","mouse","move","movie","much","muffin","mule","multiply","muscle","museum","mushroom","music","must","mutual","myself","mystery","myth","naive","name","napkin","narrow","nasty","nation","nature","near","neck","need","negative","neglect","neither","nephew","nerve","nest","net","network","neutral","never","news","next","nice","night","noble","noise","nominee","noodle","normal","north","nose","notable","note","nothing","notice","novel","now","nuclear","number","nurse","nut","oak","obey","object","oblige","obscure","observe","obtain","obvious","occur","ocean","october","odor","off","offer","office","often","oil","okay","old","olive","olympic","omit","once","one","onion","online","only","open","opera","opinion","oppose","option","orange","orbit","orchard","order","ordinary","organ","orient","original","orphan","ostrich","other","outdoor","outer","output","outside","oval","oven","over","own","owner","oxygen","oyster","ozone","pact","paddle","page","pair","palace","palm","panda","panel","panic","panther","paper","parade","parent","park","parrot","party","pass","patch","path","patient","patrol","pattern","pause","pave","payment","peace","peanut","pear","peasant","pelican","pen","penalty","pencil","people","pepper","perfect","permit","person","pet","phone","photo","phrase","physical","piano","picnic","picture","piece","pig","pigeon","pill","pilot","pink","pioneer","pipe","pistol","pitch","pizza","place","planet","plastic","plate","play","please","pledge","pluck","plug","plunge","poem","poet","point","polar","pole","police","pond","pony","pool","popular","portion","position","possible","post","potato","pottery","poverty","powder","power","practice","praise","predict","prefer","prepare","present","pretty","prevent","price","pride","primary","print","priority","prison","private","prize","problem","process","produce","profit","program","project","promote","proof","property","prosper","protect","proud","provide","public","pudding","pull","pulp","pulse","pumpkin","punch","pupil","puppy","purchase","purity","purpose","purse","push","put","puzzle","pyramid","quality","quantum","quarter","question","quick","quit","quiz","quote","rabbit","raccoon","race","rack","radar","radio","rail","rain","raise","rally","ramp","ranch","random","range","rapid","rare","rate","rather","raven","raw","razor","ready","real","reason","rebel","rebuild","recall","receive","recipe","record","recycle","reduce","reflect","reform","refuse","region","regret","regular","reject","relax","release","relief","rely","remain","remember","remind","remove","render","renew","rent","reopen","repair","repeat","replace","report","require","rescue","resemble","resist","resource","response","result","retire","retreat","return","reunion","reveal","review","reward","rhythm","rib","ribbon","rice","rich","ride","ridge","rifle","right","rigid","ring","riot","ripple","risk","ritual","rival","river","road","roast","robot","robust","rocket","romance","roof","rookie","room","rose","rotate","rough","round","route","royal","rubber","rude","rug","rule","run","runway","rural","sad","saddle","sadness","safe","sail","salad","salmon","salon","salt","salute","same","sample","sand","satisfy","satoshi","sauce","sausage","save","say","scale","scan","scare","scatter","scene","scheme","school","science","scissors","scorpion","scout","scrap","screen","script","scrub","sea","search","season","seat","second","secret","section","security","seed","seek","segment","select","sell","seminar","senior","sense","sentence","series","service","session","settle","setup","seven","shadow","shaft","shallow","share","shed","shell","sheriff","shield","shift","shine","ship","shiver","shock","shoe","shoot","shop","short","shoulder","shove","shrimp","shrug","shuffle","shy","sibling","sick","side","siege","sight","sign","silent","silk","silly","silver","similar","simple","since","sing","siren","sister","situate","six","size","skate","sketch","ski","skill","skin","skirt","skull","slab","slam","sleep","slender","slice","slide","slight","slim","slogan","slot","slow","slush","small","smart","smile","smoke","smooth","snack","snake","snap","sniff","snow","soap","soccer","social","sock","soda","soft","solar","soldier","solid","solution","solve","someone","song","soon","sorry","sort","soul","sound","soup","source","south","space","spare","spatial","spawn","speak","special","speed","spell","spend","sphere","spice","spider","spike","spin","spirit","split","spoil","sponsor","spoon","sport","spot","spray","spread","spring","spy","square","squeeze","squirrel","stable","stadium","staff","stage","stairs","stamp","stand","start","state","stay","steak","steel","stem","step","stereo","stick","still","sting","stock","stomach","stone","stool","story","stove","strategy","street","strike","strong","struggle","student","stuff","stumble","style","subject","submit","subway","success","such","sudden","suffer","sugar","suggest","suit","summer","sun","sunny","sunset","super","supply","supreme","sure","surface","surge","surprise","surround","survey","suspect","sustain","swallow","swamp","swap","swarm","swear","sweet","swift","swim","swing","switch","sword","symbol","symptom","syrup","system","table","tackle","tag","tail","talent","talk","tank","tape","target","task","taste","tattoo","taxi","teach","team","tell","ten","tenant","tennis","tent","term","test","text","thank","that","theme","then","theory","there","they","thing","this","thought","three","thrive","throw","thumb","thunder","ticket","tide","tiger","tilt","timber","time","tiny","tip","tired","tissue","title","toast","tobacco","today","toddler","toe","together","toilet","token","tomato","tomorrow","tone","tongue","tonight","tool","tooth","top","topic","topple","torch","tornado","tortoise","toss","total","tourist","toward","tower","town","toy","track","trade","traffic","tragic","train","transfer","trap","trash","travel","tray","treat","tree","trend","trial","tribe","trick","trigger","trim","trip","trophy","trouble","truck","true","truly","trumpet","trust","truth","try","tube","tuition","tumble","tuna","tunnel","turkey","turn","turtle","twelve","twenty","twice","twin","twist","two","type","typical","ugly","umbrella","unable","unaware","uncle","uncover","under","undo","unfair","unfold","unhappy","uniform","unique","unit","universe","unknown","unlock","until","unusual","unveil","update","upgrade","uphold","upon","upper","upset","urban","urge","usage","use","used","useful","useless","usual","utility","vacant","vacuum","vague","valid","valley","valve","van","vanish","vapor","various","vast","vault","vehicle","velvet","vendor","venture","venue","verb","verify","version","very","vessel","veteran","viable","vibrant","vicious","victory","video","view","village","vintage","violin","virtual","virus","visa","visit","visual","vital","vivid","vocal","voice","void","volcano","volume","vote","voyage","wage","wagon","wait","walk","wall","walnut","want","warfare","warm","warrior","wash","wasp","waste","water","wave","way","wealth","weapon","wear","weasel","weather","web","wedding","weekend","weird","welcome","west","wet","whale","what","wheat","wheel","when","where","whip","whisper","wide","width","wife","wild","will","win","window","wine","wing","wink","winner","winter","wire","wisdom","wise","wish","witness","wolf","woman","wonder","wood","wool","word","work","world","worry","worth","wrap","wreck","wrestle","wrist","write","wrong","yard","year","yellow","you","young","youth","zebra","zero","zone","zoo"],K=new m.default(m.default.givenProvider),M=function(){function e(e,t,r,s){if(this.account_passwords={},this.account_ciphertexts={},this.disable_address=!1,this.account_signatures="",this.setting_path=e,this.account_labels=t,0!==t.length){if(r){if(t.length!==r.length)throw new Error("account_labels should have same length for account_passwords");for(var o=0;o<t.length;o++){if(!this.checkPassword(t[o],r[o].trim()))throw new Error("account_passwords is not correct");this.account_passwords[t[o]]=r[o].trim()}}s&&(this.disable_address=s),this.reload()}}return e.prototype.isLogin=function(e){return e in this.account_passwords},e.prototype.reloadAccount=function(){this.reload()},e.prototype.getAccountLabel=function(e){var t=null;for(var r in this.account_ciphertexts)r.toLocaleLowerCase().includes(e.toLocaleLowerCase())&&(t=r);return null===t?null:{account_address:t,account_label:this.account_ciphertexts[t].account_label}},e.prototype.login=function(e,t){return this.checkPassword(e,t)?(this.account_passwords[e]=t,this.account_labels.push(e),this.reload(),{status:!0,output:"Login success"}):{status:!1,output:"Password is not correct"}},e.prototype.getAccounts=function(e){var t=this.getAccountSignature();t!==this.account_signatures&&(this.account_signatures=t,this.reload());for(var r=Object.keys(this.account_ciphertexts),s=[],o=0;o<r.length;o++)this.getAccountChainType(r[o])===e&&s.push(r[o]);return s},e.prototype.checkAccountLabelIsExist=function(e){return $(this.setting_path,[e])},e.prototype.checkAccountIsExist=function(e){return(e=this.getAccountChecksumAddress(e))in this.account_ciphertexts||(this.reload(),e in this.account_ciphertexts)},e.prototype.checkPassword=function(e,t){var r=f.join(this.setting_path,"accounts/".concat(e,".json"));if(!j(r))return!1;var s,o=A(r);s="PK"===o.account_type?S({salt:t},o.data[0].ciphertexts):{slat:t,data:o.pp_ciphertexts};var n=b.SHA256(JSON.stringify(s)).toString();return o.signature===n},e.prototype.showPrivateKey=function(e){if(!this.checkAccountIsExist(e))throw new Error("Account is not exist");e=this.getAccountChecksumAddress(e);var t=this.account_ciphertexts[e],r=this.account_passwords[t.account_label];return T(t.data,r)},e.prototype.getAccountChainType=function(e){return e.startsWith("0x")&&42===e.length?"evm":/^[A-HJ-NP-Za-km-z1-9]*$/.test(e)?"solana":"unknown"},e.prototype.generatePKAccount=function(e,t,r,s,o){if(o&&this.checkAccountLabelIsExist(e))throw new Error("Account labels already exist");if(!o&&!this.account_passwords[e])throw new Error("Password is not correct");o||(r=this.account_passwords[e]);var n,i=q(t,r);try{n=this.getAccountAddressByPrivateKey(t,s)}catch(e){return{status:!1,output:e.message}}var a={address:n,data:i},c=S({salt:r},a),l={signature:b.SHA256(JSON.stringify(c)).toString(),account_type:"PK",tag:"",ciphertexts:a};return o||(this.account_passwords[e]=r,this.account_labels.push(e)),{status:!0,output:l}},e.prototype.generatePPAccount=function(e,t,r){if(this.checkAccountLabelIsExist(e))return{status:!1,output:"Account labels already exist"};var s=q(t,r),o={slat:r,data:s},n=b.SHA256(JSON.stringify(o)).toString(),i=this.getSubAccount("evm",t,0);if(!1===i.status)return{status:!1,output:i.output};var a=this.getSubAccount("solana",t,0);if(!1===a.status)return{status:!1,output:a.output};var c={signature:n,account_type:"PP",pp_ciphertexts:s,tag:"",data:[{ciphertexts:{evm:{address:i.output.address,data:q(i.output.pk,r)},solana:{address:a.output.address,data:q(a.output.pk,r)}}}]};return this.account_passwords[e]=r,this.account_labels.push(e),{status:!0,output:c}},e.prototype.generateSubAccount=function(e,t){if(!this.checkAccountLabelIsExist(e))return{status:!1,output:"Account labels not exist"};var r=f.join(this.setting_path,"accounts/".concat(e,".json")),s=A(r).pp_ciphertexts,o=T(s,this.account_passwords[e]),n=this.getSubAccount("evm",o,t);if(!1===n.status)return{status:!1,output:n.output};var i=this.getSubAccount("solana",o,t);return!1===i.status?{status:!1,output:i.output}:{status:!0,output:{evm:{address:n.output.address,data:q(n.output.pk,this.account_passwords[e])},solana:{address:i.output.address,data:q(i.output.pk,this.account_passwords[e])}}}},e.prototype.resetPassword=function(e,t){if(!this.checkAccountLabelIsExist(e))return{status:!1,output:"Account labels not exist"};if(!this.checkPassword(e,this.account_passwords[e]))return{status:!1,output:"account passwords is not correct"};var r=f.join(this.setting_path,"accounts/".concat(e,".json")),s=A(r);if("PK"===s.account_type){for(var o=s.data,n=0;n<o.length;n++){var i=o[n].ciphertexts.data,a=T(i,this.account_passwords[e]);o[n].ciphertexts.data=q(a,t)}var c=S({salt:t},s.data[0].ciphertexts);return s.signature=b.SHA256(JSON.stringify(c)).toString(),C(s,r),delete this.account_passwords[e],{status:!0,output:"Password reset successfully"}}var l=T(s.pp_ciphertexts,this.account_passwords[e]);s.pp_ciphertexts=q(l,t);var u={slat:t,data:s.pp_ciphertexts};s.signature=b.SHA256(JSON.stringify(u)).toString();var p=s.data;for(n=0;n<p.length;n++){var d=T(p[n].ciphertexts.evm.data,this.account_passwords[e]);p[n].ciphertexts.evm.data=q(d,t);var h=T(p[n].ciphertexts.solana.data,this.account_passwords[e]);p[n].ciphertexts.solana.data=q(h,t)}return C(s,r),delete this.account_passwords[e],{status:!0,output:"Password reset successfully"}},e.prototype.signTransaction=function(e,t,r){return e=this.getAccountChecksumAddress(e),this.checkAccountIsExist(e)?"unknown"===this.getAccountChainType(e)?{status:!1,output:"Chain type unknown"}:"evm"===this.getAccountChainType(e)?this.signEvmTransaction(t,r):this.signSolanaTransaction(e,r,t):{status:!1,output:"Account is not exist"}},e.prototype.sendSignedTransaction=function(e,t,r){return e=this.getAccountChecksumAddress(e),this.checkAccountIsExist(e)?"unknown"===this.getAccountChainType(e)?{status:!1,output:"Chain type unknown"}:"evm"===this.getAccountChainType(e)?this.sendEvmTransaction(t,r):this.sendSolanaTransaction(t,r):{status:!1,output:"Account is not exist"}},e.prototype.signMessage=function(e,t){return e=this.getAccountChecksumAddress(e),this.checkAccountIsExist(e)?"unknown"===this.getAccountChainType(e)?{status:!1,output:"Chain type unknown"}:"evm"===this.getAccountChainType(e)?{status:!0,output:this.signEvmMessage(t,e)}:{status:!0,output:this.signSolanaMessage(t,e)}:{status:!1,output:"Account is not exist"}},e.prototype.simulateTransaction=function(e,t,r){return k(this,void 0,void 0,function(){var s,o,n;return x(this,function(i){switch(i.label){case 0:return s=new a.Connection(t),o=this.showPrivateKey(e),n=a.Keypair.fromSecretKey(v.decode(o)),[4,_(s.simulateTransaction.bind(s),[r,[n]])];case 1:return[2,i.sent()]}})})},e.prototype.signEvmTransaction=function(e,t){return k(this,void 0,void 0,function(){var r,s,o,n;return x(this,function(i){switch(i.label){case 0:return this.account_passwords?(r=e.from,e.gas?[3,2]:[4,new P(t).getEvmGasLimit(e,t)]):[2,{status:!1,output:"Please set password first"}];case 1:if(!(s=i.sent()).status)return[2,s];e.gas=s.output,i.label=2;case 2:return e.gasPrice?[3,4]:[4,new P(t).getEvmGasPrice()];case 3:if(!(s=i.sent()).status)return[2,s];e.gasPrice=s.output,i.label=4;case 4:return o=this.showPrivateKey(r),n=new m.default(t),[4,_(n.eth.accounts.signTransaction.bind(n.eth.accounts),[e,o])];case 5:return[2,i.sent()]}})})},e.prototype.sendEvmTransaction=function(e,t){return k(this,void 0,void 0,function(){var r;return x(this,function(s){switch(s.label){case 0:return r=new m.default(t),[4,_(r.eth.sendSignedTransaction.bind(r.eth),[e])];case 1:return[2,s.sent()]}})})},e.prototype.signSolanaTransaction=function(e,t,r){return k(this,void 0,void 0,function(){var s,o,n,i,l;return x(this,function(u){switch(u.label){case 0:return s=this.showPrivateKey(e),o=a.Keypair.fromSecretKey(v.decode(s)),n=new c.Wallet(o),"recentBlockhash"in r&&r.recentBlockhash?[3,2]:(i=new a.Connection(t),[4,_(i.getLatestBlockhash.bind(i),[])]);case 1:if(!(l=u.sent()).status)return[2,{status:!1,output:"Failed to get latest blockhash"}];r.recentBlockhash=l.output.blockhash,u.label=2;case 2:return r.feePayer=n.publicKey,[4,_(n.signTransaction.bind(n),[r])];case 3:return[2,u.sent()]}})})},e.prototype.sendSolanaTransaction=function(e,t){return k(this,void 0,void 0,function(){var r;return x(this,function(s){switch(s.label){case 0:return r=new a.Connection(t),[4,_(r.sendRawTransaction.bind(r),[e.serialize()])];case 1:return[2,s.sent()]}})})},e.prototype.signEvmMessage=function(e,t){var r=this.showPrivateKey(t);return K.eth.accounts.sign(e,r).signature},e.prototype.signSolanaMessage=function(e,t){var r=this.showPrivateKey(t),s=y.sign.detached(new Uint8Array(e.match(/.{1,2}/g).map(function(e){return parseInt(e,16)})),v.decode(r));return v.encode(s)},e.prototype.checkIsDisableAddress=function(e,t){if(!e||!this.disable_address)return!1;for(var r=e.length,s=0;s<r;s++){var o=e[s].from,n=e[s].to;if(t>=o&&t<=n)return!0}return!1},e.prototype.reload=function(){if(this.account_labels=I(this.setting_path,this.account_labels),!$(this.setting_path,this.account_labels))throw new Error("Account labels not exist");for(var e={},t=this.account_labels.length,r=0;r<t;r++){var s=f.join(this.setting_path,"accounts/".concat(this.account_labels[r],".json"));if(g.existsSync(s)){var o=JSON.parse(g.readFileSync(s,"utf8"));if("PK"!==o.account_type){var n=o.data.length,i=o.disabled_slots;for(l=0;l<n;l++)this.checkIsDisableAddress(i,l)||(e[o.data[l].ciphertexts.evm.address]={account_label:this.account_labels[r],data:o.data[l].ciphertexts.evm.data},e[o.data[l].ciphertexts.solana.address]={account_label:this.account_labels[r],data:o.data[l].ciphertexts.solana.data})}else{var a=o.data;if(!a)continue;for(var c=a.length,l=0;l<c;l++)e[a[l].ciphertexts.address]={account_label:this.account_labels[r],data:a[l].ciphertexts.data}}}}this.account_ciphertexts=e},e.prototype.getAccountChecksumAddress=function(e){return"evm"===this.getAccountChainType(e)&&(e=K.utils.toChecksumAddress(e)),e},e.prototype.getAccountAddressByPrivateKey=function(e,t){return"evm"===this.getNetworkTypeByChainId(t)?K.eth.accounts.privateKeyToAccount(e).address:a.Keypair.fromSecretKey(v.decode(e)).publicKey.toBase58()},e.prototype.getNetworkTypeByChainId=function(e){return"901"===e||"902"===e||"903"===e?"solana":"evm"},e.prototype.getSubAccount=function(e,t,r){if(!function(e){var t=e.split(/\s+/g),r=t.length;if(12!==r&&24!==r)return!1;for(var s=0;s<r;s++)if(!O.includes(t[s]))return!1;return!0}(t))return{status:!1,output:"Please set correct mnemonic"};if("solana"===e){var s=w.mnemonicToSeedSync(t),o=p.HDKey.fromMasterSeed(s),n=a.Keypair.fromSeed(o.derive("m/44'/501'/".concat(r,"'/0'")).privateKey);return{status:!0,output:{address:n.publicKey.toBase58(),pk:v.encode(n.secretKey)}}}if("evm"===e){s=w.mnemonicToSeedSync(t);var i=(o=u.hdkey.fromMasterSeed(s)).derivePath("m/44'/60'/0'/0").deriveChild(r).getWallet();return{status:!0,output:{address:K.utils.toChecksumAddress(i.getAddressString()),pk:i.getPrivateKeyString()}}}return{status:!1,output:"Unknown chain type"}},e.prototype.getAccountSignature=function(){for(var e=this.account_labels.length,t=[],r=0;r<e;r++){var s=f.join(this.setting_path,"accounts/".concat(this.account_labels[r],".json")),o=g.readFileSync(s,"utf8");t.push(o)}return b.MD5(JSON.stringify(t)).toString()},e}(),D=ce,L=function(){function e(e,t,r,s){this.account=new M(e,t,r,s)}return e.version=D.version,e}();e.WativeCore=L,Object.defineProperty(e,"__esModule",{value:!0})}(t,I.default,$.default,T.default,M.default,D.default,L.default,O.default,H.default,z.default,N.default,R.default)}(0,ae.exports);class le{constructor(e,t){this.runningServices=new Map,this.configManager=new B(e,t),this.pidDir=j.join(this.configManager.getKeystorePath(),"ssh","pids"),this.ensurePidDir(),this.setupLogger()}ensurePidDir(){E.existsSync(this.pidDir)||E.mkdirSync(this.pidDir,{recursive:!0})}async isPortInUse(e,t="127.0.0.1"){return new Promise(r=>{const s=F.createServer();s.listen(e,t,()=>{s.once("close",()=>{r(!1)}),s.close()}),s.on("error",e=>{"EADDRINUSE"===e.code?r(!0):r(!1)})})}getPidFilePath(e){return j.join(this.pidDir,`${e}.pid`)}writePidFile(e,t){const r=this.getPidFilePath(e);E.writeFileSync(r,t.toString())}readPidFile(e){const t=this.getPidFilePath(e);if(!E.existsSync(t))return null;try{const e=E.readFileSync(t,"utf8").trim();return parseInt(e,10)}catch(e){return null}}removePidFile(e){const t=this.getPidFilePath(e);E.existsSync(t)&&E.unlinkSync(t)}isProcessRunning(e){try{return process.kill(e,0),!0}catch(e){return!1}}async startService(e,t){if(this.runningServices.has(e))throw new Error(`Service '${e}' is already running.`);const r=this.configManager.loadServiceConfig(e);if(await this.isPortInUse(r.ssh.port,r.ssh.listen)){const t=`Port ${r.ssh.port} on ${r.ssh.listen} is already in use. Cannot start SSH service '${e}'.`;throw this.logger.error(t),console.error(`Error: ${t}`),new Error(t)}this.logger.info(`Port ${r.ssh.port} on ${r.ssh.listen} is available for service '${e}'`);const s=t||await this.promptForPasswords(r.keystore.allowed_keystores),o=await this.configManager.validateKeystorePasswords(r.keystore.allowed_keystores,s),n=Object.entries(o).filter(([e,t])=>!t).map(([e,t])=>e);if(n.length>0)throw new Error(`Invalid passwords for keystores: ${n.join(", ")}`);const i=this.createServerInstance(r,s);i.listen(r.ssh.listen,r.ssh.port),this.writePidFile(e,process.pid),this.logger.info(`SSH service '${e}' started on ${r.ssh.listen}:${r.ssh.port}`),console.log(`SSH service '${e}' is now running in the background on ${r.ssh.listen}:${r.ssh.port}`);const a={config:r,passwords:s,server:i};this.runningServices.set(e,a),this.setupServiceLogger(e)}async stopService(e){const t=this.runningServices.get(e),r=this.readPidFile(e),s=j.join(this.pidDir,`${e}-daemon.pid`),o=j.join(this.pidDir,`${e}-watcher.pid`);let n=null,i=null;if(E.existsSync(s)){const e=E.readFileSync(s,"utf8").trim();e&&(n=parseInt(e))}if(E.existsSync(o)){const e=E.readFileSync(o,"utf8").trim();e&&(i=parseInt(e))}if(t)t.server&&t.server.close&&t.server.close(),this.runningServices.delete(e);else if(i&&this.isProcessRunning(i))try{process.kill(i,"SIGTERM"),setTimeout(()=>{this.isProcessRunning(i)&&process.kill(i,"SIGKILL");try{E.existsSync(o)&&E.unlinkSync(o),E.existsSync(s)&&E.unlinkSync(s)}catch(e){}},5e3)}catch(e){if(n&&this.isProcessRunning(n))try{process.kill(n,"SIGTERM"),setTimeout(()=>{this.isProcessRunning(n)&&process.kill(n,"SIGKILL")},5e3)}catch(e){}try{E.existsSync(o)&&E.unlinkSync(o),E.existsSync(s)&&E.unlinkSync(s)}catch(e){}}else if(n&&this.isProcessRunning(n))try{process.kill(n,"SIGTERM"),setTimeout(()=>{this.isProcessRunning(n)&&process.kill(n,"SIGKILL")},5e3),E.existsSync(s)&&E.unlinkSync(s)}catch(e){}else{if(!r||!this.isProcessRunning(r))throw new Error(`Service '${e}' is not running.`);try{process.kill(r,"SIGTERM"),setTimeout(()=>{this.isProcessRunning(r)&&process.kill(r,"SIGKILL")},5e3)}catch(e){}}this.removePidFile(e),this.logger.info(`SSH service '${e}' stopped.`)}async restartService(e,t){this.runningServices.has(e)&&await this.stopService(e),await this.startService(e,t)}getRunningServices(){return Array.from(this.runningServices.keys())}getServiceConfig(e){return this.configManager.loadServiceConfig(e)}getServiceStatus(e){if(this.runningServices.has(e))return"running";try{this.configManager.loadServiceConfig(e);const t=j.join(this.pidDir,`${e}-daemon.pid`);if(E.existsSync(t)){const e=E.readFileSync(t,"utf8").trim();if(e){const r=parseInt(e);if(this.isProcessRunning(r))return"running";E.unlinkSync(t)}}const r=this.readPidFile(e);return r&&this.isProcessRunning(r)?"running":(r&&this.removePidFile(e),"stopped")}catch(e){return"not_found"}}async stopAllServices(){const e=Array.from(this.runningServices.keys());for(const t of e)await this.stopService(t)}async createService(e,t,r,s,o){return this.configManager.createServiceConfig(e,t,r,s,o)}async removeService(e){this.runningServices.has(e)&&await this.stopService(e),this.configManager.removeServiceConfig(e),this.logger.info(`Service '${e}' removed.`)}listServices(){return this.configManager.listServiceConfigs().map(e=>{const t=this.getServiceStatus(e);let r,s;try{const t=this.configManager.loadServiceConfig(e);r=t.ssh.port,s=t.description}catch(e){}return{name:e,status:t,port:r,description:s}})}updateServiceKeystores(e,t){this.configManager.updateServiceConfig(e,{keystore:{path:this.configManager.loadServiceConfig(e).keystore.path,allowed_keystores:t}})}async promptForPasswords(e){const t={};for(const r of e){let e,s=!1,o=0;const n=3;for(;!s&&o<n;){e=await W(`Enter password for keystore [${r}]`);try{const i=this.configManager.getKeystorePath();if(s=new ae.exports.WativeCore(i,[r]).account.checkPassword(r,e),s){t[r]=e;break}if(o++,!(o<n))throw new Error(`Failed to authenticate keystore [${r}] after ${n} attempts.`);console.log(`Invalid password for ${r}`)}catch(e){if(o++,!(o<n))throw new Error(`Failed to authenticate keystore [${r}] after ${n} attempts: ${e.message}`);console.log("Error validating password for keystore")}}}return t}createServerInstance(e,t){const r=e.clients;if(0===r.length)throw new Error("No clients configured for service");if(r.length>1)throw new Error("Only one client is supported for this service");const s=JSON.parse(r[0]),o=[s.name],n=[s.public_key_path],i=[s.allowed_keystores],a=e.keystore.allowed_keystores;if(0===a.length)throw new Error("No keystores configured for service");let c=[];for(const e of a)c.push(t[e]);return new ne(e.server_keys.private_key_path,e.server_keys.passphrase,o,n,i,e.keystore.path,a,c)}async showLogs(e,t=50,s=!1){const o=process.env.HOME+"/.wative/logs";let n;if(n=e?j.join(o,`${e}.log`):j.join(o,"service_manager.log"),!E.existsSync(n))throw new Error(`Log file not found: ${n}`);const i=s?["-f",`-n${t}`,n]:[`-n${t}`,n],a=r.spawn("tail",i,{stdio:["ignore","inherit","inherit"]});return s?(process.on("SIGINT",()=>{a.kill("SIGTERM"),process.exit(0)}),new Promise((e,t)=>{a.on("close",r=>{0===r?e():t(new Error(`tail process exited with code ${r}`))})})):new Promise((e,t)=>{a.on("close",r=>{0===r?e():t(new Error(`tail process exited with code ${r}`))})})}setupLogger(){const e=process.env.HOME+"/.wative/logs";E.existsSync(e)||E.mkdirSync(e,{recursive:!0}),K.configure({appenders:{file:{type:"file",filename:j.join(e,"service_manager.log"),maxLogSize:10485760,backups:3,compress:!0,keepFileExt:!0,layout:{type:"pattern",pattern:"%d{yyyy-MM-dd hh:mm:ss.SSS} [%p] %c - %m"},encoding:"utf-8"},console:{type:"console"}},categories:{default:{appenders:["file","console"],level:"info"}}}),this.logger=K.getLogger("service_manager"),this.logger.level="info"}setupServiceLogger(e){const t=process.env.HOME+"/.wative/logs";E.existsSync(t)||E.mkdirSync(t,{recursive:!0});const r=j.join(t,`${e}.log`);this.cleanupOldLogs(t),K.configure({appenders:{file:{type:"file",filename:j.join(t,"service_manager.log"),maxLogSize:10485760,backups:3,compress:!0,keepFileExt:!0,layout:{type:"pattern",pattern:"%d{yyyy-MM-dd hh:mm:ss.SSS} [%p] %c - %m"},encoding:"utf-8"},console:{type:"console"},[`${e}_file`]:{type:"file",filename:r,maxLogSize:10485760,backups:3,compress:!0,keepFileExt:!0,layout:{type:"pattern",pattern:"%d{yyyy-MM-dd hh:mm:ss.SSS} [%p] %c - %m"},encoding:"utf-8"}},categories:{default:{appenders:["file","console"],level:"info"},[e]:{appenders:[`${e}_file`],level:"info"}}})}cleanupOldLogs(e){try{const t=E.readdirSync(e),r=new Date;r.setDate(r.getDate()-3),t.forEach(t=>{const s=j.join(e,t);E.statSync(s).mtime<r&&t.endsWith(".log")&&(E.unlinkSync(s),this.logger.info(`Deleted old log file: ${t}`))})}catch(e){this.logger.warn(`Failed to cleanup old logs: ${e}`)}}}const ue=new t.Command,pe=require("../package.json");let de;ue.version(pe.version).description("Wative CLI Tool"),ue.command("version").description("Show the version of wative").action(()=>{console.log(`Wative CLI Tool v${pe.version}`)});const he=()=>{if(!de){const e=j.join(process.env.HOME||"",".wative","ssh");de=new le(e)}return de},ge=ue.command("ssh").description("Manage SSH services");ge.command("start").description("Start SSH service").option("-c, --config <name>","Specify service configuration name").option("-d, --daemon","Run service in daemon mode").action(async e=>{const t=he();try{e.config||(console.error("Error: Configuration name is required. Use -c or --config to specify a service configuration."),process.exit(1));const s=e.config,o=t.getServiceConfig(s),n=require("net"),i=async(e,t="127.0.0.1")=>new Promise(r=>{const s=n.createServer();s.listen(e,t,()=>{s.once("close",()=>{r(!1)}),s.close()}),s.on("error",e=>{"EADDRINUSE"===e.code?r(!0):r(!1)})});if(await i(o.ssh.port,o.ssh.listen)){const e=`Port ${o.ssh.port} on ${o.ssh.listen} is already in use. Cannot start SSH service '${s}'.`;console.error(`Error: ${e}`),process.exit(1)}if(console.log(`Port ${o.ssh.port} on ${o.ssh.listen} is available for service '${s}'`),e.daemon){console.log(`Starting SSH service '${s}' in daemon mode...`);const e=await t.promptForPasswords(o.keystore.allowed_keystores),n=require("crypto"),i=n.randomBytes(32),a=n.randomBytes(16),c=n.createCipheriv("aes-256-cbc",i,a);let l=c.update(JSON.stringify(e),"utf8","hex");l+=c.final("hex");const u=a.toString("hex")+":"+i.toString("hex")+":"+l;return void((e,t)=>{const s=j.join(process.env.HOME||"",".wative","logs"),o=j.join(process.env.HOME||"",".wative","ssh","pids");E.existsSync(s)||E.mkdirSync(s,{recursive:!0}),E.existsSync(o)||E.mkdirSync(o,{recursive:!0});const n=j.join(s,`${e}-daemon.log`),i=j.join(o,`${e}-daemon.pid`),a=j.join(o,`${e}-watcher.pid`),c=r.spawn("node",[j.resolve(__dirname,"daemon-watcher.js"),e,n,i,a,j.resolve(__dirname,"..")],{detached:!0,stdio:"ignore",env:{...process.env,WATIVE_ENCRYPTED_PASSWORDS:t}});E.writeFileSync(a,c.pid.toString()),c.unref(),console.log(`SSH service '${e}' daemon watcher started with PID: ${c.pid}`),console.log(`Daemon log file: ${n}`),console.log(`Watcher PID file: ${a}`)})(s,u)}if(process.env.WATIVE_DAEMON_PASSWORDS&&process.env.WATIVE_WORKER_MODE){const e=require("crypto"),t=process.env.WATIVE_DAEMON_PASSWORDS;delete process.env.WATIVE_DAEMON_PASSWORDS,delete process.env.WATIVE_WORKER_MODE;try{const r=t.split(":"),o=Buffer.from(r[0],"hex"),n=Buffer.from(r[1],"hex"),i=r[2],a=e.createDecipheriv("aes-256-cbc",n,o);let c=a.update(i,"hex","utf8");c+=a.final("utf8");const l=JSON.parse(c);console.log(`[${(new Date).toISOString()}] Worker process starting SSH service '${s}'...`);const u=he();await u.startService(s,l);for(const e in l)l[e]=null,delete l[e];console.log(`[${(new Date).toISOString()}] SSH service '${s}' started successfully`);const p=async e=>{console.log(`[${(new Date).toISOString()}] Worker received ${e}, stopping service...`);try{await u.stopService(s),console.log(`[${(new Date).toISOString()}] Service stopped successfully`)}catch(e){console.error(`[${(new Date).toISOString()}] Error stopping service:`,e)}process.exit(0)};process.on("SIGTERM",()=>p("SIGTERM")),process.on("SIGINT",()=>p("SIGINT"));const d=setInterval(async()=>{try{const e=await u.getServiceStatus(s);"running"!==e&&(console.log(`[${(new Date).toISOString()}] Service status changed to: ${e}`),"stopped"===e&&(console.log(`[${(new Date).toISOString()}] Service stopped unexpectedly, exiting worker...`),clearInterval(d),process.exit(1)))}catch(e){console.error(`[${(new Date).toISOString()}] Error checking service status:`,e)}},3e4),h=setInterval(()=>{},6e4),g=()=>{clearInterval(d),clearInterval(h)};process.on("exit",g)}catch(e){console.error(`[${(new Date).toISOString()}] Worker process error:`,e),process.exit(1)}return}{await t.startService(s),console.log(`SSH service '${s}' started successfully`),process.on("SIGINT",async()=>{console.log("\nReceived SIGINT, stopping services..."),await t.stopAllServices(),process.exit(0)}),process.on("SIGTERM",async()=>{console.log("\nReceived SIGTERM, stopping services..."),await t.stopAllServices(),process.exit(0)});const e=setInterval(()=>{"running"!==t.getServiceStatus(s)&&(console.log(`Service ${s} is no longer running, exiting...`),clearInterval(e),process.exit(1))},5e3);process.stdin.resume()}}catch(e){console.error(`Error: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}),ge.command("stop").description("Stop SSH service").option("-c, --config <name>","Specify service configuration name").action(async e=>{const t=he();try{e.config||(console.error("Error: Configuration name is required. Use -c or --config to specify a service configuration."),process.exit(1)),await t.stopService(e.config),console.log(`SSH service '${e.config}' stopped successfully`)}catch(e){console.error(`Error: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}),ge.command("restart").description("Restart SSH service").option("-c, --config <name>","Specify service configuration name").action(async e=>{const t=he();try{e.config||(console.error("Error: Configuration name is required. Use -c or --config to specify a service configuration."),process.exit(1)),await t.restartService(e.config),console.log(`SSH service '${e.config}' restarted successfully`)}catch(e){console.error(`Error: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}),ge.command("create").description("Create new SSH service configuration interactively").action(async()=>{const e=require("readline"),t=require("fs"),r=require("path"),{SSHConfigManager:s}=require("./ssh/config_manager"),o=e.createInterface({input:process.stdin,output:process.stdout}),n=e=>new Promise(t=>{o.question(e,t)});try{console.log("SSH create command started...");const e=r.join(process.env.HOME||"",".wative/ssh"),o=(await n(`SSH storage located in (default: ${e}): `)).trim()||e,i=r.join(process.env.HOME||"",".wative"),a=(await n(`Keystore storage located in (default: ${i}): `)).trim()||i,c=new s(o,a);let l,u,p,d;for(;;)if(l=await n("Enter service name: "),l.trim())try{c.loadServiceConfig(l),console.log("Service name already exists, please enter a different name")}catch(e){break}else console.log("Service name cannot be empty");for(;;){const e=await n("Enter port number: ");if(u=parseInt(e),isNaN(u)||u<1024||u>65535){console.log("Port number must be between 1024-65535");continue}const t=c.listServiceConfigs();let r=!1;for(const e of t)try{if(c.loadServiceConfig(e).ssh.port===u){r=!0;break}}catch(e){}if(!r)break;console.log(`Port ${u} is already in use by another service, please enter a different port`)}for(;;){const e=await n("Enter allowed keystore list (comma separated): ");if(!e.trim()){console.log("Keystore list cannot be empty");continue}if(p=e.split(",").map(e=>e.trim()).filter(e=>e),0===p.length){console.log("At least one valid keystore is required");continue}const s=r.join(a,"accounts");let o=!0;for(const e of p){const n=r.join(s,`${e}.json`);if(!t.existsSync(n)){console.log(`Keystore '${e}' does not exist`),o=!1;break}}if(o){console.log("All keystores verified to exist");break}console.log("Please re-enter valid keystore list")}for(;d=await n("Enter remote client name: "),!d.trim();)console.log("Client name cannot be empty");const h=r.join(o,"conf.d",l);t.existsSync(h)||t.mkdirSync(h,{recursive:!0});const g=r.join(h,`${d}.pub`);for(console.log("\nPlease place the remote client's public key file at the following path:"),console.log(`${g}`),console.log("\nPress Enter to continue after placing the file...");;){if(await n(""),t.existsSync(g)){console.log("Client public key file found");break}console.log("Client public key file not found, please confirm the file is correctly placed and press Enter again")}const f=await n("Enter service description (optional): ");console.log("\nCreating SSH service configuration...");const m=await c.createServiceConfig(l,u,p,d,f||void 0);console.log("\nNote: Passwords will be requested when starting the service."),console.log(`\nSSH service configuration '${l}' created successfully!`),console.log(`Port: ${u}`),console.log(`Allowed keystores: ${p.join(", ")}`),console.log(`Client name: ${d}`),console.log(`Server private key: ${m.server_keys.private_key_path}`),console.log(`Client public key: ${g}`)}catch(e){console.error(`Error: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}finally{o.close()}}),ge.command("remove").description("Remove SSH service configuration").option("-c, --config <name>","Service configuration name").action(async e=>{const t=he();try{e.config||(console.error("Error: Configuration name is required for remove command"),process.exit(1)),await t.removeService(e.config),console.log(`SSH service configuration '${e.config}' removed successfully`)}catch(e){console.error(`Error: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}),ge.command("list").description("List all SSH service configurations").action(async()=>{const e=new B,t=new le,r=e.listServiceConfigs();if(0!==r.length){console.log("SSH Service Configurations:");for(const s of r)try{const r=e.loadServiceConfig(s),o=t.getServiceStatus(s);console.log(` - ${s}: ${r.description||"No description"} (${o})`)}catch(e){const r=t.getServiceStatus(s);console.log(` - ${s}: Configuration error (${r})`)}}else console.log("No SSH service configurations found.")}),ge.command("status").description("Show SSH service status").option("-c, --config <name>","Service configuration name").action(async e=>{const t=he();try{if(e.config){const r=t.getServiceStatus(e.config);console.log(`SSH service '${e.config}' status: ${r}`)}else{const e=t.listServices();if(0===e.length)return void console.log("No SSH service configurations found");console.log("SSH Service Status:"),e.forEach(e=>{const r=t.getServiceStatus(e.name);console.log(` - ${e.name}: ${r}`)})}}catch(e){console.error(`Error: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}),ge.command("log").description("Show SSH service logs").option("-c, --config <name>","Service configuration name").option("-n, --lines <number>","Number of lines to show (default: 50)","50").option("-f, --follow","Follow log output").action(async e=>{const t=he();try{const r=parseInt(e.lines)||50;await t.showLogs(e.config,r,e.follow)}catch(e){console.error(`Error: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}),ue.command("cmd").description("Start wallet-cli shell").action(async()=>{try{r.execSync("wallet-cli",{stdio:"inherit"})}catch(e){}}),ue.parse(process.argv)});
|
package/lib/web3.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export declare const getChainIdByEvm: (rpc_url: string) => Promise<import("./utils").Result>;
|
|
2
|
+
export declare const getAccountBalanceInEvm: (account: string, rpc_url: string) => Promise<import("./utils").Result>;
|
|
3
|
+
export declare const getAccountBalanceInSolana: (account: string, rpc_url: string) => Promise<import("./utils").Result>;
|
|
4
|
+
export declare const getTokenInfoInEvm: (token_address: string, rpc_url: string) => Promise<{
|
|
5
|
+
status: boolean;
|
|
6
|
+
output: string;
|
|
7
|
+
} | {
|
|
8
|
+
status: boolean;
|
|
9
|
+
output: {
|
|
10
|
+
symbol: any;
|
|
11
|
+
name: any;
|
|
12
|
+
decimals: any;
|
|
13
|
+
};
|
|
14
|
+
}>;
|
|
15
|
+
export declare const getTokenInfoInSolana: (token_address: string, rpc_url: string) => Promise<{
|
|
16
|
+
status: boolean;
|
|
17
|
+
output: {
|
|
18
|
+
symbol: string;
|
|
19
|
+
name: string;
|
|
20
|
+
decimals: string;
|
|
21
|
+
};
|
|
22
|
+
} | {
|
|
23
|
+
status: boolean;
|
|
24
|
+
output: string;
|
|
25
|
+
}>;
|
|
26
|
+
export declare const getTokenBalanceInEvm: (account: string, token_address: string, rpc_url: string) => Promise<{
|
|
27
|
+
status: boolean;
|
|
28
|
+
output: any;
|
|
29
|
+
}>;
|
|
30
|
+
export declare const getTokenBalanceInSolana: (account: string, token_address: string, rpc_url: string) => Promise<{
|
|
31
|
+
status: boolean;
|
|
32
|
+
output: any;
|
|
33
|
+
}>;
|
|
34
|
+
export declare const getCodeInEvm: (account: string, rpc_url: string) => Promise<{
|
|
35
|
+
status: boolean;
|
|
36
|
+
output: any;
|
|
37
|
+
}>;
|
|
38
|
+
export declare const getTransferTokenData: (to: string, amount: string, rpc_url: string) => Promise<string>;
|
|
39
|
+
export declare const getPrioritizationFee: (rpc_url: string) => Promise<{
|
|
40
|
+
status: boolean;
|
|
41
|
+
output: string;
|
|
42
|
+
} | {
|
|
43
|
+
status: boolean;
|
|
44
|
+
output: number;
|
|
45
|
+
}>;
|
|
46
|
+
export declare const getLatestBlockhash: (rpc_url: string) => Promise<{
|
|
47
|
+
status: boolean;
|
|
48
|
+
output: any;
|
|
49
|
+
}>;
|
|
50
|
+
export declare const getAccountInfoInSolana: (account: string, rpc_url: string) => Promise<{
|
|
51
|
+
status: boolean;
|
|
52
|
+
output: any;
|
|
53
|
+
}>;
|
|
54
|
+
export declare const updateBalance: (account_address_list: string[], token_address: string, chain_id: string, rpc_url: string, is_evm: boolean) => Promise<any>;
|
|
55
|
+
export declare const getTokenBalance: (chain_id: string, account_address_list: any, asset_info_list: any, network_info: any) => any;
|
|
56
|
+
export declare const deleteTokenBalance: (chain_id: string, account_address_list: string[], token_address_list: string[]) => void;
|
|
57
|
+
export declare const batchUpdateUserTokenBalance: (chain_id: string, account_address: string, token_address_list: string[], rpc_url: string, is_evm: boolean) => Promise<void>;
|
|
58
|
+
export declare const batchHasTokenBalance: (chain_id: string, account_address_list: string[]) => boolean;
|
|
59
|
+
//# sourceMappingURL=web3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web3.d.ts","sourceRoot":"","sources":["../src/web3.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,eAAe,GAAU,SAAS,MAAM,sCAIpD,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAU,SAAS,MAAM,EAAE,SAAS,MAAM,sCAI5E,CAAA;AAED,eAAO,MAAM,yBAAyB,GAAU,SAAS,MAAM,EAAE,SAAS,MAAM,sCAI/E,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAU,eAAe,MAAM,EAAE,SAAS,MAAM;;;;;;;;;;EAiE7E,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAU,eAAe,MAAM,EAAE,SAAS,MAAM;;;;;;;;;;EA0ChF,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAU,SAAS,MAAM,EAAE,eAAe,MAAM,EAAE,SAAS,MAAM;;;EAkCjG,CAAA;AAED,eAAO,MAAM,uBAAuB,GAAU,SAAS,MAAM,EAAE,eAAe,MAAM,EAAE,SAAS,MAAM;;;EAoBpG,CAAA;AAED,eAAO,MAAM,YAAY,GAAU,SAAS,MAAM,EAAE,SAAS,MAAM;;;EAalE,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAU,IAAI,MAAM,EAAE,QAAQ,MAAM,EAAE,SAAS,MAAM,oBAsBrF,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAU,SAAS,MAAM;;;;;;EAkBzD,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAU,SAAS,MAAM;;;EAevD,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAU,SAAS,MAAM,EAAE,SAAS,MAAM;;;EAe5E,CAAA;AAED,eAAO,MAAM,aAAa,GAAU,sBAAsB,MAAM,EAAE,EAAE,eAAe,MAAM,EAAE,UAAU,MAAM,EAAE,SAAS,MAAM,EAAE,QAAQ,OAAO,iBAyC5I,CAAA;AAED,eAAO,MAAM,eAAe,GACxB,UAAU,MAAM,EAChB,sBAAsB,GAAG,EACzB,iBAAiB,GAAG,EACpB,cAAc,GAAG,QA0CpB,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,EAAE,sBAAsB,MAAM,EAAE,EAAE,oBAAoB,MAAM,EAAE,SAUhH,CAAA;AAED,eAAO,MAAM,2BAA2B,GAAU,UAAU,MAAM,EAAE,iBAAiB,MAAM,EAAE,oBAAoB,MAAM,EAAE,EAAE,SAAS,MAAM,EAAE,QAAQ,OAAO,kBAK1J,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,UAAU,MAAM,EAAE,sBAAsB,MAAM,EAAE,YAepF,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wative",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.17",
|
|
4
4
|
"description": "An agile keystore management toolkit",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"bin": {
|
|
12
12
|
"wallet-cli": "bin/wative-cli.js",
|
|
13
|
-
"wative": "bin/wative.js"
|
|
14
|
-
"wative-ssh": "bin/wative-ssh.sh"
|
|
13
|
+
"wative": "bin/wative.js"
|
|
15
14
|
},
|
|
16
15
|
"repository": {
|
|
17
16
|
"type": "git",
|
|
@@ -40,7 +39,8 @@
|
|
|
40
39
|
"@types/node-fetch": "2.6.11",
|
|
41
40
|
"bip39": "3.1.0",
|
|
42
41
|
"cli-progress": "3.12.0",
|
|
43
|
-
"
|
|
42
|
+
"commander": "^9.5.0",
|
|
43
|
+
"crypto-js": "^4.2.0",
|
|
44
44
|
"dotenv": "16.4.5",
|
|
45
45
|
"ethereumjs-wallet": "1.0.2",
|
|
46
46
|
"ethers-multicall": "0.2.3",
|
|
@@ -68,6 +68,10 @@
|
|
|
68
68
|
},
|
|
69
69
|
"keywords": [],
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@
|
|
71
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
72
|
+
"@types/node": "^24.2.0",
|
|
73
|
+
"@types/ssh2": "^1.15.4",
|
|
74
|
+
"rollup-plugin-copy": "^3.5.0",
|
|
75
|
+
"ts-node": "^10.9.2"
|
|
72
76
|
}
|
|
73
77
|
}
|
package/src/assets.ts
CHANGED
|
@@ -88,19 +88,10 @@ export const updateTokenBalanceOption = async (
|
|
|
88
88
|
account_address: string
|
|
89
89
|
) => {
|
|
90
90
|
const network_info = getNetworkInfoByName(keystore_path, default_network);
|
|
91
|
-
const network_type = getChainType(network_info.chainId.toString());
|
|
92
91
|
let asset_info_list = await getAssetList(keystore_path, network_info.chainId.toString());
|
|
93
92
|
let token_list_addrs = asset_info_list.map((item: any) => item.address);
|
|
94
93
|
token_list_addrs.push("0");
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
await batchUpdateUserTokenBalance(
|
|
98
|
-
network_info.chainId.toString(),
|
|
99
|
-
account_address,
|
|
100
|
-
token_list_addrs,
|
|
101
|
-
network_info.rpcUrl,
|
|
102
|
-
is_evm
|
|
103
|
-
);
|
|
94
|
+
deleteTokenBalance(network_info.chainId.toString(), [account_address], token_list_addrs);
|
|
104
95
|
}
|
|
105
96
|
|
|
106
97
|
export const saveAsset = async (
|