wative 1.0.37 → 1.0.39

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.
@@ -0,0 +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],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}))}))}));
@@ -0,0 +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 n from"ini";import"figlet";import"inquirer";import"web3";import"@solana/web3.js";import"@solana/spl-token";import"@metaplex-foundation/js";import"bignumber.js";function o(e,t,r,i){return new(r||(r=Promise))((function(n,o){function s(e){try{c(i.next(e))}catch(e){o(e)}}function a(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?n(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,n,o,s={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(r=1,i&&(n=2&a[0]?i.return:a[0]?i.throw||((n=i.return)&&n.call(i),0):i.next)&&!(n=n.call(i,a[1])).done)return n;switch(i=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=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(!(n=s.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){s.label=a[1];break}if(6===a[0]&&s.label<n[1]){s.label=n[1],n=a;break}if(n&&s.label<n[2]){s.label=n[2],s.ops.push(a);break}n[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],i=0}finally{r=n=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 o(void 0,void 0,void 0,(function(){var a,c,l,u,d,v,p;return s(this,(function(m){switch(m.label){case 0:return a="/etc/wative",i.existsSync(a)||i.mkdirSync(a),[4,o(void 0,void 0,void 0,(function(){var t,n,o,a,c;return s(this,(function(s){return t="/etc/wative",n=e.join(t,"id_rsa_server.pub"),o=e.join(t,"id_rsa_server"),i.existsSync(n)&&i.existsSync(o)||(console.log("Generating SSH key pair..."),r("ssh-keygen -t rsa -f ".concat(o," -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 m.sent(),c=e.join(a,"config.ini"),i.existsSync(c)||(f=t,h=e.resolve(f,"network.json"),l=JSON.parse(i.readFileSync(h,"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=n.stringify(v),i.writeFileSync(c,p)),[2,n.parse(i.readFileSync(c,"utf-8"))]}var f,h}))}))},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))}));var v=l.command("ssh").description("Manage SSH service");v.command("start").description("Start SSH service").action((function(){if(d()){try{r("wative-ssh",{stdio:"inherit"})}catch(e){}console.log("Starting SSH service...")}else console.log("Systemd is not available.")}));var p=v.command("service").description("Manage SSH service");p.command("add").description("Add SSH service").action((function(){return o(void 0,void 0,void 0,(function(){var t,i;return s(this,(function(n){switch(n.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 n.sent(),console.log("Adding SSH service..."),r("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("systemctl daemon-reload",{stdio:"inherit"}),r("systemctl enable wative",{stdio:"inherit"}),r("systemctl start wative",{stdio:"inherit"}),[2]}}))}))})),p.command("remove").description("Remove SSH service").action((function(){d()?(console.log("Removing SSH service..."),r("systemctl stop wative",{stdio:"inherit"}),r("systemctl disable wative",{stdio:"inherit"}),r("rm /etc/systemd/system/wative.service",{stdio:"inherit"}),r("systemctl daemon-reload",{stdio:"inherit"})):console.log("Systemd is not available.")})),l.command("cmd").description("Start wallet-cli shell").action((function(){return o(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);
@@ -0,0 +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 l(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 u(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 l(void 0,void 0,void 0,(function(){var t,n,i,o,d,v,f;return u(this,(function(p){switch(p.label){case 0:return t="/etc/wative",c.existsSync(t)||c.mkdirSync(t),[4,l(void 0,void 0,void 0,(function(){var e,t,n,i,o;return u(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)||(y=e,h=s.resolve(y,"network.json"),i=JSON.parse(c.readFileSync(h,"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 y,h}))}))},v=require("os"),f=new t.Command,p=require("../package.json"),y=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))}));var h=f.command("ssh").description("Manage SSH service");h.command("start").description("Start SSH service").action((function(){if(y()){try{r.execSync("wative-ssh",{stdio:"inherit"})}catch(e){}console.log("Starting SSH service...")}else console.log("Systemd is not available.")}));var S=h.command("service").description("Manage SSH service");S.command("add").description("Add SSH service").action((function(){return l(void 0,void 0,void 0,(function(){var e,t;return u(this,(function(n){switch(n.label){case 0:return y()?(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("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("systemctl daemon-reload",{stdio:"inherit"}),r.execSync("systemctl enable wative",{stdio:"inherit"}),r.execSync("systemctl start wative",{stdio:"inherit"}),[2]}}))}))})),S.command("remove").description("Remove SSH service").action((function(){y()?(console.log("Removing SSH service..."),r.execSync("systemctl stop wative",{stdio:"inherit"}),r.execSync("systemctl disable wative",{stdio:"inherit"}),r.execSync("rm /etc/systemd/system/wative.service",{stdio:"inherit"}),r.execSync("systemctl daemon-reload",{stdio:"inherit"})):console.log("Systemd is not available.")})),f.command("cmd").description("Start wallet-cli shell").action((function(){return l(void 0,void 0,void 0,(function(){return u(this,(function(e){try{r.execSync("wallet-cli",{stdio:"inherit"})}catch(e){}return[2]}))}))})),f.parse(process.argv)}));
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "wative",
3
- "version": "1.0.37",
3
+ "version": "1.0.39",
4
4
  "description": "An agile keystore management toolkit",
5
5
  "main": "index.ts",
6
6
  "scripts": {
7
7
  "test": "jest",
8
8
  "compile": "tsc",
9
- "build": "rollup --config"
9
+ "build": "rollup --config rollup.config.js"
10
10
  },
11
11
  "bin": {
12
- "wallet-cli": "bin/wative-cli.js"
12
+ "wallet-cli": "bin/wative-cli.js",
13
+ "wative": "bin/wative.js",
14
+ "wative-ssh": "bin/wative-ssh.sh"
13
15
  },
14
16
  "repository": {
15
17
  "type": "git",
@@ -30,8 +32,10 @@
30
32
  "@metamask/bip39": "4.0.0",
31
33
  "@metaplex-foundation/js": "0.20.1",
32
34
  "@rollup/plugin-commonjs": "21.0.1",
35
+ "@rollup/plugin-typescript": "^12.1.2",
33
36
  "@solana/web3.js": "1.91.8",
34
37
  "@types/figlet": "1.5.8",
38
+ "@types/ini": "^4.1.1",
35
39
  "@types/inquirer": "9.0.7",
36
40
  "@types/node-fetch": "2.6.11",
37
41
  "bip39": "3.1.0",
@@ -41,16 +45,19 @@
41
45
  "ethereumjs-wallet": "1.0.2",
42
46
  "ethers-multicall": "0.2.3",
43
47
  "figlet": "1.7.0",
48
+ "ini": "^5.0.0",
44
49
  "inquirer": "8.0.0",
45
50
  "inquirer-table-input": "0.0.3",
46
51
  "inquirer-tree-prompt": "1.1.2",
47
52
  "keythereum": "2.0.0",
53
+ "log4js": "^6.9.1",
48
54
  "micro-ed25519-hdkey": "0.1.2",
49
55
  "node-fetch": "2.6.0",
50
56
  "rollup": "2.79.1",
51
57
  "rollup-plugin-terser": "7.0.2",
52
58
  "rollup-plugin-typescript2": "0.31.2",
53
59
  "rpc-websockets": "7.10.0",
60
+ "ssh2": "1.14.0",
54
61
  "uuid": "9.0.0",
55
62
  "wative-core": "1.0.17",
56
63
  "web3": "1.7.3"
@@ -59,5 +66,8 @@
59
66
  "lib": "lib",
60
67
  "test": "test"
61
68
  },
62
- "keywords": []
63
- }
69
+ "keywords": [],
70
+ "devDependencies": {
71
+ "@types/ssh2": "^1.15.4"
72
+ }
73
+ }
package/src/account.ts CHANGED
@@ -19,6 +19,7 @@ import {
19
19
  inputPasswordWithoutValidator,
20
20
  getKeystoreSlugByAccountName,
21
21
  getAccountNameByKeystoreSlug,
22
+ inputMaskedPassword,
22
23
  } from "./utils";
23
24
  import { getAccountAddress, getAccountBalance, getNetworkInfoByName, getNetworkTypeByName, getStatus, selectDefaultNetwork, showAllAccounts, switchNetworkByAccountName } from "./network";
24
25
  import { getAssetList, showAssetsDetail } from './assets';
@@ -70,7 +71,7 @@ const importPassphrase = async (keystore_path: string, wative_core: typeof Wativ
70
71
  return;
71
72
  }
72
73
 
73
- let passphrase = await inputSomething('Please enter a mnemonic [split by space]', passphraseValidator);
74
+ let passphrase = await inputMaskedPassword('Please enter a mnemonic [split by space]', passphraseValidator);
74
75
  passphrase = passphrase.replace(/\s+/g, " ");
75
76
 
76
77
  let keystore_slug = getKeystoreSlugByAccountName(pre_account_info.account_name);
@@ -99,7 +100,7 @@ const createPrivateKeyAccount = async (keystore_path: string, wative_core: typeo
99
100
  return;
100
101
  }
101
102
 
102
- let private_key = await inputSomething('Please enter a private key');
103
+ let private_key = await inputMaskedPassword('Please enter a private key');
103
104
  let keystore_slug = getKeystoreSlugByAccountName(pre_account_info.account_name);
104
105
  await _importAccount(
105
106
  keystore_path,
@@ -248,9 +249,11 @@ export const loginIn = async (keystore_path: string, keystore_slug: string, wati
248
249
 
249
250
  for (let i = 0; i < 3; i++) {
250
251
  let account_name = getAccountNameByKeystoreSlug(keystore_path, keystore_slug);
251
-
252
+ let password_name = 'WATIVE_PASSWD_' + keystore_slug;
252
253
  let password: any;
253
- if (process.env.WativePassword && process.env.WativePassword !== '') {
254
+ if (process.env[password_name] && process.env[password_name] !== '') {
255
+ password = process.env[password_name];
256
+ } else if (process.env.WativePassword && process.env.WativePassword !== '') {
254
257
  password = process.env.WativePassword;
255
258
  } else {
256
259
  password = await inputPasswordWithoutValidator(`Please input the password for Account [${account_name}]`);
@@ -317,6 +320,9 @@ const selectAccount = async (keystore_path: string, wative_core: typeof WativeCo
317
320
  const selected_account_name = account_name_list[select_account_options.indexOf(selected_account) - 2];
318
321
  const keystore_slug = getKeystoreSlugByAccountName(selected_account_name);
319
322
 
323
+ console.log(
324
+ chalk.green(`Keystore slug: [${keystore_slug}]`)
325
+ );
320
326
  let login_result = await loginIn(keystore_path, keystore_slug, wative_core);
321
327
  if (login_result.isLoginIn) {
322
328
  await accountManager(keystore_path, keystore_slug, wative_core, login_result.password);
@@ -0,0 +1,52 @@
1
+ import WativeServer from './wative_server';
2
+ import * as path from 'path';
3
+ import { getAndGenerateConfig } from './utils';
4
+
5
+ require('dotenv').config();
6
+ const os = require('os');
7
+
8
+ const getKeystorePasswords = async (allowedKeystores: string[]) => {
9
+ const passwords: any = [];
10
+ for (let i = 0; i < allowedKeystores.length; i++) {
11
+ const keystore = allowedKeystores[i];
12
+ passwords.push(process.env[keystore]);
13
+ }
14
+ return passwords;
15
+ }
16
+
17
+ const main = async () => {
18
+ const userHomeDirectory = os.homedir();
19
+ const keystorePath = path.join(userHomeDirectory, '.wative');
20
+
21
+ let config = await getAndGenerateConfig(keystorePath);
22
+
23
+ const export_server_listen = config.ssh.listen;
24
+ const export_server_port = config.ssh.port;
25
+ const id_rsa_private_key_path = "/etc/wative/id_rsa_server";
26
+ const id_rsa_password = "wative_server";
27
+
28
+ const client_name = 'detake';
29
+ const client_id_rsa_public_key_path = "/etc/wative/id_rsa_detake.pub";
30
+ const client_keystores = config.keystore.allowed_keystores;
31
+ const client_keystore_passwords = await getKeystorePasswords(client_keystores);
32
+
33
+ // return
34
+ const wativeServer = new WativeServer(
35
+ id_rsa_private_key_path,
36
+ id_rsa_password,
37
+ [client_name],
38
+ [client_id_rsa_public_key_path],
39
+ [client_keystores],
40
+ keystorePath,
41
+ client_keystores,
42
+ client_keystore_passwords,
43
+ );
44
+
45
+ wativeServer.listen(export_server_listen, export_server_port);
46
+ }
47
+
48
+ process.on('unhandledRejection', (reason, p) => {
49
+ console.log('Unhandled Rejection at:', p, 'reason:', reason);
50
+ });
51
+
52
+ main()
@@ -0,0 +1,18 @@
1
+ import { TxParams } from "@walletbunker/core/lib/types"
2
+
3
+ type SubAccountMessageParams = {
4
+ rootAccount: string,
5
+ chainId: string,
6
+ startIndex?: number,
7
+ endIndex?: number
8
+ }
9
+
10
+ type SignMessageParams = {
11
+ txParams: TxParams,
12
+ rpcUrl: string
13
+ }
14
+
15
+ export {
16
+ SubAccountMessageParams,
17
+ SignMessageParams
18
+ }
@@ -0,0 +1,85 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import * as ini from 'ini';
4
+ import { execSync } from 'child_process';
5
+ import { getNetworkInfo } from '../account';
6
+ import { batchGetKeystoreSlugByAccountName } from '../utils';
7
+
8
+
9
+ /**
10
+ * Check the existence of the file
11
+ * @filePath
12
+ */
13
+ const checkFileExistence = (filePath: string) => {
14
+ filePath = filePath.trim()
15
+ let isExists = fs.existsSync(filePath)
16
+ if (!isExists) {
17
+ throw new Error('File not exists')
18
+ }
19
+ }
20
+
21
+ function sleep(time = 0) {
22
+ return new Promise((resolve, reject) => {
23
+ setTimeout(() => {
24
+ resolve(true)
25
+ }, time)
26
+ })
27
+ }
28
+
29
+ const createSSHKeyPair = async () => {
30
+ const configDir = "/etc/wative";
31
+ const idRsaServerPublicKeyPath = path.join(configDir, 'id_rsa_server.pub');
32
+ const idRsaServerPrivateKeyPath = path.join(configDir, 'id_rsa_server');
33
+
34
+ if (!fs.existsSync(idRsaServerPublicKeyPath) || !fs.existsSync(idRsaServerPrivateKeyPath)) {
35
+ console.log('Generating SSH key pair...');
36
+ execSync(`ssh-keygen -t rsa -f ${idRsaServerPrivateKeyPath} -N 'wative_server'`, { stdio: 'inherit' });
37
+ }
38
+
39
+ const idRsaDetakePublicKeyPath = path.join(configDir, 'id_rsa_detake.pub');
40
+ const idRsaDetakePrivateKeyPath = path.join(configDir, 'id_rsa_detake');
41
+
42
+ if (!fs.existsSync(idRsaDetakePublicKeyPath) || !fs.existsSync(idRsaDetakePrivateKeyPath)) {
43
+ console.log('Generating SSH key pair...');
44
+ execSync(`ssh-keygen -t rsa -f ${idRsaDetakePrivateKeyPath} -N 'wative_detake'`, { stdio: 'inherit' });
45
+ }
46
+ }
47
+
48
+
49
+ const getAndGenerateConfig = async (keystorePath: string) => {
50
+ const configDir = "/etc/wative";
51
+ if (!fs.existsSync(configDir)) {
52
+ fs.mkdirSync(configDir);
53
+ }
54
+
55
+ await createSSHKeyPair();
56
+ const configPath = path.join(configDir, 'config.ini');
57
+ if (!fs.existsSync(configPath)) {
58
+ const networks = getNetworkInfo(keystorePath);
59
+ const account_name_list = networks.accounts;
60
+ const keystore_slug_list = batchGetKeystoreSlugByAccountName(account_name_list);
61
+ const keystore: any = {
62
+ path: keystorePath,
63
+ allowed_keystores: keystore_slug_list,
64
+ }
65
+ const ssh: any = {
66
+ listen: '127.0.0.1',
67
+ port: 5678,
68
+ }
69
+ const config = {
70
+ keystore,
71
+ ssh,
72
+ }
73
+ let text = ini.stringify(config);
74
+ fs.writeFileSync(configPath, text);
75
+ }
76
+
77
+ const config = ini.parse(fs.readFileSync(configPath, 'utf-8'));
78
+ return config;
79
+ }
80
+
81
+ export {
82
+ checkFileExistence,
83
+ sleep,
84
+ getAndGenerateConfig,
85
+ }