wative 1.0.44 → 1.1.1

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/bin/wative-ssh.sh CHANGED
@@ -11,7 +11,6 @@ awk -F "=" '/^\[keystore\]/ {flag=1} flag && /^allowed_keystores/ {print $2}' "$
11
11
  # Clear previous environment variables file
12
12
  > "$ENV_FILE"
13
13
 
14
-
15
14
  # Iterate through the keystores and prompt for passwords
16
15
  while IFS= read -r ALLOWED_KEYSTORE; do
17
16
  # Skip empty lines
@@ -20,7 +19,7 @@ while IFS= read -r ALLOWED_KEYSTORE; do
20
19
  ALLOWED_KEYSTORE=$(echo "$ALLOWED_KEYSTORE" | sed 's/-/_/g')
21
20
  # Prompt the user to input a password for the current keystore
22
21
  PASSWORD_INPUT=$(systemd-ask-password "Input the password for keystore [$ALLOWED_KEYSTORE]: ")
23
-
22
+
24
23
  # Save the environment variable to a temporary file
25
24
  echo "export \"$ALLOWED_KEYSTORE\"=\"$PASSWORD_INPUT\"" >> "$ENV_FILE"
26
25
 
@@ -38,4 +37,8 @@ rm -f "$ENV_FILE"
38
37
  # Execute wative-ssh with the loaded environment variables
39
38
  TARGET_FILE=$(realpath "$(dirname "$(realpath "$0")")/../lib/wative-ssh.umd.js")
40
39
 
