wative 1.0.40 → 1.0.41

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
@@ -8,27 +8,36 @@ ENV_FILE="/tmp/wative_env.tmp"
8
8
  # Extract allowed_keystores and store them in the temporary file
9
9
  awk -F "=" '/^\[keystore\]/ {flag=1} flag && /^allowed_keystores/ {print $2}' "$KEYSTORE_CONFIG_PATH" > "$TEMP_FILE"
10
10
 
11
- # Iterate through the keystores and prompt for passwords
12
- while IFS= read -r ALLOWED_KEYSTORE; do
11
+ # Clear previous environment variables file
12
+ > "$ENV_FILE"
13
+
14
+ # Use a for loop to iterate over the keystores and prompt for passwords
15
+ for ALLOWED_KEYSTORE in $(cat "$TEMP_FILE"); do
13
16
  # Skip empty lines
14
17
  [[ -z "$ALLOWED_KEYSTORE" ]] && continue
15
18
 
19
+ # Replace dashes with underscores for valid environment variable names
16
20
  ALLOWED_KEYSTORE=$(echo "$ALLOWED_KEYSTORE" | sed 's/-/_/g')
21
+
17
22
  # Prompt the user to input a password for the current keystore
18
- PASSWORD_INPUT=$(systemd-ask-password "Input the password for keystore [$ALLOWED_KEYSTORE]: ")
23
+ echo "Input the password for keystore [$ALLOWED_KEYSTORE]: "
24
+
25
+ # Read password input (the -s flag hides the input for privacy)
26
+ read -s PASSWORD_INPUT # Waits for user input, hides the password
19
27
 
20
28
  # Save the environment variable to a temporary file
21
- echo "export \"$ALLOWED_KEYSTORE\"=\"$PASSWORD_INPUT\"" >> "$ENV_FILE"
22
-
23
- done < "$TEMP_FILE"
29
+ echo "export $ALLOWED_KEYSTORE=\"$PASSWORD_INPUT\"" >> "$ENV_FILE"
30
+ done
24
31
 
25
32
  # Clean up the temporary keystore file
26
33
  rm -f "$TEMP_FILE"
34
+
27
35
  # Load the environment variables from the temporary file
28
36
  source "$ENV_FILE"
37
+
29
38
  # Clean up the temporary environment file
30
39
  rm -f "$ENV_FILE"
31
40
 
32
41
  # Execute wative-ssh with the loaded environment variables
33
42
  TARGET_FILE=$(realpath "$(dirname "$(realpath "$0")")/../lib/wative-ssh.umd.js")
34
- exec "$(which node)" "$TARGET_FILE"
43
+ exec "$(which node)" "$TARGET_FILE" > /var/log/wative-ssh.log 2>&1 &
@@ -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(console.log(process.env),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(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 +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(console.log(process.env),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,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}))}))}));
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(f){switch(f.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 f.sent(),c=e.join(a,"config.ini"),i.existsSync(c)||(h=t,m=e.resolve(h,"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 h,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(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:return o.sent(),console.log("Adding SSH service..."),r("sudo echo '".concat("[Unit]\n Description=Wative SSH Server\n After=network.target\n\n [Service]\n ExecStart=/usr/local/bin/wative-ssh\n Restart=always\n User=root\n Group=root\n StandardOutput=append:/var/log/wative.log\n StandardError=append:/var/log/wative.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"}),console.log("SSH service added."),[2]}}))})),[2]):"service"===t&&"remove"===i?(d()?(console.log("Removing SSH service..."),r("sudo systemctl stop wative",{stdio:"inherit"}),r("sudo systemctl disable wative",{stdio:"inherit"}),r("sudo rm -rf /etc/systemd/system/wative.service",{stdio:"inherit"}),r("sudo systemctl daemon-reload",{stdio:"inherit"}),console.log("SSH service removed.")):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}},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("[Unit]\n Description=Wative SSH Server\n After=network.target\n\n [Service]\n ExecStart=/usr/local/bin/wative-ssh\n Restart=always\n User=root\n Group=root\n StandardOutput=append:/var/log/wative.log\n StandardError=append:/var/log/wative.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){}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(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:return n.sent(),console.log("Adding SSH service..."),r.execSync("sudo echo '".concat("[Unit]\n Description=Wative SSH Server\n After=network.target\n\n [Service]\n ExecStart=/usr/local/bin/wative-ssh\n Restart=always\n User=root\n Group=root\n StandardOutput=append:/var/log/wative.log\n StandardError=append:/var/log/wative.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"}),console.log("SSH service added."),[2]}}))})),[2]):"service"===e&&"remove"===t?(h()?(console.log("Removing SSH service..."),r.execSync("sudo systemctl stop wative",{stdio:"inherit"}),r.execSync("sudo systemctl disable wative",{stdio:"inherit"}),r.execSync("sudo rm -rf /etc/systemd/system/wative.service",{stdio:"inherit"}),r.execSync("sudo systemctl daemon-reload",{stdio:"inherit"}),console.log("SSH service removed.")):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}},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("[Unit]\n Description=Wative SSH Server\n After=network.target\n\n [Service]\n ExecStart=/usr/local/bin/wative-ssh\n Restart=always\n User=root\n Group=root\n StandardOutput=append:/var/log/wative.log\n StandardError=append:/var/log/wative.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){}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.40",
3
+ "version": "1.0.41",
4
4
  "description": "An agile keystore management toolkit",
5
5
  "main": "index.ts",
6
6
  "scripts": {
package/src/ssh/index.ts CHANGED
@@ -6,7 +6,6 @@ require('dotenv').config();
6
6
  const os = require('os');
7
7
 
8
8
  const getKeystorePasswords = async (allowedKeystores: string[]) => {
9
- console.log(process.env);
10
9
  const passwords: any = [];
11
10
  for (let i = 0; i < allowedKeystores.length; i++) {
12
11
  const keystore = allowedKeystores[i].replace(/-/g, '_');
@@ -15,6 +14,7 @@ const getKeystorePasswords = async (allowedKeystores: string[]) => {
15
14
  return passwords;
16
15
  }
17
16
 
17
+
18
18
  const main = async () => {
19
19
  const userHomeDirectory = os.homedir();
20
20
  const keystorePath = path.join(userHomeDirectory, '.wative');
package/src/wative.ts CHANGED
@@ -43,7 +43,7 @@ const stopSSHService = () => {
43
43
  try {
44
44
  execSync("ps aux | grep wative-ssh | grep -v grep | awk '{print $2}' | sudo xargs kill", { stdio: 'inherit' });
45
45
  } catch (error) {
46
- console.log(error);
46
+ // console.log(error);
47
47
  }
48
48
  console.log('SSH service stopped.');
49
49
  }
@@ -76,26 +76,50 @@ const addSSHService = async () => {
76
76
  `;
77
77
 
78
78
  console.log('Adding SSH service...');
79
- execSync(`sudo echo '${serviceContent}' > ${serviceFilePath}`, { stdio: 'inherit' });
80
- execSync('sudo systemctl daemon-reload', { stdio: 'inherit' });
81
- execSync('sudo systemctl enable wative', { stdio: 'inherit' });
82
- execSync('sudo systemctl start wative', { stdio: 'inherit' });
79
+ try {
80
+ execSync(`sudo echo '${serviceContent}' > ${serviceFilePath}`, { stdio: 'inherit' });
81
+ execSync('sudo systemctl daemon-reload', { stdio: 'inherit' });
82
+ execSync('sudo systemctl enable wative', { stdio: 'inherit' });
83
+ execSync('sudo systemctl start wative', { stdio: 'inherit' });
84
+ } catch (error) {
85
+
86
+ }
87
+
83
88
  console.log('SSH service added.');
84
89
  }
85
90
 
91
+
86
92
  const removeSSHService = () => {
87
93
  if (!hasSystemd()) {
88
94
  console.log('Systemd is not available.');
89
95
  return;
90
96
  }
91
97
  console.log('Removing SSH service...');
92
- execSync('sudo systemctl stop wative', { stdio: 'inherit' });
93
- execSync('sudo systemctl disable wative', { stdio: 'inherit' });
94
- execSync('sudo rm -rf /etc/systemd/system/wative.service', { stdio: 'inherit' });
95
- execSync('sudo systemctl daemon-reload', { stdio: 'inherit' });
98
+
99
+ try {
100
+ execSync('sudo systemctl stop wative', { stdio: 'inherit' });
101
+ } catch (error) {
102
+ }
103
+
104
+ try {
105
+ execSync('sudo systemctl disable wative', { stdio: 'inherit' });
106
+ } catch (error) {
107
+ }
108
+
109
+ try {
110
+ execSync('sudo rm -rf /etc/systemd/system/wative.service', { stdio: 'inherit' });
111
+ } catch (error) {
112
+ }
113
+
114
+ try {
115
+ execSync('sudo systemctl daemon-reload', { stdio: 'inherit' });
116
+ } catch (error) {
117
+ }
96
118
  console.log('SSH service removed.');
97
119
  }
98
120
 
121
+
122
+
99
123
  program
100
124
  .command('ssh')
101
125
  .option('start', 'Start SSH service')