41
- "$(which node)" "$TARGET_FILE"
40
+ if [ "$1" == "--daemon" ]; then
41
+ /usr/local/bin/node "$TARGET_FILE" > /var/log/wative/wative-ssh.log 2>&1 &
42
+ else
43
+ /usr/local/bin/node "$TARGET_FILE"
44
+ fi
@@ -1 +1 @@
1
- import*as e from"path";import*as t from"fs";import{readFileSync as r}from"fs";import{utils as s,Server as n}from"ssh2";import{timingSafeEqual as a}from"crypto";import*as o from"ini";import{execSync as i}from"child_process";import"figlet";import"inquirer";import"web3";import"@solana/web3.js";import"@solana/spl-token";import"@metaplex-foundation/js";import"bignumber.js";import*as u from"log4js";import{ethers as c}from"ethers";function l(e,t,r,s){return new(r||(r=Promise))((function(n,a){function o(e){try{u(s.next(e))}catch(e){a(e)}}function i(e){try{u(s.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,i)}u((s=s.apply(e,t||[])).next())}))}function p(e,t){var r,s,n,a,o={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,i[0]&&(o=0)),o;)try{if(r=1,s&&(n=2&i[0]?s.return:i[0]?s.throw||((n=s.return)&&n.call(s),0):s.next)&&!(n=n.call(s,i[1])).done)return n;switch(s=0,n&&(i=[2&i[0],n.value]),i[0]){case 0:case 1:n=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,s=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!(n=o.trys,(n=n.length>0&&n[n.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!n||i[1]>n[0]&&i[1]<n[3])){o.label=i[1];break}if(6===i[0]&&o.label<n[1]){o.label=n[1],n=i;break}if(n&&o.label<n[2]){o.label=n[2],o.ops.push(i);break}n[2]&&o.ops.pop(),o.trys.pop();continue}i=t.call(e,o)}catch(e){i=[6,e],s=0}finally{r=n=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}"function"==typeof SuppressedError&&SuppressedError,require("chalk"),require("chalk"),require("chalk"),process.env.HOME||process.env.USERPROFILE;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 d=function(r){return l(void 0,void 0,void 0,(function(){var s,n,a,u,c,d,h;return p(this,(function(g){switch(g.label){case 0:return s="/etc/wative",t.existsSync(s)||t.mkdirSync(s),[4,l(void 0,void 0,void 0,(function(){var r,s,n,a,o;return p(this,(function(u){return r="/etc/wative",s=e.join(r,"id_rsa_server.pub"),n=e.join(r,"id_rsa_server"),t.existsSync(s)&&t.existsSync(n)||(console.log("Generating SSH key pair..."),i("ssh-keygen -t rsa -f ".concat(n," -N 'wative_server'"),{stdio:"inherit"})),a=e.join(r,"id_rsa_detake.pub"),o=e.join(r,"id_rsa_detake"),t.existsSync(a)&&t.existsSync(o)||(console.log("Generating SSH key pair..."),i("ssh-keygen -t rsa -f ".concat(o," -N 'wative_detake'"),{stdio:"inherit"})),[2]}))}))];case 1:return g.sent(),n=e.join(s,"config.ini"),t.existsSync(n)||(f=r,m=e.resolve(f,"network.json"),a=JSON.parse(t.readFileSync(m,"utf8")),u=a.accounts,c=function(e){for(var t=[],r=0;r<e.length;r++)t.push(e[r].trim().toLocaleLowerCase().replace(/\s+/g,"-").trim().replace(/\-+/g,"-").trim());return t}(u),d={keystore:{path:r,allowed_keystores:c},ssh:{listen:"127.0.0.1",port:5678}},h=o.stringify(d),t.writeFileSync(n,h)),[2,o.parse(t.readFileSync(n,"utf-8"))]}var f,m}))}))},h=require("wative-core").WativeCore,g=require("@solana/web3.js"),f=g.Connection,m=g.PublicKey,v=g.VersionedTransaction,y=g.VersionedMessage,w=require("bs58"),b=require("@solana/web3.js"),_=b.Keypair,S=b.TransactionMessage,k=b.ComputeBudgetInstruction,x=b.TransactionInstruction,P=b.ComputeBudgetProgram,I=require("@coral-xyz/anchor").Wallet,C=u.getLogger();C.level="info";var A=function(){function o(e,n,a,o,i,u,c,l){if(this._allowedAppIds=[],this._allowedPubKeys=[],this._allowedKeystoreIds=[],this._sessionIdAppIdMap={},function(e){if(e=e.trim(),!t.existsSync(e))throw new Error("File not exists")}(e),0===a.length||0===o.length||0===i.length||a.length!==o.length||a.length!==i.length)throw new Error("WativeWielderServer:: constructor: Invaild AllowedApp");for(var p=0;p<i.length;p++)for(var d=0;d<i[p].length;d++){var g=i[p][d];if(!c.includes(g))throw new Error("WativeWielderServer:: constructor: Invaild AllowedKeystoreIds")}for(var f=0,m=a;f<m.length;f++){var v=m[f];this._allowedAppIds.push(Buffer.from(v))}for(var y=0,w=o;y<w.length;y++){var b=w[y],_=s.parseKey(r(b));this._allowedPubKeys.push(_)}this.wativeCore=new h(u,c,l),this._idRsaPrivatePath=e,this._idRsaPassphrase=n,this._allowedKeystoreIds=i,this._keystoreDirectoryPath=u}return o.prototype.listen=function(e,t){var s=this;new n({hostKeys:[{key:r(this._idRsaPrivatePath),passphrase:this._idRsaPassphrase}]},(function(e){e.on("authentication",(function(t){var r=!0;if(s&&(s.checkValue(Buffer.from(t.username),"appId")||(r=!1)),"publickey"!==t.method||!r)return t.reject();var n=s.getBytesIndex(Buffer.from(t.username),s._allowedAppIds),a=s._allowedPubKeys[n];if(t.key.algo!==a.type||!s.checkValue(t.key.data,"publicKey")||t.signature&&!0!==a.verify(t.blob,t.signature,t.hashAlgo))return t.reject();if(r){var o=e._protocol._kex.sessionID.toString("hex");s._sessionIdAppIdMap[o]=Buffer.from(t.username),t.accept()}else t.reject()})).on("ready",(function(){e.on("session",(function(t,r){t().once("exec",(function(t,r,n){return l(s,void 0,void 0,(function(){var r,s,a;return p(this,(function(o){switch(o.label){case 0:return r=e._protocol._kex.sessionID.toString("hex"),[4,this.web3Request(r,n.command)];case 1:return s=o.sent(),(a=t())?(JSON.stringify(s)?(a.write(JSON.stringify(s)),a.exit(0),a.end()):(a.write("ssh2 connect error"),a.exit(0),a.end()),[2]):[2]}}))}))}))}))})).on("close",(function(){C.info("Client disconnected")})).on("error",(function(e){C.error("err: ",e.message)}))})).listen(t,e,(function(){C.info("Listening on port "+t)}))},o.prototype.web3Request=function(e,t){return l(this,void 0,void 0,(function(){var r,s,n,a,o,i,u,c,l,d,h,g,f,m,v;return p(this,(function(p){switch(p.label){case 0:return p.trys.push([0,34,,35]),r=this._sessionIdAppIdMap[e],(s=this.getBytesIndex(r,this._allowedAppIds))<0?[2,{status:!1,msg:"app not found"}]:(n=JSON.parse(t),C.info("sign message: ",t),a=n.method,o=n.keystoreId||n.params.keystoreId,i=n.chainId||n.params.chainId,this._allowedKeystoreIds[s].includes(o)?(u=void 0,"get_root_account"!==a?[3,1]:(u=this.getRootAccount(o,i),[3,33])):[2,{status:!1,msg:"keystore not allowed"}]);case 1:return"get_sub_account"!==a?[3,2]:(f=n.params,u=this.getSubAccount(o,f.chainId,null==f?void 0:f.startIndex,null==f?void 0:f.endIndex),[3,33]);case 2:if("sign"!==a)return[3,7];f=n.params,p.label=3;case 3:return p.trys.push([3,5,,6]),[4,this.wativeCore.account.signTransaction(f.txParams.from,f.txParams,f.rpcUrl)];case 4:return u=p.sent(),[3,6];case 5:return c=p.sent(),C.error("sign error: ",c.message),[2,{status:!1,msg:c.msg}];case 6:return[3,33];case 7:if("sign_and_send"!==a)return[3,12];f=n.params,p.label=8;case 8:return p.trys.push([8,10,,11]),[4,this.wativeCore.account.signAndSendTx(f.txParams,f.rpcUrl)];case 9:return l=p.sent(),u={transactionHash:l},[3,11];case 10:return[2,{status:!1,msg:p.sent().msg}];case 11:return[3,33];case 12:if("solana_sign"!==a)return[3,17];p.label=13;case 13:return p.trys.push([13,15,,16]),f=n.params,[4,this.signSolanaTransaction(f.txParams.from,f.txParams.data,f.txParams.lookup_tables,f.rpcUrl,f.priority_fee)];case 14:return u=p.sent(),[3,16];case 15:return d=p.sent(),C.error("sign error: ",d.message),[2,{status:!1,msg:d.msg}];case 16:return[3,33];case 17:if("solana_send"!==a)return[3,22];p.label=18;case 18:return p.trys.push([18,20,,21]),f=n.params,[4,this.sendSignedSolanaTransaction(f.txParams.from,f.txParams.signature,f.txParams.data,f.rpcUrl)];case 19:return u=p.sent(),[3,21];case 20:return h=p.sent(),C.error("sign error: ",h.message),[2,{status:!1,msg:h.msg}];case 21:return[3,33];case 22:if("sign_message"!==a)return[3,27];p.label=23;case 23:return p.trys.push([23,25,,26]),f=n.params,C.debug("sign message: ",f),[4,this.signMessage(f.account,f.message)];case 24:return u=p.sent(),[3,26];case 25:return g=p.sent(),C.error("sign error: ",g.message),[2,{status:!1,msg:g.msg}];case 26:return[3,33];case 27:if("sign_typed_data"!==a)return[3,32];p.label=28;case 28:return p.trys.push([28,30,,31]),f=n.params,C.debug("sign message: ",f),[4,this.signTypedData(f.account,f.domain,f.types_name,f.types,f.message)];case 29:return u=p.sent(),[3,31];case 30:return m=p.sent(),C.error("sign error: ",m.message),[2,{status:!1,msg:m.msg}];case 31:return[3,33];case 32:return[2,{status:!1,msg:"message method not find"}];case 33:return[2,{status:!0,data:u}];case 34:return v=p.sent(),C.error("sign error: ",v.message),[2,{status:!1,msg:v.msg}];case 35:return[2]}}))}))},o.prototype.checkValue=function(e,t){if("appId"!==t&&"publicKey"!==t)return!1;for(var r=this._allowedAppIds.length,s=0;s<r;s++){var n=void 0;n="appId"===t?this._allowedAppIds[s]:this._allowedPubKeys[s].getPublicSSH();var o=e.length!==n.length;o&&(n=e);var i=a(e,n);if(!o&&i)return!0}},o.prototype.getBytesIndex=function(e,t){for(var r=t.length,s=0;s<r;s++)if(e.length===t[s].length&&a(e,t[s]))return s;return-1},o.prototype.getRootAccount=function(t,s){var n=e.resolve(this._keystoreDirectoryPath,"accounts/".concat(t,".json")),a=r(n);return a=JSON.parse(a.toString()),[{id:0,address:"SOLANA"===this.getChainType(s)?a.data[0].ciphertexts.solana.address:a.data[0].ciphertexts.evm.address,children:a.data.length,type:"M"}]},o.prototype.getChainType=function(e){return"901"===e||"902"===e||"903"===e?"SOLANA":"EVM"},o.prototype.getSubAccount=function(t,s,n,a){var o=e.resolve(this._keystoreDirectoryPath,"accounts/".concat(t,".json")),i=r(o),u=(i=JSON.parse(i.toString())).data.length-1;a&&a<u&&(u=a);var c=0;if(n&&n>0&&(c=n),c>u)return[];for(var l=this.getChainType(s),p=[],d=c;d<=u;d++)p.push(i.data[d].ciphertexts[l.toLocaleLowerCase()].address);return p},o.prototype.signMessage=function(e,t){return l(this,void 0,void 0,(function(){var r;return p(this,(function(s){switch(s.label){case 0:return[4,this.wativeCore.account.signMessage(e,t)];case 1:return r=s.sent(),console.log(r),[2,r]}}))}))},o.prototype.signTypedData=function(e,t,r,s,n){return l(this,void 0,void 0,(function(){var a,o,i,u,l,d;return p(this,(function(p){switch(p.label){case 0:return console.log("111"),a=JSON.parse(t),o=JSON.parse(s),i=JSON.parse(n),console.log(a),console.log(o),console.log(i),u=this.wativeCore.account.showPrivateKey(e),[4,new c.Wallet(u).signTypedData(a,(d={},d[r]=o,d),i)];case 1:return l=p.sent(),console.log(l),[2,{status:!0,output:l}]}}))}))},o.prototype.signSolanaTransaction=function(e,t,r,s,n){return l(this,void 0,void 0,(function(){var a,o,i,u,c,l,d,h,g,b,k,x,C,A,j,q,B,K,L,N;return p(this,(function(p){switch(p.label){case 0:if(a=new f(s),o=[],!r)return[3,5];i=0,u=r,p.label=1;case 1:return i<u.length?(c=u[i],[4,a.getAddressLookupTable(new m(c))]):[3,5];case 2:return l=p.sent().value,o.push(l),[4,T(1e3)];case 3:p.sent(),p.label=4;case 4:return i++,[3,1];case 5:return d=y.deserialize(Uint8Array.from(Buffer.from(t,"hex"))),(h=S.decompile(d)).instructions.push(P.setComputeUnitLimit({units:2e6})),h.instructions.push(P.setComputeUnitPrice({microLamports:1e3})),d=h.compileToV0Message(o),g=d,[4,a.getLatestBlockhash()];case 6:return g.recentBlockhash=p.sent().blockhash,[4,T(3e3)];case 7:return p.sent(),b=new v(d),k=this.wativeCore.account.showPrivateKey(e),x=_.fromSecretKey(new Uint8Array(w.decode(k))),C=new I(x),[4,a.simulateTransaction(b)];case 8:if(!(A=p.sent())||!A.value||0===A.value.unitsConsumed||A.value.err)return[2,{status:!1,output:A.value.err}];if(j=h.instructions.length,q=Math.trunc(1.2*A.value.unitsConsumed),h.instructions[j-2]=P.setComputeUnitLimit({units:q}),n&&"null"!=n)return[3,12];p.label=9;case 9:return p.trys.push([9,11,,12]),[4,this.getPrioritizationFee(s)];case 10:return n=p.sent(),[3,12];case 11:return p.sent(),n=2e5,[3,12];case 12:return n<1e4&&(n=1e4),n>5e5&&(n=5e5),h.instructions[j-1]=P.setComputeUnitPrice({microLamports:n}),d=h.compileToV0Message(o),[4,T(1e3)];case 13:return p.sent(),B=d,[4,a.getLatestBlockhash()];case 14:return B.recentBlockhash=p.sent().blockhash,(b=new v(d)).feePayer=C.publicKey,[4,T(3e3)];case 15:return p.sent(),[4,this.wativeCore.account.signTransaction(e,b,s)];case 16:return K=p.sent(),L=new v(K.output.message,K.output.signatures),N=L.message.serialize(),N=Buffer.from(N).toString("hex"),[2,{status:!0,output:{transactionHash:w.encode(K.output.signatures[0]),message:N,compute_units:A.value.unitsConsumed.toString()}}]}}))}))},o.prototype.sendSignedSolanaTransaction=function(e,t,r,s){return l(this,void 0,void 0,(function(){var n,a,o;return p(this,(function(i){switch(i.label){case 0:return n=[w.decode(t)],a=y.deserialize(Uint8Array.from(Buffer.from(r,"hex"))),o=new v(a,n),[4,this.wativeCore.account.sendSignedTransaction(e,o,s)];case 1:return[2,i.sent()]}}))}))},o.prototype.getPrioritizationFee=function(e){return l(this,void 0,void 0,(function(){var t,r,s,n,a,o,i,u,c,l,d,h;return p(this,(function(p){switch(p.label){case 0:return t=new m("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"),[4,(r=new f(e,"confirmed")).getSignaturesForAddress(t,{limit:5})];case 1:return s=p.sent(),[4,T(2e3)];case 2:for(p.sent(),n=[],i=0;i<s.length;i++)n.push(s[i].signature);return[4,r.getParsedTransactions(n,{maxSupportedTransactionVersion:0})];case 3:for(a=p.sent(),o=0,i=0;i<a.length;i++)for(u=a[i].transaction.message.instructions,c=0;c<u.length;c++)if("ComputeBudget111111111111111111111111111111"===u[c].programId.toBase58()){l=u[c].data;try{d=new x({keys:[],programId:new m("ComputeBudget111111111111111111111111111111"),data:Buffer.from(w.decode(l))}),h=k.decodeSetComputeUnitPrice(d).microLamports,o+=Number(h);continue}catch(e){}}return[2,Math.ceil(o/5)]}}))}))},o}(),T=function(e){return new Promise((function(t){return setTimeout(t,e)}))};require("dotenv").config();var j=require("os");process.on("unhandledRejection",(function(e,t){console.log("Unhandled Rejection at:",t,"reason:",e)})),l(void 0,void 0,void 0,(function(){var t,r,s,n,a,o,i,u,c,h,g;return p(this,(function(f){switch(f.label){case 0:return t=j.homedir(),r=e.join(t,".wative"),[4,d(r)];case 1:return s=f.sent(),n=s.ssh.listen,a=s.ssh.port,o="/etc/wative/id_rsa_server",i="wative_server",u="detake",c="/etc/wative/id_rsa_detake.pub",h=s.keystore.allowed_keystores,[4,(m=h,l(void 0,void 0,void 0,(function(){var e,t,r;return p(this,(function(s){for(e=[],t=0;t<m.length;t++)r=m[t].replace(/-/g,"_"),e.push(process.env[r]);return[2,e]}))})))];case 2:return g=f.sent(),new A(o,i,[u],[c],[h],r,h,g).listen(n,a),[2]}var m}))}));
1
+ import*as e from"path";import*as t from"fs";import{readFileSync as r}from"fs";import{utils as s,Server as n}from"ssh2";import{timingSafeEqual as a}from"crypto";import*as o from"ini";import{execSync as i}from"child_process";import"figlet";import"inquirer";import"web3";import"@solana/web3.js";import"@solana/spl-token";import"@metaplex-foundation/js";import"bignumber.js";import*as u from"log4js";import{ethers as c}from"ethers";function l(e,t,r,s){return new(r||(r=Promise))((function(n,a){function o(e){try{u(s.next(e))}catch(e){a(e)}}function i(e){try{u(s.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,i)}u((s=s.apply(e,t||[])).next())}))}function p(e,t){var r,s,n,a,o={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,i[0]&&(o=0)),o;)try{if(r=1,s&&(n=2&i[0]?s.return:i[0]?s.throw||((n=s.return)&&n.call(s),0):s.next)&&!(n=n.call(s,i[1])).done)return n;switch(s=0,n&&(i=[2&i[0],n.value]),i[0]){case 0:case 1:n=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,s=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!(n=o.trys,(n=n.length>0&&n[n.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!n||i[1]>n[0]&&i[1]<n[3])){o.label=i[1];break}if(6===i[0]&&o.label<n[1]){o.label=n[1],n=i;break}if(n&&o.label<n[2]){o.label=n[2],o.ops.push(i);break}n[2]&&o.ops.pop(),o.trys.pop();continue}i=t.call(e,o)}catch(e){i=[6,e],s=0}finally{r=n=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}"function"==typeof SuppressedError&&SuppressedError,require("chalk"),require("chalk"),require("chalk"),process.env.HOME||process.env.USERPROFILE;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 d=function(r){return l(void 0,void 0,void 0,(function(){var s,n,a,u,c,d,h;return p(this,(function(f){switch(f.label){case 0:return s="/etc/wative",t.existsSync(s)||t.mkdirSync(s),[4,l(void 0,void 0,void 0,(function(){var r,s,n,a,o;return p(this,(function(u){return r="/etc/wative",s=e.join(r,"id_rsa_server.pub"),n=e.join(r,"id_rsa_server"),t.existsSync(s)&&t.existsSync(n)||(console.log("Generating SSH key pair..."),i("ssh-keygen -t rsa -f ".concat(n," -N 'wative_server'"),{stdio:"inherit"})),a=e.join(r,"id_rsa_detake.pub"),o=e.join(r,"id_rsa_detake"),t.existsSync(a)&&t.existsSync(o)||(console.log("Generating SSH key pair..."),i("ssh-keygen -t rsa -f ".concat(o," -N 'wative_detake'"),{stdio:"inherit"})),[2]}))}))];case 1:return f.sent(),n=e.join(s,"config.ini"),t.existsSync(n)||(g=r,m=e.resolve(g,"network.json"),a=JSON.parse(t.readFileSync(m,"utf8")),u=a.accounts,c=function(e){for(var t=[],r=0;r<e.length;r++)t.push(e[r].trim().toLocaleLowerCase().replace(/\s+/g,"-").trim().replace(/\-+/g,"-").trim());return t}(u),d={keystore:{path:r,allowed_keystores:c},ssh:{listen:"127.0.0.1",port:5678,log:{size:10485760,backups:3}}},h=o.stringify(d),t.writeFileSync(n,h)),[2,o.parse(t.readFileSync(n,"utf-8"))]}var g,m}))}))},h=require("wative-core").WativeCore,f=require("@solana/web3.js"),g=f.Connection,m=f.PublicKey,v=f.VersionedTransaction,y=f.VersionedMessage,w=require("bs58"),b=require("@solana/web3.js"),_=b.Keypair,S=b.TransactionMessage,k=b.ComputeBudgetInstruction,x=b.TransactionInstruction,P=b.ComputeBudgetProgram,I=require("@coral-xyz/anchor").Wallet;u.configure({appenders:{file:{type:"file",filename:"/var/log/wative/wative-ssh.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"}}});var C=u.getLogger("file");C.level="info";var A=function(){function o(e,n,a,o,i,u,c,l){if(this._allowedAppIds=[],this._allowedPubKeys=[],this._allowedKeystoreIds=[],this._sessionIdAppIdMap={},function(e){if(e=e.trim(),!t.existsSync(e))throw new Error("File not exists")}(e),0===a.length||0===o.length||0===i.length||a.length!==o.length||a.length!==i.length)throw new Error("WativeWielderServer:: constructor: Invaild AllowedApp");for(var p=0;p<i.length;p++)for(var d=0;d<i[p].length;d++){var f=i[p][d];if(!c.includes(f))throw new Error("WativeWielderServer:: constructor: Invaild AllowedKeystoreIds")}for(var g=0,m=a;g<m.length;g++){var v=m[g];this._allowedAppIds.push(Buffer.from(v))}for(var y=0,w=o;y<w.length;y++){var b=w[y],_=s.parseKey(r(b));this._allowedPubKeys.push(_)}this.wativeCore=new h(u,c,l),this._idRsaPrivatePath=e,this._idRsaPassphrase=n,this._allowedKeystoreIds=i,this._keystoreDirectoryPath=u}return o.prototype.listen=function(e,t){var s=this;new n({hostKeys:[{key:r(this._idRsaPrivatePath),passphrase:this._idRsaPassphrase}]},(function(e){e.on("authentication",(function(t){var r=!0;if(s&&(s.checkValue(Buffer.from(t.username),"appId")||(r=!1)),"publickey"!==t.method||!r)return t.reject();var n=s.getBytesIndex(Buffer.from(t.username),s._allowedAppIds),a=s._allowedPubKeys[n];if(t.key.algo!==a.type||!s.checkValue(t.key.data,"publicKey")||t.signature&&!0!==a.verify(t.blob,t.signature,t.hashAlgo))return t.reject();if(r){var o=e._protocol._kex.sessionID.toString("hex");s._sessionIdAppIdMap[o]=Buffer.from(t.username),t.accept()}else t.reject()})).on("ready",(function(){e.on("session",(function(t,r){t().once("exec",(function(t,r,n){return l(s,void 0,void 0,(function(){var r,s,a;return p(this,(function(o){switch(o.label){case 0:return r=e._protocol._kex.sessionID.toString("hex"),[4,this.web3Request(r,n.command)];case 1:return s=o.sent(),(a=t())?(JSON.stringify(s)?(a.write(JSON.stringify(s)),a.exit(0),a.end()):(a.write("ssh2 connect error"),a.exit(0),a.end()),[2]):[2]}}))}))}))}))})).on("close",(function(){C.info("Client disconnected")})).on("error",(function(e){C.error("err: ",e.message)}))})).listen(t,e,(function(){C.info("Listening on port "+t)}))},o.prototype.web3Request=function(e,t){return l(this,void 0,void 0,(function(){var r,s,n,a,o,i,u,c,l,d,h,f,g,m,v;return p(this,(function(p){switch(p.label){case 0:return p.trys.push([0,34,,35]),r=this._sessionIdAppIdMap[e],(s=this.getBytesIndex(r,this._allowedAppIds))<0?[2,{status:!1,msg:"app not found"}]:(n=JSON.parse(t),C.info("sign message: ",t),a=n.method,o=n.keystoreId||n.params.keystoreId,i=n.chainId||n.params.chainId,this._allowedKeystoreIds[s].includes(o)?(u=void 0,"get_root_account"!==a?[3,1]:(u=this.getRootAccount(o,i),[3,33])):[2,{status:!1,msg:"keystore not allowed"}]);case 1:return"get_sub_account"!==a?[3,2]:(g=n.params,u=this.getSubAccount(o,g.chainId,null==g?void 0:g.startIndex,null==g?void 0:g.endIndex),[3,33]);case 2:if("sign"!==a)return[3,7];g=n.params,p.label=3;case 3:return p.trys.push([3,5,,6]),[4,this.wativeCore.account.signTransaction(g.txParams.from,g.txParams,g.rpcUrl)];case 4:return u=p.sent(),[3,6];case 5:return c=p.sent(),C.error("sign error: ",c.message),[2,{status:!1,msg:c.msg}];case 6:return[3,33];case 7:if("sign_and_send"!==a)return[3,12];g=n.params,p.label=8;case 8:return p.trys.push([8,10,,11]),[4,this.wativeCore.account.signAndSendTx(g.txParams,g.rpcUrl)];case 9:return l=p.sent(),u={transactionHash:l},[3,11];case 10:return[2,{status:!1,msg:p.sent().msg}];case 11:return[3,33];case 12:if("solana_sign"!==a)return[3,17];p.label=13;case 13:return p.trys.push([13,15,,16]),g=n.params,[4,this.signSolanaTransaction(g.txParams.from,g.txParams.data,g.txParams.lookup_tables,g.rpcUrl,g.priority_fee)];case 14:return u=p.sent(),[3,16];case 15:return d=p.sent(),C.error("sign error: ",d.message),[2,{status:!1,msg:d.msg}];case 16:return[3,33];case 17:if("solana_send"!==a)return[3,22];p.label=18;case 18:return p.trys.push([18,20,,21]),g=n.params,[4,this.sendSignedSolanaTransaction(g.txParams.from,g.txParams.signature,g.txParams.data,g.rpcUrl)];case 19:return u=p.sent(),[3,21];case 20:return h=p.sent(),C.error("sign error: ",h.message),[2,{status:!1,msg:h.msg}];case 21:return[3,33];case 22:if("sign_message"!==a)return[3,27];p.label=23;case 23:return p.trys.push([23,25,,26]),g=n.params,C.debug("sign message: ",g),[4,this.signMessage(g.account,g.message)];case 24:return u=p.sent(),[3,26];case 25:return f=p.sent(),C.error("sign error: ",f.message),[2,{status:!1,msg:f.msg}];case 26:return[3,33];case 27:if("sign_typed_data"!==a)return[3,32];p.label=28;case 28:return p.trys.push([28,30,,31]),g=n.params,C.debug("sign message: ",g),[4,this.signTypedData(g.account,g.domain,g.types_name,g.types,g.message)];case 29:return u=p.sent(),[3,31];case 30:return m=p.sent(),C.error("sign error: ",m.message),[2,{status:!1,msg:m.msg}];case 31:return[3,33];case 32:return[2,{status:!1,msg:"message method not find"}];case 33:return[2,{status:!0,data:u}];case 34:return v=p.sent(),C.error("sign error: ",v.message),[2,{status:!1,msg:v.msg}];case 35:return[2]}}))}))},o.prototype.checkValue=function(e,t){if("appId"!==t&&"publicKey"!==t)return!1;for(var r=this._allowedAppIds.length,s=0;s<r;s++){var n=void 0;n="appId"===t?this._allowedAppIds[s]:this._allowedPubKeys[s].getPublicSSH();var o=e.length!==n.length;o&&(n=e);var i=a(e,n);if(!o&&i)return!0}},o.prototype.getBytesIndex=function(e,t){for(var r=t.length,s=0;s<r;s++)if(e.length===t[s].length&&a(e,t[s]))return s;return-1},o.prototype.getRootAccount=function(t,s){var n=e.resolve(this._keystoreDirectoryPath,"accounts/".concat(t,".json")),a=r(n);return a=JSON.parse(a.toString()),[{id:0,address:"SOLANA"===this.getChainType(s)?a.data[0].ciphertexts.solana.address:a.data[0].ciphertexts.evm.address,children:a.data.length,type:"M"}]},o.prototype.getChainType=function(e){return"901"===e||"902"===e||"903"===e?"SOLANA":"EVM"},o.prototype.getSubAccount=function(t,s,n,a){var o=e.resolve(this._keystoreDirectoryPath,"accounts/".concat(t,".json")),i=r(o),u=(i=JSON.parse(i.toString())).data.length-1;a&&a<u&&(u=a);var c=0;if(n&&n>0&&(c=n),c>u)return[];for(var l=this.getChainType(s),p=[],d=c;d<=u;d++)p.push(i.data[d].ciphertexts[l.toLocaleLowerCase()].address);return p},o.prototype.signMessage=function(e,t){return l(this,void 0,void 0,(function(){var r;return p(this,(function(s){switch(s.label){case 0:return[4,this.wativeCore.account.signMessage(e,t)];case 1:return r=s.sent(),console.log(r),[2,r]}}))}))},o.prototype.signTypedData=function(e,t,r,s,n){return l(this,void 0,void 0,(function(){var a,o,i,u,l,d;return p(this,(function(p){switch(p.label){case 0:return console.log("111"),a=JSON.parse(t),o=JSON.parse(s),i=JSON.parse(n),console.log(a),console.log(o),console.log(i),u=this.wativeCore.account.showPrivateKey(e),[4,new c.Wallet(u).signTypedData(a,(d={},d[r]=o,d),i)];case 1:return l=p.sent(),console.log(l),[2,{status:!0,output:l}]}}))}))},o.prototype.signSolanaTransaction=function(e,t,r,s,n){return l(this,void 0,void 0,(function(){var a,o,i,u,c,l,d,h,f,b,k,x,C,A,j,q,B,K,L,N;return p(this,(function(p){switch(p.label){case 0:if(a=new g(s),o=[],!r)return[3,5];i=0,u=r,p.label=1;case 1:return i<u.length?(c=u[i],[4,a.getAddressLookupTable(new m(c))]):[3,5];case 2:return l=p.sent().value,o.push(l),[4,T(1e3)];case 3:p.sent(),p.label=4;case 4:return i++,[3,1];case 5:return d=y.deserialize(Uint8Array.from(Buffer.from(t,"hex"))),(h=S.decompile(d)).instructions.push(P.setComputeUnitLimit({units:2e6})),h.instructions.push(P.setComputeUnitPrice({microLamports:1e3})),d=h.compileToV0Message(o),f=d,[4,a.getLatestBlockhash()];case 6:return f.recentBlockhash=p.sent().blockhash,[4,T(3e3)];case 7:return p.sent(),b=new v(d),k=this.wativeCore.account.showPrivateKey(e),x=_.fromSecretKey(new Uint8Array(w.decode(k))),C=new I(x),[4,a.simulateTransaction(b)];case 8:if(!(A=p.sent())||!A.value||0===A.value.unitsConsumed||A.value.err)return[2,{status:!1,output:A.value.err}];if(j=h.instructions.length,q=Math.trunc(1.2*A.value.unitsConsumed),h.instructions[j-2]=P.setComputeUnitLimit({units:q}),n&&"null"!=n)return[3,12];p.label=9;case 9:return p.trys.push([9,11,,12]),[4,this.getPrioritizationFee(s)];case 10:return n=p.sent(),[3,12];case 11:return p.sent(),n=2e5,[3,12];case 12:return n<1e4&&(n=1e4),n>5e5&&(n=5e5),h.instructions[j-1]=P.setComputeUnitPrice({microLamports:n}),d=h.compileToV0Message(o),[4,T(1e3)];case 13:return p.sent(),B=d,[4,a.getLatestBlockhash()];case 14:return B.recentBlockhash=p.sent().blockhash,(b=new v(d)).feePayer=C.publicKey,[4,T(3e3)];case 15:return p.sent(),[4,this.wativeCore.account.signTransaction(e,b,s)];case 16:return K=p.sent(),L=new v(K.output.message,K.output.signatures),N=L.message.serialize(),N=Buffer.from(N).toString("hex"),[2,{status:!0,output:{transactionHash:w.encode(K.output.signatures[0]),message:N,compute_units:A.value.unitsConsumed.toString()}}]}}))}))},o.prototype.sendSignedSolanaTransaction=function(e,t,r,s){return l(this,void 0,void 0,(function(){var n,a,o;return p(this,(function(i){switch(i.label){case 0:return n=[w.decode(t)],a=y.deserialize(Uint8Array.from(Buffer.from(r,"hex"))),o=new v(a,n),[4,this.wativeCore.account.sendSignedTransaction(e,o,s)];case 1:return[2,i.sent()]}}))}))},o.prototype.getPrioritizationFee=function(e){return l(this,void 0,void 0,(function(){var t,r,s,n,a,o,i,u,c,l,d,h;return p(this,(function(p){switch(p.label){case 0:return t=new m("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"),[4,(r=new g(e,"confirmed")).getSignaturesForAddress(t,{limit:5})];case 1:return s=p.sent(),[4,T(2e3)];case 2:for(p.sent(),n=[],i=0;i<s.length;i++)n.push(s[i].signature);return[4,r.getParsedTransactions(n,{maxSupportedTransactionVersion:0})];case 3:for(a=p.sent(),o=0,i=0;i<a.length;i++)for(u=a[i].transaction.message.instructions,c=0;c<u.length;c++)if("ComputeBudget111111111111111111111111111111"===u[c].programId.toBase58()){l=u[c].data;try{d=new x({keys:[],programId:new m("ComputeBudget111111111111111111111111111111"),data:Buffer.from(w.decode(l))}),h=k.decodeSetComputeUnitPrice(d).microLamports,o+=Number(h);continue}catch(e){}}return[2,Math.ceil(o/5)]}}))}))},o}(),T=function(e){return new Promise((function(t){return setTimeout(t,e)}))};require("dotenv").config();var j=require("os");process.on("unhandledRejection",(function(e,t){console.log("Unhandled Rejection at:",t,"reason:",e)})),l(void 0,void 0,void 0,(function(){var t,r,s,n,a,o,i,u,c,h,f;return p(this,(function(g){switch(g.label){case 0:return t=j.homedir(),r=e.join(t,".wative"),[4,d(r)];case 1:return s=g.sent(),n=s.ssh.listen,a=s.ssh.port,o="/etc/wative/id_rsa_server",i="wative_server",u="detake",c="/etc/wative/id_rsa_detake.pub",h=s.keystore.allowed_keystores,[4,(m=h,l(void 0,void 0,void 0,(function(){var e,t,r;return p(this,(function(s){for(e=[],t=0;t<m.length;t++)r=m[t].replace(/-/g,"_"),e.push(process.env[r]);return[2,e]}))})))];case 2:return f=g.sent(),new A(o,i,[u],[c],[h],r,h,f).listen(n,a),[2]}var m}))}));
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("path"),require("fs"),require("ssh2"),require("crypto"),require("ini"),require("child_process"),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")):"function"==typeof define&&define.amd?define(["path","fs","ssh2","crypto","ini","child_process","figlet","inquirer","web3","@solana/web3.js","@solana/spl-token","@metaplex-foundation/js","bignumber.js","log4js","ethers"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).path,e.fs,e.ssh2,e.crypto,e.ini,e.child_process,null,null,null,null,null,null,null,e.log4js,e.ethers)}(this,(function(e,t,r,n,s,a,i,o,u,c,l,d,h,p,f){"use strict";function g(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 v=g(e),m=g(t),y=g(s),w=g(p);function b(e,t,r,n){return new(r||(r=Promise))((function(s,a){function i(e){try{u(n.next(e))}catch(e){a(e)}}function o(e){try{u(n.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,o)}u((n=n.apply(e,t||[])).next())}))}function S(e,t){var r,n,s,a,i={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return a={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function o(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,o[0]&&(i=0)),i;)try{if(r=1,n&&(s=2&o[0]?n.return:o[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,o[1])).done)return s;switch(n=0,s&&(o=[2&o[0],s.value]),o[0]){case 0:case 1:s=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,n=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(s=i.trys,(s=s.length>0&&s[s.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!s||o[1]>s[0]&&o[1]<s[3])){i.label=o[1];break}if(6===o[0]&&i.label<s[1]){i.label=s[1],s=o;break}if(s&&i.label<s[2]){i.label=s[2],i.ops.push(o);break}s[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],n=0}finally{r=s=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}"function"==typeof SuppressedError&&SuppressedError,require("chalk"),require("chalk"),require("chalk"),process.env.HOME||process.env.USERPROFILE;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 _=function(e){return b(void 0,void 0,void 0,(function(){var t,r,n,s,i,o,u;return S(this,(function(c){switch(c.label){case 0:return t="/etc/wative",m.existsSync(t)||m.mkdirSync(t),[4,b(void 0,void 0,void 0,(function(){var e,t,r,n,s;return S(this,(function(i){return e="/etc/wative",t=v.join(e,"id_rsa_server.pub"),r=v.join(e,"id_rsa_server"),m.existsSync(t)&&m.existsSync(r)||(console.log("Generating SSH key pair..."),a.execSync("ssh-keygen -t rsa -f ".concat(r," -N 'wative_server'"),{stdio:"inherit"})),n=v.join(e,"id_rsa_detake.pub"),s=v.join(e,"id_rsa_detake"),m.existsSync(n)&&m.existsSync(s)||(console.log("Generating SSH key pair..."),a.execSync("ssh-keygen -t rsa -f ".concat(s," -N 'wative_detake'"),{stdio:"inherit"})),[2]}))}))];case 1:return c.sent(),r=v.join(t,"config.ini"),m.existsSync(r)||(l=e,d=v.resolve(l,"network.json"),n=JSON.parse(m.readFileSync(d,"utf8")),s=n.accounts,i=function(e){for(var t=[],r=0;r<e.length;r++)t.push(e[r].trim().toLocaleLowerCase().replace(/\s+/g,"-").trim().replace(/\-+/g,"-").trim());return t}(s),o={keystore:{path:e,allowed_keystores:i},ssh:{listen:"127.0.0.1",port:5678}},u=y.stringify(o),m.writeFileSync(r,u)),[2,y.parse(m.readFileSync(r,"utf-8"))]}var l,d}))}))},k=require("wative-core").WativeCore,x=require("@solana/web3.js"),P=x.Connection,q=x.PublicKey,I=x.VersionedTransaction,j=x.VersionedMessage,C=require("bs58"),T=require("@solana/web3.js"),A=T.Keypair,B=T.TransactionMessage,K=T.ComputeBudgetInstruction,L=T.TransactionInstruction,O=T.ComputeBudgetProgram,N=require("@coral-xyz/anchor").Wallet,M=w.getLogger();M.level="info";var U=function(){function e(e,n,s,a,i,o,u,c){if(this._allowedAppIds=[],this._allowedPubKeys=[],this._allowedKeystoreIds=[],this._sessionIdAppIdMap={},function(e){if(e=e.trim(),!m.existsSync(e))throw new Error("File not exists")}(e),0===s.length||0===a.length||0===i.length||s.length!==a.length||s.length!==i.length)throw new Error("WativeWielderServer:: constructor: Invaild AllowedApp");for(var l=0;l<i.length;l++)for(var d=0;d<i[l].length;d++){var h=i[l][d];if(!u.includes(h))throw new Error("WativeWielderServer:: constructor: Invaild AllowedKeystoreIds")}for(var p=0,f=s;p<f.length;p++){var g=f[p];this._allowedAppIds.push(Buffer.from(g))}for(var v=0,y=a;v<y.length;v++){var w=y[v],b=r.utils.parseKey(t.readFileSync(w));this._allowedPubKeys.push(b)}this.wativeCore=new k(o,u,c),this._idRsaPrivatePath=e,this._idRsaPassphrase=n,this._allowedKeystoreIds=i,this._keystoreDirectoryPath=o}return e.prototype.listen=function(e,n){var s=this;new r.Server({hostKeys:[{key:t.readFileSync(this._idRsaPrivatePath),passphrase:this._idRsaPassphrase}]},(function(e){e.on("authentication",(function(t){var r=!0;if(s&&(s.checkValue(Buffer.from(t.username),"appId")||(r=!1)),"publickey"!==t.method||!r)return t.reject();var n=s.getBytesIndex(Buffer.from(t.username),s._allowedAppIds),a=s._allowedPubKeys[n];if(t.key.algo!==a.type||!s.checkValue(t.key.data,"publicKey")||t.signature&&!0!==a.verify(t.blob,t.signature,t.hashAlgo))return t.reject();if(r){var i=e._protocol._kex.sessionID.toString("hex");s._sessionIdAppIdMap[i]=Buffer.from(t.username),t.accept()}else t.reject()})).on("ready",(function(){e.on("session",(function(t,r){t().once("exec",(function(t,r,n){return b(s,void 0,void 0,(function(){var r,s,a;return S(this,(function(i){switch(i.label){case 0:return r=e._protocol._kex.sessionID.toString("hex"),[4,this.web3Request(r,n.command)];case 1:return s=i.sent(),(a=t())?(JSON.stringify(s)?(a.write(JSON.stringify(s)),a.exit(0),a.end()):(a.write("ssh2 connect error"),a.exit(0),a.end()),[2]):[2]}}))}))}))}))})).on("close",(function(){M.info("Client disconnected")})).on("error",(function(e){M.error("err: ",e.message)}))})).listen(n,e,(function(){M.info("Listening on port "+n)}))},e.prototype.web3Request=function(e,t){return b(this,void 0,void 0,(function(){var r,n,s,a,i,o,u,c,l,d,h,p,f,g,v;return S(this,(function(m){switch(m.label){case 0:return m.trys.push([0,34,,35]),r=this._sessionIdAppIdMap[e],(n=this.getBytesIndex(r,this._allowedAppIds))<0?[2,{status:!1,msg:"app not found"}]:(s=JSON.parse(t),M.info("sign message: ",t),a=s.method,i=s.keystoreId||s.params.keystoreId,o=s.chainId||s.params.chainId,this._allowedKeystoreIds[n].includes(i)?(u=void 0,"get_root_account"!==a?[3,1]:(u=this.getRootAccount(i,o),[3,33])):[2,{status:!1,msg:"keystore not allowed"}]);case 1:return"get_sub_account"!==a?[3,2]:(f=s.params,u=this.getSubAccount(i,f.chainId,null==f?void 0:f.startIndex,null==f?void 0:f.endIndex),[3,33]);case 2:if("sign"!==a)return[3,7];f=s.params,m.label=3;case 3:return m.trys.push([3,5,,6]),[4,this.wativeCore.account.signTransaction(f.txParams.from,f.txParams,f.rpcUrl)];case 4:return u=m.sent(),[3,6];case 5:return c=m.sent(),M.error("sign error: ",c.message),[2,{status:!1,msg:c.msg}];case 6:return[3,33];case 7:if("sign_and_send"!==a)return[3,12];f=s.params,m.label=8;case 8:return m.trys.push([8,10,,11]),[4,this.wativeCore.account.signAndSendTx(f.txParams,f.rpcUrl)];case 9:return l=m.sent(),u={transactionHash:l},[3,11];case 10:return[2,{status:!1,msg:m.sent().msg}];case 11:return[3,33];case 12:if("solana_sign"!==a)return[3,17];m.label=13;case 13:return m.trys.push([13,15,,16]),f=s.params,[4,this.signSolanaTransaction(f.txParams.from,f.txParams.data,f.txParams.lookup_tables,f.rpcUrl,f.priority_fee)];case 14:return u=m.sent(),[3,16];case 15:return d=m.sent(),M.error("sign error: ",d.message),[2,{status:!1,msg:d.msg}];case 16:return[3,33];case 17:if("solana_send"!==a)return[3,22];m.label=18;case 18:return m.trys.push([18,20,,21]),f=s.params,[4,this.sendSignedSolanaTransaction(f.txParams.from,f.txParams.signature,f.txParams.data,f.rpcUrl)];case 19:return u=m.sent(),[3,21];case 20:return h=m.sent(),M.error("sign error: ",h.message),[2,{status:!1,msg:h.msg}];case 21:return[3,33];case 22:if("sign_message"!==a)return[3,27];m.label=23;case 23:return m.trys.push([23,25,,26]),f=s.params,M.debug("sign message: ",f),[4,this.signMessage(f.account,f.message)];case 24:return u=m.sent(),[3,26];case 25:return p=m.sent(),M.error("sign error: ",p.message),[2,{status:!1,msg:p.msg}];case 26:return[3,33];case 27:if("sign_typed_data"!==a)return[3,32];m.label=28;case 28:return m.trys.push([28,30,,31]),f=s.params,M.debug("sign message: ",f),[4,this.signTypedData(f.account,f.domain,f.types_name,f.types,f.message)];case 29:return u=m.sent(),[3,31];case 30:return g=m.sent(),M.error("sign error: ",g.message),[2,{status:!1,msg:g.msg}];case 31:return[3,33];case 32:return[2,{status:!1,msg:"message method not find"}];case 33:return[2,{status:!0,data:u}];case 34:return v=m.sent(),M.error("sign error: ",v.message),[2,{status:!1,msg:v.msg}];case 35:return[2]}}))}))},e.prototype.checkValue=function(e,t){if("appId"!==t&&"publicKey"!==t)return!1;for(var r=this._allowedAppIds.length,s=0;s<r;s++){var a=void 0;a="appId"===t?this._allowedAppIds[s]:this._allowedPubKeys[s].getPublicSSH();var i=e.length!==a.length;i&&(a=e);var o=n.timingSafeEqual(e,a);if(!i&&o)return!0}},e.prototype.getBytesIndex=function(e,t){for(var r=t.length,s=0;s<r;s++)if(e.length===t[s].length&&n.timingSafeEqual(e,t[s]))return s;return-1},e.prototype.getRootAccount=function(e,r){var n=v.resolve(this._keystoreDirectoryPath,"accounts/".concat(e,".json")),s=t.readFileSync(n);return s=JSON.parse(s.toString()),[{id:0,address:"SOLANA"===this.getChainType(r)?s.data[0].ciphertexts.solana.address:s.data[0].ciphertexts.evm.address,children:s.data.length,type:"M"}]},e.prototype.getChainType=function(e){return"901"===e||"902"===e||"903"===e?"SOLANA":"EVM"},e.prototype.getSubAccount=function(e,r,n,s){var a=v.resolve(this._keystoreDirectoryPath,"accounts/".concat(e,".json")),i=t.readFileSync(a),o=(i=JSON.parse(i.toString())).data.length-1;s&&s<o&&(o=s);var u=0;if(n&&n>0&&(u=n),u>o)return[];for(var c=this.getChainType(r),l=[],d=u;d<=o;d++)l.push(i.data[d].ciphertexts[c.toLocaleLowerCase()].address);return l},e.prototype.signMessage=function(e,t){return b(this,void 0,void 0,(function(){var r;return S(this,(function(n){switch(n.label){case 0:return[4,this.wativeCore.account.signMessage(e,t)];case 1:return r=n.sent(),console.log(r),[2,r]}}))}))},e.prototype.signTypedData=function(e,t,r,n,s){return b(this,void 0,void 0,(function(){var a,i,o,u,c,l;return S(this,(function(d){switch(d.label){case 0:return console.log("111"),a=JSON.parse(t),i=JSON.parse(n),o=JSON.parse(s),console.log(a),console.log(i),console.log(o),u=this.wativeCore.account.showPrivateKey(e),[4,new f.ethers.Wallet(u).signTypedData(a,(l={},l[r]=i,l),o)];case 1:return c=d.sent(),console.log(c),[2,{status:!0,output:c}]}}))}))},e.prototype.signSolanaTransaction=function(e,t,r,n,s){return b(this,void 0,void 0,(function(){var a,i,o,u,c,l,d,h,p,f,g,v,m,y,w,b,_,k,x,T;return S(this,(function(S){switch(S.label){case 0:if(a=new P(n),i=[],!r)return[3,5];o=0,u=r,S.label=1;case 1:return o<u.length?(c=u[o],[4,a.getAddressLookupTable(new q(c))]):[3,5];case 2:return l=S.sent().value,i.push(l),[4,E(1e3)];case 3:S.sent(),S.label=4;case 4:return o++,[3,1];case 5:return d=j.deserialize(Uint8Array.from(Buffer.from(t,"hex"))),(h=B.decompile(d)).instructions.push(O.setComputeUnitLimit({units:2e6})),h.instructions.push(O.setComputeUnitPrice({microLamports:1e3})),d=h.compileToV0Message(i),p=d,[4,a.getLatestBlockhash()];case 6:return p.recentBlockhash=S.sent().blockhash,[4,E(3e3)];case 7:return S.sent(),f=new I(d),g=this.wativeCore.account.showPrivateKey(e),v=A.fromSecretKey(new Uint8Array(C.decode(g))),m=new N(v),[4,a.simulateTransaction(f)];case 8:if(!(y=S.sent())||!y.value||0===y.value.unitsConsumed||y.value.err)return[2,{status:!1,output:y.value.err}];if(w=h.instructions.length,b=Math.trunc(1.2*y.value.unitsConsumed),h.instructions[w-2]=O.setComputeUnitLimit({units:b}),s&&"null"!=s)return[3,12];S.label=9;case 9:return S.trys.push([9,11,,12]),[4,this.getPrioritizationFee(n)];case 10:return s=S.sent(),[3,12];case 11:return S.sent(),s=2e5,[3,12];case 12:return s<1e4&&(s=1e4),s>5e5&&(s=5e5),h.instructions[w-1]=O.setComputeUnitPrice({microLamports:s}),d=h.compileToV0Message(i),[4,E(1e3)];case 13:return S.sent(),_=d,[4,a.getLatestBlockhash()];case 14:return _.recentBlockhash=S.sent().blockhash,(f=new I(d)).feePayer=m.publicKey,[4,E(3e3)];case 15:return S.sent(),[4,this.wativeCore.account.signTransaction(e,f,n)];case 16:return k=S.sent(),x=new I(k.output.message,k.output.signatures),T=x.message.serialize(),T=Buffer.from(T).toString("hex"),[2,{status:!0,output:{transactionHash:C.encode(k.output.signatures[0]),message:T,compute_units:y.value.unitsConsumed.toString()}}]}}))}))},e.prototype.sendSignedSolanaTransaction=function(e,t,r,n){return b(this,void 0,void 0,(function(){var s,a,i;return S(this,(function(o){switch(o.label){case 0:return s=[C.decode(t)],a=j.deserialize(Uint8Array.from(Buffer.from(r,"hex"))),i=new I(a,s),[4,this.wativeCore.account.sendSignedTransaction(e,i,n)];case 1:return[2,o.sent()]}}))}))},e.prototype.getPrioritizationFee=function(e){return b(this,void 0,void 0,(function(){var t,r,n,s,a,i,o,u,c,l,d,h;return S(this,(function(p){switch(p.label){case 0:return t=new q("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"),[4,(r=new P(e,"confirmed")).getSignaturesForAddress(t,{limit:5})];case 1:return n=p.sent(),[4,E(2e3)];case 2:for(p.sent(),s=[],o=0;o<n.length;o++)s.push(n[o].signature);return[4,r.getParsedTransactions(s,{maxSupportedTransactionVersion:0})];case 3:for(a=p.sent(),i=0,o=0;o<a.length;o++)for(u=a[o].transaction.message.instructions,c=0;c<u.length;c++)if("ComputeBudget111111111111111111111111111111"===u[c].programId.toBase58()){l=u[c].data;try{d=new L({keys:[],programId:new q("ComputeBudget111111111111111111111111111111"),data:Buffer.from(C.decode(l))}),h=K.decodeSetComputeUnitPrice(d).microLamports,i+=Number(h);continue}catch(e){}}return[2,Math.ceil(i/5)]}}))}))},e}(),E=function(e){return new Promise((function(t){return setTimeout(t,e)}))};require("dotenv").config();var F=require("os");process.on("unhandledRejection",(function(e,t){console.log("Unhandled Rejection at:",t,"reason:",e)})),b(void 0,void 0,void 0,(function(){var e,t,r,n,s,a,i,o,u,c,l;return S(this,(function(d){switch(d.label){case 0:return e=F.homedir(),t=v.join(e,".wative"),[4,_(t)];case 1:return r=d.sent(),n=r.ssh.listen,s=r.ssh.port,a="/etc/wative/id_rsa_server",i="wative_server",o="detake",u="/etc/wative/id_rsa_detake.pub",c=r.keystore.allowed_keystores,[4,(h=c,b(void 0,void 0,void 0,(function(){var e,t,r;return S(this,(function(n){for(e=[],t=0;t<h.length;t++)r=h[t].replace(/-/g,"_"),e.push(process.env[r]);return[2,e]}))})))];case 2:return l=d.sent(),new U(a,i,[o],[u],[c],t,c,l).listen(n,s),[2]}var h}))}))}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("path"),require("fs"),require("ssh2"),require("crypto"),require("ini"),require("child_process"),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")):"function"==typeof define&&define.amd?define(["path","fs","ssh2","crypto","ini","child_process","figlet","inquirer","web3","@solana/web3.js","@solana/spl-token","@metaplex-foundation/js","bignumber.js","log4js","ethers"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).path,e.fs,e.ssh2,e.crypto,e.ini,e.child_process,null,null,null,null,null,null,null,e.log4js,e.ethers)}(this,(function(e,t,r,n,s,a,i,o,u,c,l,d,p,h,f){"use strict";function g(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 m=g(e),v=g(t),y=g(s),w=g(h);function b(e,t,r,n){return new(r||(r=Promise))((function(s,a){function i(e){try{u(n.next(e))}catch(e){a(e)}}function o(e){try{u(n.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,o)}u((n=n.apply(e,t||[])).next())}))}function S(e,t){var r,n,s,a,i={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return a={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function o(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,o[0]&&(i=0)),i;)try{if(r=1,n&&(s=2&o[0]?n.return:o[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,o[1])).done)return s;switch(n=0,s&&(o=[2&o[0],s.value]),o[0]){case 0:case 1:s=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,n=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(s=i.trys,(s=s.length>0&&s[s.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!s||o[1]>s[0]&&o[1]<s[3])){i.label=o[1];break}if(6===o[0]&&i.label<s[1]){i.label=s[1],s=o;break}if(s&&i.label<s[2]){i.label=s[2],i.ops.push(o);break}s[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],n=0}finally{r=s=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}"function"==typeof SuppressedError&&SuppressedError,require("chalk"),require("chalk"),require("chalk"),process.env.HOME||process.env.USERPROFILE;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 _=function(e){return b(void 0,void 0,void 0,(function(){var t,r,n,s,i,o,u;return S(this,(function(c){switch(c.label){case 0:return t="/etc/wative",v.existsSync(t)||v.mkdirSync(t),[4,b(void 0,void 0,void 0,(function(){var e,t,r,n,s;return S(this,(function(i){return e="/etc/wative",t=m.join(e,"id_rsa_server.pub"),r=m.join(e,"id_rsa_server"),v.existsSync(t)&&v.existsSync(r)||(console.log("Generating SSH key pair..."),a.execSync("ssh-keygen -t rsa -f ".concat(r," -N 'wative_server'"),{stdio:"inherit"})),n=m.join(e,"id_rsa_detake.pub"),s=m.join(e,"id_rsa_detake"),v.existsSync(n)&&v.existsSync(s)||(console.log("Generating SSH key pair..."),a.execSync("ssh-keygen -t rsa -f ".concat(s," -N 'wative_detake'"),{stdio:"inherit"})),[2]}))}))];case 1:return c.sent(),r=m.join(t,"config.ini"),v.existsSync(r)||(l=e,d=m.resolve(l,"network.json"),n=JSON.parse(v.readFileSync(d,"utf8")),s=n.accounts,i=function(e){for(var t=[],r=0;r<e.length;r++)t.push(e[r].trim().toLocaleLowerCase().replace(/\s+/g,"-").trim().replace(/\-+/g,"-").trim());return t}(s),o={keystore:{path:e,allowed_keystores:i},ssh:{listen:"127.0.0.1",port:5678,log:{size:10485760,backups:3}}},u=y.stringify(o),v.writeFileSync(r,u)),[2,y.parse(v.readFileSync(r,"utf-8"))]}var l,d}))}))},k=require("wative-core").WativeCore,x=require("@solana/web3.js"),P=x.Connection,q=x.PublicKey,I=x.VersionedTransaction,j=x.VersionedMessage,C=require("bs58"),T=require("@solana/web3.js"),A=T.Keypair,B=T.TransactionMessage,K=T.ComputeBudgetInstruction,L=T.TransactionInstruction,O=T.ComputeBudgetProgram,M=require("@coral-xyz/anchor").Wallet;w.configure({appenders:{file:{type:"file",filename:"/var/log/wative/wative-ssh.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"}}});var N=w.getLogger("file");N.level="info";var U=function(){function e(e,n,s,a,i,o,u,c){if(this._allowedAppIds=[],this._allowedPubKeys=[],this._allowedKeystoreIds=[],this._sessionIdAppIdMap={},function(e){if(e=e.trim(),!v.existsSync(e))throw new Error("File not exists")}(e),0===s.length||0===a.length||0===i.length||s.length!==a.length||s.length!==i.length)throw new Error("WativeWielderServer:: constructor: Invaild AllowedApp");for(var l=0;l<i.length;l++)for(var d=0;d<i[l].length;d++){var p=i[l][d];if(!u.includes(p))throw new Error("WativeWielderServer:: constructor: Invaild AllowedKeystoreIds")}for(var h=0,f=s;h<f.length;h++){var g=f[h];this._allowedAppIds.push(Buffer.from(g))}for(var m=0,y=a;m<y.length;m++){var w=y[m],b=r.utils.parseKey(t.readFileSync(w));this._allowedPubKeys.push(b)}this.wativeCore=new k(o,u,c),this._idRsaPrivatePath=e,this._idRsaPassphrase=n,this._allowedKeystoreIds=i,this._keystoreDirectoryPath=o}return e.prototype.listen=function(e,n){var s=this;new r.Server({hostKeys:[{key:t.readFileSync(this._idRsaPrivatePath),passphrase:this._idRsaPassphrase}]},(function(e){e.on("authentication",(function(t){var r=!0;if(s&&(s.checkValue(Buffer.from(t.username),"appId")||(r=!1)),"publickey"!==t.method||!r)return t.reject();var n=s.getBytesIndex(Buffer.from(t.username),s._allowedAppIds),a=s._allowedPubKeys[n];if(t.key.algo!==a.type||!s.checkValue(t.key.data,"publicKey")||t.signature&&!0!==a.verify(t.blob,t.signature,t.hashAlgo))return t.reject();if(r){var i=e._protocol._kex.sessionID.toString("hex");s._sessionIdAppIdMap[i]=Buffer.from(t.username),t.accept()}else t.reject()})).on("ready",(function(){e.on("session",(function(t,r){t().once("exec",(function(t,r,n){return b(s,void 0,void 0,(function(){var r,s,a;return S(this,(function(i){switch(i.label){case 0:return r=e._protocol._kex.sessionID.toString("hex"),[4,this.web3Request(r,n.command)];case 1:return s=i.sent(),(a=t())?(JSON.stringify(s)?(a.write(JSON.stringify(s)),a.exit(0),a.end()):(a.write("ssh2 connect error"),a.exit(0),a.end()),[2]):[2]}}))}))}))}))})).on("close",(function(){N.info("Client disconnected")})).on("error",(function(e){N.error("err: ",e.message)}))})).listen(n,e,(function(){N.info("Listening on port "+n)}))},e.prototype.web3Request=function(e,t){return b(this,void 0,void 0,(function(){var r,n,s,a,i,o,u,c,l,d,p,h,f,g,m;return S(this,(function(v){switch(v.label){case 0:return v.trys.push([0,34,,35]),r=this._sessionIdAppIdMap[e],(n=this.getBytesIndex(r,this._allowedAppIds))<0?[2,{status:!1,msg:"app not found"}]:(s=JSON.parse(t),N.info("sign message: ",t),a=s.method,i=s.keystoreId||s.params.keystoreId,o=s.chainId||s.params.chainId,this._allowedKeystoreIds[n].includes(i)?(u=void 0,"get_root_account"!==a?[3,1]:(u=this.getRootAccount(i,o),[3,33])):[2,{status:!1,msg:"keystore not allowed"}]);case 1:return"get_sub_account"!==a?[3,2]:(f=s.params,u=this.getSubAccount(i,f.chainId,null==f?void 0:f.startIndex,null==f?void 0:f.endIndex),[3,33]);case 2:if("sign"!==a)return[3,7];f=s.params,v.label=3;case 3:return v.trys.push([3,5,,6]),[4,this.wativeCore.account.signTransaction(f.txParams.from,f.txParams,f.rpcUrl)];case 4:return u=v.sent(),[3,6];case 5:return c=v.sent(),N.error("sign error: ",c.message),[2,{status:!1,msg:c.msg}];case 6:return[3,33];case 7:if("sign_and_send"!==a)return[3,12];f=s.params,v.label=8;case 8:return v.trys.push([8,10,,11]),[4,this.wativeCore.account.signAndSendTx(f.txParams,f.rpcUrl)];case 9:return l=v.sent(),u={transactionHash:l},[3,11];case 10:return[2,{status:!1,msg:v.sent().msg}];case 11:return[3,33];case 12:if("solana_sign"!==a)return[3,17];v.label=13;case 13:return v.trys.push([13,15,,16]),f=s.params,[4,this.signSolanaTransaction(f.txParams.from,f.txParams.data,f.txParams.lookup_tables,f.rpcUrl,f.priority_fee)];case 14:return u=v.sent(),[3,16];case 15:return d=v.sent(),N.error("sign error: ",d.message),[2,{status:!1,msg:d.msg}];case 16:return[3,33];case 17:if("solana_send"!==a)return[3,22];v.label=18;case 18:return v.trys.push([18,20,,21]),f=s.params,[4,this.sendSignedSolanaTransaction(f.txParams.from,f.txParams.signature,f.txParams.data,f.rpcUrl)];case 19:return u=v.sent(),[3,21];case 20:return p=v.sent(),N.error("sign error: ",p.message),[2,{status:!1,msg:p.msg}];case 21:return[3,33];case 22:if("sign_message"!==a)return[3,27];v.label=23;case 23:return v.trys.push([23,25,,26]),f=s.params,N.debug("sign message: ",f),[4,this.signMessage(f.account,f.message)];case 24:return u=v.sent(),[3,26];case 25:return h=v.sent(),N.error("sign error: ",h.message),[2,{status:!1,msg:h.msg}];case 26:return[3,33];case 27:if("sign_typed_data"!==a)return[3,32];v.label=28;case 28:return v.trys.push([28,30,,31]),f=s.params,N.debug("sign message: ",f),[4,this.signTypedData(f.account,f.domain,f.types_name,f.types,f.message)];case 29:return u=v.sent(),[3,31];case 30:return g=v.sent(),N.error("sign error: ",g.message),[2,{status:!1,msg:g.msg}];case 31:return[3,33];case 32:return[2,{status:!1,msg:"message method not find"}];case 33:return[2,{status:!0,data:u}];case 34:return m=v.sent(),N.error("sign error: ",m.message),[2,{status:!1,msg:m.msg}];case 35:return[2]}}))}))},e.prototype.checkValue=function(e,t){if("appId"!==t&&"publicKey"!==t)return!1;for(var r=this._allowedAppIds.length,s=0;s<r;s++){var a=void 0;a="appId"===t?this._allowedAppIds[s]:this._allowedPubKeys[s].getPublicSSH();var i=e.length!==a.length;i&&(a=e);var o=n.timingSafeEqual(e,a);if(!i&&o)return!0}},e.prototype.getBytesIndex=function(e,t){for(var r=t.length,s=0;s<r;s++)if(e.length===t[s].length&&n.timingSafeEqual(e,t[s]))return s;return-1},e.prototype.getRootAccount=function(e,r){var n=m.resolve(this._keystoreDirectoryPath,"accounts/".concat(e,".json")),s=t.readFileSync(n);return s=JSON.parse(s.toString()),[{id:0,address:"SOLANA"===this.getChainType(r)?s.data[0].ciphertexts.solana.address:s.data[0].ciphertexts.evm.address,children:s.data.length,type:"M"}]},e.prototype.getChainType=function(e){return"901"===e||"902"===e||"903"===e?"SOLANA":"EVM"},e.prototype.getSubAccount=function(e,r,n,s){var a=m.resolve(this._keystoreDirectoryPath,"accounts/".concat(e,".json")),i=t.readFileSync(a),o=(i=JSON.parse(i.toString())).data.length-1;s&&s<o&&(o=s);var u=0;if(n&&n>0&&(u=n),u>o)return[];for(var c=this.getChainType(r),l=[],d=u;d<=o;d++)l.push(i.data[d].ciphertexts[c.toLocaleLowerCase()].address);return l},e.prototype.signMessage=function(e,t){return b(this,void 0,void 0,(function(){var r;return S(this,(function(n){switch(n.label){case 0:return[4,this.wativeCore.account.signMessage(e,t)];case 1:return r=n.sent(),console.log(r),[2,r]}}))}))},e.prototype.signTypedData=function(e,t,r,n,s){return b(this,void 0,void 0,(function(){var a,i,o,u,c,l;return S(this,(function(d){switch(d.label){case 0:return console.log("111"),a=JSON.parse(t),i=JSON.parse(n),o=JSON.parse(s),console.log(a),console.log(i),console.log(o),u=this.wativeCore.account.showPrivateKey(e),[4,new f.ethers.Wallet(u).signTypedData(a,(l={},l[r]=i,l),o)];case 1:return c=d.sent(),console.log(c),[2,{status:!0,output:c}]}}))}))},e.prototype.signSolanaTransaction=function(e,t,r,n,s){return b(this,void 0,void 0,(function(){var a,i,o,u,c,l,d,p,h,f,g,m,v,y,w,b,_,k,x,T;return S(this,(function(S){switch(S.label){case 0:if(a=new P(n),i=[],!r)return[3,5];o=0,u=r,S.label=1;case 1:return o<u.length?(c=u[o],[4,a.getAddressLookupTable(new q(c))]):[3,5];case 2:return l=S.sent().value,i.push(l),[4,E(1e3)];case 3:S.sent(),S.label=4;case 4:return o++,[3,1];case 5:return d=j.deserialize(Uint8Array.from(Buffer.from(t,"hex"))),(p=B.decompile(d)).instructions.push(O.setComputeUnitLimit({units:2e6})),p.instructions.push(O.setComputeUnitPrice({microLamports:1e3})),d=p.compileToV0Message(i),h=d,[4,a.getLatestBlockhash()];case 6:return h.recentBlockhash=S.sent().blockhash,[4,E(3e3)];case 7:return S.sent(),f=new I(d),g=this.wativeCore.account.showPrivateKey(e),m=A.fromSecretKey(new Uint8Array(C.decode(g))),v=new M(m),[4,a.simulateTransaction(f)];case 8:if(!(y=S.sent())||!y.value||0===y.value.unitsConsumed||y.value.err)return[2,{status:!1,output:y.value.err}];if(w=p.instructions.length,b=Math.trunc(1.2*y.value.unitsConsumed),p.instructions[w-2]=O.setComputeUnitLimit({units:b}),s&&"null"!=s)return[3,12];S.label=9;case 9:return S.trys.push([9,11,,12]),[4,this.getPrioritizationFee(n)];case 10:return s=S.sent(),[3,12];case 11:return S.sent(),s=2e5,[3,12];case 12:return s<1e4&&(s=1e4),s>5e5&&(s=5e5),p.instructions[w-1]=O.setComputeUnitPrice({microLamports:s}),d=p.compileToV0Message(i),[4,E(1e3)];case 13:return S.sent(),_=d,[4,a.getLatestBlockhash()];case 14:return _.recentBlockhash=S.sent().blockhash,(f=new I(d)).feePayer=v.publicKey,[4,E(3e3)];case 15:return S.sent(),[4,this.wativeCore.account.signTransaction(e,f,n)];case 16:return k=S.sent(),x=new I(k.output.message,k.output.signatures),T=x.message.serialize(),T=Buffer.from(T).toString("hex"),[2,{status:!0,output:{transactionHash:C.encode(k.output.signatures[0]),message:T,compute_units:y.value.unitsConsumed.toString()}}]}}))}))},e.prototype.sendSignedSolanaTransaction=function(e,t,r,n){return b(this,void 0,void 0,(function(){var s,a,i;return S(this,(function(o){switch(o.label){case 0:return s=[C.decode(t)],a=j.deserialize(Uint8Array.from(Buffer.from(r,"hex"))),i=new I(a,s),[4,this.wativeCore.account.sendSignedTransaction(e,i,n)];case 1:return[2,o.sent()]}}))}))},e.prototype.getPrioritizationFee=function(e){return b(this,void 0,void 0,(function(){var t,r,n,s,a,i,o,u,c,l,d,p;return S(this,(function(h){switch(h.label){case 0:return t=new q("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"),[4,(r=new P(e,"confirmed")).getSignaturesForAddress(t,{limit:5})];case 1:return n=h.sent(),[4,E(2e3)];case 2:for(h.sent(),s=[],o=0;o<n.length;o++)s.push(n[o].signature);return[4,r.getParsedTransactions(s,{maxSupportedTransactionVersion:0})];case 3:for(a=h.sent(),i=0,o=0;o<a.length;o++)for(u=a[o].transaction.message.instructions,c=0;c<u.length;c++)if("ComputeBudget111111111111111111111111111111"===u[c].programId.toBase58()){l=u[c].data;try{d=new L({keys:[],programId:new q("ComputeBudget111111111111111111111111111111"),data:Buffer.from(C.decode(l))}),p=K.decodeSetComputeUnitPrice(d).microLamports,i+=Number(p);continue}catch(e){}}return[2,Math.ceil(i/5)]}}))}))},e}(),E=function(e){return new Promise((function(t){return setTimeout(t,e)}))};require("dotenv").config();var F=require("os");process.on("unhandledRejection",(function(e,t){console.log("Unhandled Rejection at:",t,"reason:",e)})),b(void 0,void 0,void 0,(function(){var e,t,r,n,s,a,i,o,u,c,l;return S(this,(function(d){switch(d.label){case 0:return e=F.homedir(),t=m.join(e,".wative"),[4,_(t)];case 1:return r=d.sent(),n=r.ssh.listen,s=r.ssh.port,a="/etc/wative/id_rsa_server",i="wative_server",o="detake",u="/etc/wative/id_rsa_detake.pub",c=r.keystore.allowed_keystores,[4,(p=c,b(void 0,void 0,void 0,(function(){var e,t,r;return S(this,(function(n){for(e=[],t=0;t<p.length;t++)r=p[t].replace(/-/g,"_"),e.push(process.env[r]);return[2,e]}))})))];case 2:return l=d.sent(),new U(a,i,[o],[u],[c],t,c,l).listen(n,s),[2]}var p}))}))}));
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,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return n={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function a(a){return function(c){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;n&&(n=0,a[0]&&(s=0)),s;)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 s.label++,{value:a[1],done:!1};case 5:s.label++,i=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}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;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 a=function(t){return n(void 0,void 0,void 0,(function(){var a,c,l,u,d,v,p;return s(this,(function(h){switch(h.label){case 0:return a="/etc/wative",i.existsSync(a)||i.mkdirSync(a),[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(),c=e.join(a,"config.ini"),i.existsSync(c)||(f=t,m=e.resolve(f,"network.json"),l=JSON.parse(i.readFileSync(m,"utf8")),u=l.accounts,d=function(e){for(var t=[],r=0;r<e.length;r++)t.push(e[r].trim().toLocaleLowerCase().replace(/\s+/g,"-").trim().replace(/\-+/g,"-").trim());return t}(u),v={keystore:{path:t,allowed_keystores:d},ssh:{listen:"127.0.0.1",port:5678}},p=o.stringify(v),i.writeFileSync(c,p)),[2,o.parse(i.readFileSync(c,"utf-8"))]}var f,m}))}))},c=require("os"),l=new t,u=require("../package.json"),d=function(){try{return r("systemctl --version",{stdio:"ignore"}),!0}catch(e){return!1}};l.version(u.version).description("Wative CLI Tool"),l.command("version").description("Show the version of wative").action((function(){console.log("Wative CLI Tool v".concat(u.version))}));l.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,i){return n(void 0,void 0,void 0,(function(){return s(this,(function(o){switch(o.label){case 0:return"start"!==t?[3,2]:[4,n(void 0,void 0,void 0,(function(){var t,i;return s(this,(function(o){switch(o.label){case 0:return t=c.homedir(),i=e.join(t,".wative"),[4,a(i)];case 1:o.sent(),console.log("Starting SSH service...");try{r("wative-ssh",{stdio:"inherit"})}catch(e){}return console.log("SSH service started."),[2]}}))}))];case 1:return o.sent(),[2];case 2:return"stop"===t?(function(){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.")}(),[2]):"service"===t&&"add"===i?(n(void 0,void 0,void 0,(function(){var t,i;return s(this,(function(o){switch(o.label){case 0:return d()?(t=c.homedir(),i=e.join(t,".wative"),[4,a(i)]):(console.log("Systemd is not available."),[2]);case 1:o.sent(),console.log("Adding SSH service...");try{r("sudo echo '".concat("\n [Unit]\n Description=Wative SSH Server\n After=network.target\n\n [Service]\n ExecStart=/usr/local/bin/wative-ssh\n User=root\n Group=root\n StandardOutput=append:/var/log/wative-ssh.log\n StandardError=append:/var/log/wative-ssh.err\n\n [Install]\n WantedBy=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){console.log(e)}return console.log("SSH service added."),[2]}}))})),[2]):"service"===t&&"remove"===i?(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]}}))}))})),l.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]}))}))})),l.parse(process.argv);
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,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return n={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function a(a){return function(c){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;n&&(n=0,a[0]&&(s=0)),s;)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 s.label++,{value:a[1],done:!1};case 5:s.label++,i=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}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;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 a=function(t){return n(void 0,void 0,void 0,(function(){var a,c,l,u,d,v,p;return s(this,(function(h){switch(h.label){case 0:return a="/etc/wative",i.existsSync(a)||i.mkdirSync(a),[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(),c=e.join(a,"config.ini"),i.existsSync(c)||(f=t,m=e.resolve(f,"network.json"),l=JSON.parse(i.readFileSync(m,"utf8")),u=l.accounts,d=function(e){for(var t=[],r=0;r<e.length;r++)t.push(e[r].trim().toLocaleLowerCase().replace(/\s+/g,"-").trim().replace(/\-+/g,"-").trim());return t}(u),v={keystore:{path:t,allowed_keystores:d},ssh:{listen:"127.0.0.1",port:5678,log:{size:10485760,backups:3}}},p=o.stringify(v),i.writeFileSync(c,p)),[2,o.parse(i.readFileSync(c,"utf-8"))]}var f,m}))}))},c=require("os"),l=new t,u=require("../package.json"),d=function(){try{return r("systemctl --version",{stdio:"ignore"}),!0}catch(e){return!1}};l.version(u.version).description("Wative CLI Tool"),l.command("version").description("Show the version of wative").action((function(){console.log("Wative CLI Tool v".concat(u.version))}));l.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,i){return n(void 0,void 0,void 0,(function(){return s(this,(function(o){switch(o.label){case 0:return"start"!==t?[3,2]:[4,n(void 0,void 0,void 0,(function(){var t,i;return s(this,(function(o){switch(o.label){case 0:return d()?(t=c.homedir(),i=e.join(t,".wative"),[4,a(i)]):(console.log("Systemd is not available."),[2]);case 1:o.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 o.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"===i?(n(void 0,void 0,void 0,(function(){var t,i;return s(this,(function(o){switch(o.label){case 0:return d()?(t=c.homedir(),i=e.join(t,".wative"),[4,a(i)]):(console.log("Systemd is not available."),[2]);case 1:o.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-ssh.log\nStandardError=append:/var/log/wative/wative-ssh.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"===i?(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]}}))}))})),l.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]}))}))})),l.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,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(c){return function(a){return function(c){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(s=0)),s;)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 s.label++,{value:c[1],done:!1};case 5:s.label++,n=c[1],c=[0];continue;case 7:c=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==c[0]&&2!==c[0])){s=0;continue}if(3===c[0]&&(!i||c[1]>i[0]&&c[1]<i[3])){s.label=c[1];break}if(6===c[0]&&s.label<i[1]){s.label=i[1],i=c;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(c);break}i[2]&&s.ops.pop(),s.trys.pop();continue}c=t.call(e,s)}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;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 d=function(e){return u(void 0,void 0,void 0,(function(){var t,n,i,o,d,v,f;return l(this,(function(p){switch(p.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 p.sent(),n=s.join(t,"config.ini"),c.existsSync(n)||(h=e,y=s.resolve(h,"network.json"),i=JSON.parse(c.readFileSync(y,"utf8")),o=i.accounts,d=function(e){for(var t=[],r=0;r<e.length;r++)t.push(e[r].trim().toLocaleLowerCase().replace(/\s+/g,"-").trim().replace(/\-+/g,"-").trim());return t}(o),v={keystore:{path:e,allowed_keystores:d},ssh:{listen:"127.0.0.1",port:5678}},f=a.stringify(v),c.writeFileSync(n,f)),[2,a.parse(c.readFileSync(n,"utf-8"))]}var h,y}))}))},v=require("os"),f=new t.Command,p=require("../package.json"),h=function(){try{return r.execSync("systemctl --version",{stdio:"ignore"}),!0}catch(e){return!1}};f.version(p.version).description("Wative CLI Tool"),f.command("version").description("Show the version of wative").action((function(){console.log("Wative CLI Tool v".concat(p.version))}));f.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;return l(this,(function(n){switch(n.label){case 0:return e=v.homedir(),t=s.join(e,".wative"),[4,d(t)];case 1:n.sent(),console.log("Starting SSH service...");try{r.execSync("wative-ssh",{stdio:"inherit"})}catch(e){}return console.log("SSH service started."),[2]}}))}))];case 1:return n.sent(),[2];case 2:return"stop"===e?(function(){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.")}(),[2]):"service"===e&&"add"===t?(u(void 0,void 0,void 0,(function(){var e,t;return l(this,(function(n){switch(n.label){case 0:return h()?(e=v.homedir(),t=s.join(e,".wative"),[4,d(t)]):(console.log("Systemd is not available."),[2]);case 1:n.sent(),console.log("Adding SSH service...");try{r.execSync("sudo echo '".concat("\n [Unit]\n Description=Wative SSH Server\n After=network.target\n\n [Service]\n ExecStart=/usr/local/bin/wative-ssh\n User=root\n Group=root\n StandardOutput=append:/var/log/wative-ssh.log\n StandardError=append:/var/log/wative-ssh.err\n\n [Install]\n WantedBy=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){console.log(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]}}))}))})),f.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]}))}))})),f.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("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,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(c){return function(a){return function(c){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(s=0)),s;)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 s.label++,{value:c[1],done:!1};case 5:s.label++,n=c[1],c=[0];continue;case 7:c=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==c[0]&&2!==c[0])){s=0;continue}if(3===c[0]&&(!i||c[1]>i[0]&&c[1]<i[3])){s.label=c[1];break}if(6===c[0]&&s.label<i[1]){s.label=i[1],i=c;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(c);break}i[2]&&s.ops.pop(),s.trys.pop();continue}c=t.call(e,s)}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;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 d=function(e){return u(void 0,void 0,void 0,(function(){var t,n,i,o,d,v,f;return l(this,(function(p){switch(p.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 p.sent(),n=s.join(t,"config.ini"),c.existsSync(n)||(h=e,y=s.resolve(h,"network.json"),i=JSON.parse(c.readFileSync(y,"utf8")),o=i.accounts,d=function(e){for(var t=[],r=0;r<e.length;r++)t.push(e[r].trim().toLocaleLowerCase().replace(/\s+/g,"-").trim().replace(/\-+/g,"-").trim());return t}(o),v={keystore:{path:e,allowed_keystores:d},ssh:{listen:"127.0.0.1",port:5678,log:{size:10485760,backups:3}}},f=a.stringify(v),c.writeFileSync(n,f)),[2,a.parse(c.readFileSync(n,"utf-8"))]}var h,y}))}))},v=require("os"),f=new t.Command,p=require("../package.json"),h=function(){try{return r.execSync("systemctl --version",{stdio:"ignore"}),!0}catch(e){return!1}};f.version(p.version).description("Wative CLI Tool"),f.command("version").description("Show the version of wative").action((function(){console.log("Wative CLI Tool v".concat(p.version))}));f.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;return l(this,(function(n){switch(n.label){case 0:return h()?(e=v.homedir(),t=s.join(e,".wative"),[4,d(t)]):(console.log("Systemd is not available."),[2]);case 1:n.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;return l(this,(function(n){switch(n.label){case 0:return h()?(e=v.homedir(),t=s.join(e,".wative"),[4,d(t)]):(console.log("Systemd is not available."),[2]);case 1:n.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-ssh.log\nStandardError=append:/var/log/wative/wative-ssh.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]}}))}))})),f.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]}))}))})),f.parse(process.argv)}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wative",
3
- "version": "1.0.44",
3
+ "version": "1.1.1",
4
4
  "description": "An agile keystore management toolkit",
5
5
  "main": "index.ts",
6
6
  "scripts": {
package/src/ssh/index.ts CHANGED
@@ -31,7 +31,6 @@ const main = async () => {
31
31
  const client_keystores = config.keystore.allowed_keystores;
32
32
  const client_keystore_passwords = await getKeystorePasswords(client_keystores);
33
33
 
34
- // return
35
34
  const wativeServer = new WativeServer(
36
35
  id_rsa_private_key_path,
37
36
  id_rsa_password,
package/src/ssh/utils.ts CHANGED
@@ -65,6 +65,10 @@ const getAndGenerateConfig = async (keystorePath: string) => {
65
65
  const ssh: any = {
66
66
  listen: '127.0.0.1',
67
67
  port: 5678,
68
+ log: {
69
+ size: 10485760,
70
+ backups: 3
71
+ }
68
72
  }
69
73
  const config = {
70
74
  keystore,
@@ -12,7 +12,29 @@ const { Connection, PublicKey, VersionedTransaction, VersionedMessage } = requir
12
12
  const bs58 = require("bs58");
13
13
  const { Keypair, TransactionMessage, ComputeBudgetInstruction, TransactionInstruction, ComputeBudgetProgram } = require("@solana/web3.js");
14
14
  const { Wallet } = require("@coral-xyz/anchor");
15
- const logger = log4js.getLogger();
15
+ log4js.configure({
16
+ appenders: {
17
+ file: {
18
+ type: 'file',
19
+ filename: '/var/log/wative/wative-ssh.log',
20
+ maxLogSize: 10485760,
21
+ backups: 3,
22
+ compress: true,
23
+ keepFileExt: true,
24
+ layout: {
25
+ type: 'pattern',
26
+ pattern: '%d{yyyy-MM-dd hh:mm:ss.SSS} [%p] %c - %m'
27
+ },
28
+ encoding: 'utf-8'
29
+ },
30
+ console: { type: 'console' }
31
+ },
32
+ categories: {
33
+ default: { appenders: ['file', 'console'], level: 'info' }
34
+ }
35
+ })
36
+
37
+ const logger = log4js.getLogger("file");
16
38
  logger.level = "info";
17
39
 
18
40
  export class WativeWielderServer {
@@ -90,7 +112,6 @@ export class WativeWielderServer {
90
112
  }, (client: any) => {
91
113
  client.on('authentication', (ctx: any) => {
92
114
  let allowed = true;
93
-
94
115
  if (this)
95
116
  if (!this.checkValue(Buffer.from(ctx.username), 'appId')) {
96
117
  allowed = false;
package/src/wative.ts CHANGED
@@ -29,17 +29,27 @@ program
29
29
 
30
30
 
31
31
  const startSSHService = async () => {
32
+ if (!hasSystemd()) {
33
+ console.log('Systemd is not available.');
34
+ return;
35
+ }
36
+
32
37
  const userHomeDirectory = os.homedir();
33
38
  const keystorePath = path.join(userHomeDirectory, '.wative');
34
39
  await getAndGenerateConfig(keystorePath);
35
40
  console.log('Starting SSH service...');
36
41
  try {
37
- execSync('wative-ssh', { stdio: 'inherit' });
42
+ execSync('wative-ssh --daemon', { stdio: 'inherit' });
38
43
  } catch (error) { }
39
44
  console.log('SSH service started.');
40
45
  }
41
46
 
42
47
  const stopSSHService = () => {
48
+ if (!hasSystemd()) {
49
+ console.log('Systemd is not available.');
50
+ return;
51
+ }
52
+
43
53
  try {
44
54
  execSync("ps aux | grep wative-ssh | grep -v grep | awk '{print $2}' | sudo xargs kill", { stdio: 'inherit' });
45
55
  } catch (error) {
@@ -60,19 +70,19 @@ const addSSHService = async () => {
60
70
 
61
71
  const serviceFilePath = '/etc/systemd/system/wative.service';
62
72
  const serviceContent = `
63
- [Unit]
64
- Description=Wative SSH Server
65
- After=network.target
66
-
67
- [Service]
68
- ExecStart=/usr/local/bin/wative-ssh
69
- User=root
70
- Group=root
71
- StandardOutput=append:/var/log/wative-ssh.log
72
- StandardError=append:/var/log/wative-ssh.err
73
-
74
- [Install]
75
- WantedBy=multi-user.target
73
+ [Unit]
74
+ Description=Wative SSH Server
75
+ After=network.target
76
+
77
+ [Service]
78
+ ExecStart=/usr/local/bin/wative-ssh
79
+ User=root
80
+ Group=root
81
+ StandardOutput=append:/var/log/wative/wative-ssh.log
82
+ StandardError=append:/var/log/wative/wative-ssh.err
83
+
84
+ [Install]
85
+ WantedBy=multi-user.target
76
86
  `;
77
87
 
78
88
  console.log('Adding SSH service...');
@@ -82,7 +92,7 @@ const addSSHService = async () => {
82
92
  execSync('sudo systemctl enable wative', { stdio: 'inherit' });
83
93
  execSync('sudo systemctl start wative', { stdio: 'inherit' });
84
94
  } catch (error) {
85
- console.log(error);;
95
+ // console.log(error);
86
96
  }
87
97
 
88
98
  console.log('SSH service added.');
@@ -105,12 +115,12 @@ const removeSSHService = () => {
105
115
  execSync('sudo systemctl disable wative', { stdio: 'inherit' });
106
116
  } catch (error) {
107
117
  }
108
-
118
+
109
119
  try {
110
120
  execSync('sudo rm -rf /etc/systemd/system/wative.service', { stdio: 'inherit' });
111
121
  } catch (error) {
112
122
  }
113
-
123
+
114
124
  try {
115
125
  execSync('sudo systemctl daemon-reload', { stdio: 'inherit' });
116
126
  } catch (error) {