wative 1.1.16 → 1.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/account.d.ts +14 -0
- package/lib/account.d.ts.map +1 -0
- package/lib/assets.d.ts +11 -0
- package/lib/assets.d.ts.map +1 -0
- package/lib/chain.d.ts +6 -0
- package/lib/chain.d.ts.map +1 -0
- package/lib/config.d.ts +23 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/daemon-watcher.js +181 -0
- package/lib/home_page.d.ts +4 -0
- package/lib/home_page.d.ts.map +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.esm.js +1 -1
- package/lib/index.umd.js +1 -1
- package/lib/network.d.ts +28 -0
- package/lib/network.d.ts.map +1 -0
- package/lib/ssh/client.d.ts +120 -0
- package/lib/ssh/client.d.ts.map +1 -0
- package/lib/ssh/client_example.d.ts +19 -0
- package/lib/ssh/client_example.d.ts.map +1 -0
- package/lib/ssh/client_test.d.ts +27 -0
- package/lib/ssh/client_test.d.ts.map +1 -0
- package/lib/ssh/config_manager.d.ts +55 -0
- package/lib/ssh/config_manager.d.ts.map +1 -0
- package/lib/ssh/config_template.d.ts +52 -0
- package/lib/ssh/config_template.d.ts.map +1 -0
- package/lib/ssh/index.d.ts +8 -0
- package/lib/ssh/index.d.ts.map +1 -0
- package/lib/ssh/remote_server_example.d.ts +16 -0
- package/lib/ssh/remote_server_example.d.ts.map +1 -0
- package/lib/ssh/service_manager.d.ts +119 -0
- package/lib/ssh/service_manager.d.ts.map +1 -0
- package/lib/ssh/types.d.ts +45 -0
- package/lib/ssh/types.d.ts.map +1 -0
- package/lib/ssh/utils.d.ts +11 -0
- package/lib/ssh/utils.d.ts.map +1 -0
- package/lib/ssh/wative_server.d.ts +26 -0
- package/lib/ssh/wative_server.d.ts.map +1 -0
- package/lib/tools.d.ts +6 -0
- package/lib/tools.d.ts.map +1 -0
- package/lib/tx_gas_utils.d.ts +18 -0
- package/lib/tx_gas_utils.d.ts.map +1 -0
- package/lib/utils.d.ts +49 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/wative.d.ts +4 -0
- package/lib/wative.d.ts.map +1 -0
- package/lib/wative.esm.js +1 -1
- package/lib/wative.umd.js +1 -1
- package/lib/web3.d.ts +59 -0
- package/lib/web3.d.ts.map +1 -0
- package/package.json +10 -6
- package/src/daemon-watcher.js +181 -0
- package/src/index.ts +22 -6
- package/src/ssh/client.rs +221 -0
- package/src/ssh/client.ts +389 -0
- package/src/ssh/config_manager.ts +317 -0
- package/src/ssh/index.ts +50 -36
- package/src/ssh/service_manager.ts +684 -0
- package/src/ssh/types.ts +35 -1
- package/src/ssh/wative_server.ts +1 -2
- package/src/wative.ts +566 -122
- package/bin/wative-ssh.sh +0 -44
- package/lib/wative-ssh.esm.js +0 -1
- package/lib/wative-ssh.umd.js +0 -1
package/bin/wative-ssh.sh
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
KEYSTORE_CONFIG_PATH="/etc/wative/config.ini"
|
|
3
|
-
|
|
4
|
-
# Create a temporary file to store the keystore list
|
|
5
|
-
TEMP_FILE="/tmp/allowed_keystores.tmp"
|
|
6
|
-
ENV_FILE="/tmp/wative_env.tmp"
|
|
7
|
-
|
|
8
|
-
# Extract allowed_keystores and store them in the temporary file
|
|
9
|
-
awk -F "=" '/^\[keystore\]/ {flag=1} flag && /^allowed_keystores/ {print $2}' "$KEYSTORE_CONFIG_PATH" > "$TEMP_FILE"
|
|
10
|
-
|
|
11
|
-
# Clear previous environment variables file
|
|
12
|
-
> "$ENV_FILE"
|
|
13
|
-
|
|
14
|
-
# Iterate through the keystores and prompt for passwords
|
|
15
|
-
while IFS= read -r ALLOWED_KEYSTORE; do
|
|
16
|
-
# Skip empty lines
|
|
17
|
-
[[ -z "$ALLOWED_KEYSTORE" ]] && continue
|
|
18
|
-
|
|
19
|
-
ALLOWED_KEYSTORE=$(echo "$ALLOWED_KEYSTORE" | sed 's/-/_/g')
|
|
20
|
-
# Prompt the user to input a password for the current keystore
|
|
21
|
-
PASSWORD_INPUT=$(systemd-ask-password "Input the password for keystore [$ALLOWED_KEYSTORE]: ")
|
|
22
|
-
|
|
23
|
-
# Save the environment variable to a temporary file
|
|
24
|
-
echo "export \"$ALLOWED_KEYSTORE\"=\"$PASSWORD_INPUT\"" >> "$ENV_FILE"
|
|
25
|
-
|
|
26
|
-
done < "$TEMP_FILE"
|
|
27
|
-
|
|
28
|
-
# Clean up the temporary keystore file
|
|
29
|
-
rm -f "$TEMP_FILE"
|
|
30
|
-
|
|
31
|
-
# Load the environment variables from the temporary file
|
|
32
|
-
source "$ENV_FILE"
|
|
33
|
-
|
|
34
|
-
# Clean up the temporary environment file
|
|
35
|
-
rm -f "$ENV_FILE"
|
|
36
|
-
|
|
37
|
-
# Execute wative-ssh with the loaded environment variables
|
|
38
|
-
TARGET_FILE=$(realpath "$(dirname "$(realpath "$0")")/../lib/wative-ssh.umd.js")
|
|
39
|
-
|
|
40
|
-
if [ "$1" == "--daemon" ]; then
|
|
41
|
-
/usr/local/bin/node "$TARGET_FILE" > /var/log/wative/wative.log 2>&1 &
|
|
42
|
-
else
|
|
43
|
-
/usr/local/bin/node "$TARGET_FILE"
|
|
44
|
-
fi
|
package/lib/wative-ssh.esm.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=i(0),o.throw=i(1),o.return=i(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,i[0]&&(a=0)),a;)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 a.label++,{value:i[1],done:!1};case 5:a.label++,s=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(n=a.trys,(n=n.length>0&&n[n.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!n||i[1]>n[0]&&i[1]<n[3])){a.label=i[1];break}if(6===i[0]&&a.label<n[1]){a.label=n[1],n=i;break}if(n&&a.label<n[2]){a.label=n[2],a.ops.push(i);break}n[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}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;var d=function(e){return e=(e=(e=(e=e.trim()).toLocaleLowerCase()).replace(/\s+/g,"-").trim()).replace(/\-+/g,"-").trim()};require("bn.js").BN,require("ethereumjs-util").stripHexPrefix,require("bignumber.js").BigNumber,require("chalk"),require("wative-core").WativeCore,require("chalk"),require("dotenv").config(),require("cli-progress"),require("wative-core").WativeCore;var h=function(r){return l(void 0,void 0,void 0,function(){var s,n,a,u,c,h,f;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)||(m=r,v=e.resolve(m,"network.json"),a=JSON.parse(t.readFileSync(v,"utf8")),u=a.accounts,c=function(e){for(var t=[],r=0;r<e.length;r++)t.push(d(e[r]));return t}(u),h={keystore:{path:r,allowed_keystores:c},ssh:{listen:"127.0.0.1",port:5678,log:{size:10485760,backups:3}}},f=o.stringify(h),t.writeFileSync(n,f)),[2,o.parse(t.readFileSync(n,"utf-8"))]}var m,v})})},f=require("wative-core").WativeCore,g=require("@solana/web3.js"),m=g.Connection,v=g.PublicKey,y=g.VersionedTransaction,w=g.VersionedMessage,b=require("bs58"),_=require("@solana/web3.js"),S=_.Keypair,k=_.TransactionMessage,x=_.ComputeBudgetInstruction,I=_.TransactionInstruction,P=_.ComputeBudgetProgram,C=require("@coral-xyz/anchor").Wallet;u.configure({appenders:{file:{type:"file",filename:"/var/log/wative/wative.log",maxLogSize:10485760,backups:3,compress:!0,keepFileExt:!0,layout:{type:"pattern",pattern:"%d{yyyy-MM-dd hh:mm:ss.SSS} [%p] %c - %m"},encoding:"utf-8"},console:{type:"console"}},categories:{default:{appenders:["file","console"],level:"info"}}});var j=u.getLogger("file");j.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 h=i[p][d];if(!c.includes(h))throw new Error("WativeWielderServer:: constructor: Invaild AllowedKeystoreIds")}for(var g=0,m=a;g<m.length;g++){var v=m[g];this._allowedAppIds.push(Buffer.from(v))}for(var y=0,w=o;y<w.length;y++){var b=w[y],_=s.parseKey(r(b));this._allowedPubKeys.push(_)}this.wativeCore=new f(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(){j.info("Client disconnected")}).on("error",function(e){j.error("err: ",e.message)})}).listen(t,e,function(){j.info("Listening on port "+t)})},o.prototype.web3Request=function(e,t){return l(this,void 0,void 0,function(){var r,s,n,a,o,i,u,c,l,d,h,f,g,m,v;return p(this,function(p){switch(p.label){case 0:return p.trys.push([0,34,,35]),r=this._sessionIdAppIdMap[e],(s=this.getBytesIndex(r,this._allowedAppIds))<0?[2,{status:!1,msg:"app not found"}]:(n=JSON.parse(t),j.info("sign message: ",t),a=n.method,o=n.keystoreId||n.params.keystoreId,i=n.chainId||n.params.chainId,this._allowedKeystoreIds[s].includes(o)?(u=void 0,"get_root_account"!==a?[3,1]:(u=this.getRootAccount(o,i),[3,33])):[2,{status:!1,msg:"keystore not allowed"}]);case 1:return"get_sub_account"!==a?[3,2]:(g=n.params,u=this.getSubAccount(o,g.chainId,null==g?void 0:g.startIndex,null==g?void 0:g.endIndex),[3,33]);case 2:if("sign"!==a)return[3,7];g=n.params,p.label=3;case 3:return p.trys.push([3,5,,6]),[4,this.wativeCore.account.signTransaction(g.txParams.from,g.txParams,g.rpcUrl)];case 4:return u=p.sent(),[3,6];case 5:return c=p.sent(),j.error("sign error: ",c.message),[2,{status:!1,msg:c.msg}];case 6:return[3,33];case 7:if("sign_and_send"!==a)return[3,12];g=n.params,p.label=8;case 8:return p.trys.push([8,10,,11]),[4,this.wativeCore.account.signAndSendTx(g.txParams,g.rpcUrl)];case 9:return l=p.sent(),u={transactionHash:l},[3,11];case 10:return[2,{status:!1,msg:p.sent().msg}];case 11:return[3,33];case 12:if("solana_sign"!==a)return[3,17];p.label=13;case 13:return p.trys.push([13,15,,16]),g=n.params,[4,this.signSolanaTransaction(g.txParams.from,g.txParams.data,g.txParams.lookup_tables,g.rpcUrl,g.priority_fee)];case 14:return u=p.sent(),[3,16];case 15:return d=p.sent(),j.error("sign error: ",d.message),[2,{status:!1,msg:d.msg}];case 16:return[3,33];case 17:if("solana_send"!==a)return[3,22];p.label=18;case 18:return p.trys.push([18,20,,21]),g=n.params,[4,this.sendSignedSolanaTransaction(g.txParams.from,g.txParams.signature,g.txParams.data,g.rpcUrl)];case 19:return u=p.sent(),[3,21];case 20:return h=p.sent(),j.error("sign error: ",h.message),[2,{status:!1,msg:h.msg}];case 21:return[3,33];case 22:if("sign_message"!==a)return[3,27];p.label=23;case 23:return p.trys.push([23,25,,26]),g=n.params,j.debug("sign message: ",g),[4,this.signMessage(g.account,g.message)];case 24:return u=p.sent(),[3,26];case 25:return f=p.sent(),j.error("sign error: ",f.message),[2,{status:!1,msg:f.msg}];case 26:return[3,33];case 27:if("sign_typed_data"!==a)return[3,32];p.label=28;case 28:return p.trys.push([28,30,,31]),g=n.params,j.debug("sign message: ",g),[4,this.signTypedData(g.account,g.domain,g.types_name,g.types,g.message)];case 29:return u=p.sent(),[3,31];case 30:return m=p.sent(),j.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(),j.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 a=JSON.parse(t),o=JSON.parse(s),i=JSON.parse(n),console.log(a),console.log(o),console.log(i),u=this.wativeCore.account.showPrivateKey(e),[4,new c.Wallet(u).signTypedData(a,(d={},d[r]=o,d),i)];case 1:return l=p.sent(),console.log(l),[2,{status:!0,output:l}]}})})},o.prototype.signSolanaTransaction=function(e,t,r,s,n){return l(this,void 0,void 0,function(){var a,o,i,u,c,l,d,h,f,g,_,x,I,j,A,q,B,K,L,N;return p(this,function(p){switch(p.label){case 0:if(a=new m(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 v(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=w.deserialize(Uint8Array.from(Buffer.from(t,"hex"))),(h=k.decompile(d)).instructions.push(P.setComputeUnitLimit({units:2e6})),h.instructions.push(P.setComputeUnitPrice({microLamports:1e3})),d=h.compileToV0Message(o),f=d,[4,a.getLatestBlockhash()];case 6:return f.recentBlockhash=p.sent().blockhash,[4,T(3e3)];case 7:return p.sent(),g=new y(d),_=this.wativeCore.account.showPrivateKey(e),x=S.fromSecretKey(new Uint8Array(b.decode(_))),I=new C(x),[4,a.simulateTransaction(g)];case 8:if(!(j=p.sent())||!j.value||0===j.value.unitsConsumed||j.value.err)return[2,{status:!1,output:j.value.err}];if(A=h.instructions.length,q=Math.trunc(1.2*j.value.unitsConsumed),h.instructions[A-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[A-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,(g=new y(d)).feePayer=I.publicKey,[4,T(3e3)];case 15:return p.sent(),[4,this.wativeCore.account.signTransaction(e,g,s)];case 16:return K=p.sent(),L=new y(K.output.message,K.output.signatures),N=L.message.serialize(),N=Buffer.from(N).toString("hex"),[2,{status:!0,output:{transactionHash:b.encode(K.output.signatures[0]),message:N,compute_units:j.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=[b.decode(t)],a=w.deserialize(Uint8Array.from(Buffer.from(r,"hex"))),o=new y(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 v("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"),[4,(r=new m(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 I({keys:[],programId:new v("ComputeBudget111111111111111111111111111111"),data:Buffer.from(b.decode(l))}),h=x.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 q=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,d,f;return p(this,function(g){switch(g.label){case 0:return t=q.homedir(),r=e.join(t,".wative"),[4,h(r)];case 1:return s=g.sent(),n=s.ssh.listen,a=s.ssh.port,o="/etc/wative/id_rsa_server",i="wative_server",u="detake",c="/etc/wative/id_rsa_detake.pub",d=s.keystore.allowed_keystores,[4,(m=d,l(void 0,void 0,void 0,function(){var e,t,r;return p(this,function(s){for(e=[],t=0;t<m.length;t++)r=m[t].replace(/-/g,"_"),e.push(process.env[r]);return[2,e]})}))];case 2:return f=g.sent(),new A(o,i,[u],[c],[d],r,d,f).listen(n,a),[2]}var m})});
|
package/lib/wative-ssh.umd.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("path"),require("fs"),require("ssh2"),require("crypto"),require("ini"),require("child_process"),require("figlet"),require("inquirer"),require("web3"),require("@solana/web3.js"),require("@solana/spl-token"),require("@metaplex-foundation/js"),require("bignumber.js"),require("log4js"),require("ethers")):"function"==typeof define&&define.amd?define(["path","fs","ssh2","crypto","ini","child_process","figlet","inquirer","web3","@solana/web3.js","@solana/spl-token","@metaplex-foundation/js","bignumber.js","log4js","ethers"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).path,e.fs,e.ssh2,e.crypto,e.ini,e.child_process,null,null,null,null,null,null,null,e.log4js,e.ethers)}(this,function(e,t,r,n,s,a,i,o,u,c,l,d,p,h,f){"use strict";function g(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,Object.freeze(t)}var v=g(e),y=g(t),m=g(s),w=g(h);function b(e,t,r,n){return new(r||(r=Promise))(function(s,a){function i(e){try{u(n.next(e))}catch(e){a(e)}}function o(e){try{u(n.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(i,o)}u((n=n.apply(e,t||[])).next())})}function S(e,t){var r,n,s,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=o(0),i.throw=o(1),i.return=o(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function o(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,o[0]&&(a=0)),a;)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 a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(s=a.trys,(s=s.length>0&&s[s.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!s||o[1]>s[0]&&o[1]<s[3])){a.label=o[1];break}if(6===o[0]&&a.label<s[1]){a.label=s[1],s=o;break}if(s&&a.label<s[2]){a.label=s[2],a.ops.push(o);break}s[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}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;var _=function(e){return e=(e=(e=(e=e.trim()).toLocaleLowerCase()).replace(/\s+/g,"-").trim()).replace(/\-+/g,"-").trim()};require("bn.js").BN,require("ethereumjs-util").stripHexPrefix,require("bignumber.js").BigNumber,require("chalk"),require("wative-core").WativeCore,require("chalk"),require("dotenv").config(),require("cli-progress"),require("wative-core").WativeCore;var k=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",y.existsSync(t)||y.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"),y.existsSync(t)&&y.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"),y.existsSync(n)&&y.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"),y.existsSync(r)||(l=e,d=v.resolve(l,"network.json"),n=JSON.parse(y.readFileSync(d,"utf8")),s=n.accounts,i=function(e){for(var t=[],r=0;r<e.length;r++)t.push(_(e[r]));return t}(s),o={keystore:{path:e,allowed_keystores:i},ssh:{listen:"127.0.0.1",port:5678,log:{size:10485760,backups:3}}},u=m.stringify(o),y.writeFileSync(r,u)),[2,m.parse(y.readFileSync(r,"utf-8"))]}var l,d})})},x=require("wative-core").WativeCore,P=require("@solana/web3.js"),q=P.Connection,I=P.PublicKey,j=P.VersionedTransaction,C=P.VersionedMessage,T=require("bs58"),A=require("@solana/web3.js"),B=A.Keypair,O=A.TransactionMessage,K=A.ComputeBudgetInstruction,L=A.TransactionInstruction,M=A.ComputeBudgetProgram,N=require("@coral-xyz/anchor").Wallet;w.configure({appenders:{file:{type:"file",filename:"/var/log/wative/wative.log",maxLogSize:10485760,backups:3,compress:!0,keepFileExt:!0,layout:{type:"pattern",pattern:"%d{yyyy-MM-dd hh:mm:ss.SSS} [%p] %c - %m"},encoding:"utf-8"},console:{type:"console"}},categories:{default:{appenders:["file","console"],level:"info"}}});var U=w.getLogger("file");U.level="info";var E=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(),!y.existsSync(e))throw new Error("File not exists")}(e),0===s.length||0===a.length||0===i.length||s.length!==a.length||s.length!==i.length)throw new Error("WativeWielderServer:: constructor: Invaild AllowedApp");for(var l=0;l<i.length;l++)for(var d=0;d<i[l].length;d++){var p=i[l][d];if(!u.includes(p))throw new Error("WativeWielderServer:: constructor: Invaild AllowedKeystoreIds")}for(var h=0,f=s;h<f.length;h++){var g=f[h];this._allowedAppIds.push(Buffer.from(g))}for(var v=0,m=a;v<m.length;v++){var w=m[v],b=r.utils.parseKey(t.readFileSync(w));this._allowedPubKeys.push(b)}this.wativeCore=new x(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(){U.info("Client disconnected")}).on("error",function(e){U.error("err: ",e.message)})}).listen(n,e,function(){U.info("Listening on port "+n)})},e.prototype.web3Request=function(e,t){return b(this,void 0,void 0,function(){var r,n,s,a,i,o,u,c,l,d,p,h,f,g,v;return S(this,function(y){switch(y.label){case 0:return y.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),U.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,y.label=3;case 3:return y.trys.push([3,5,,6]),[4,this.wativeCore.account.signTransaction(f.txParams.from,f.txParams,f.rpcUrl)];case 4:return u=y.sent(),[3,6];case 5:return c=y.sent(),U.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,y.label=8;case 8:return y.trys.push([8,10,,11]),[4,this.wativeCore.account.signAndSendTx(f.txParams,f.rpcUrl)];case 9:return l=y.sent(),u={transactionHash:l},[3,11];case 10:return[2,{status:!1,msg:y.sent().msg}];case 11:return[3,33];case 12:if("solana_sign"!==a)return[3,17];y.label=13;case 13:return y.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=y.sent(),[3,16];case 15:return d=y.sent(),U.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];y.label=18;case 18:return y.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=y.sent(),[3,21];case 20:return p=y.sent(),U.error("sign error: ",p.message),[2,{status:!1,msg:p.msg}];case 21:return[3,33];case 22:if("sign_message"!==a)return[3,27];y.label=23;case 23:return y.trys.push([23,25,,26]),f=s.params,U.debug("sign message: ",f),[4,this.signMessage(f.account,f.message)];case 24:return u=y.sent(),[3,26];case 25:return h=y.sent(),U.error("sign error: ",h.message),[2,{status:!1,msg:h.msg}];case 26:return[3,33];case 27:if("sign_typed_data"!==a)return[3,32];y.label=28;case 28:return y.trys.push([28,30,,31]),f=s.params,U.debug("sign message: ",f),[4,this.signTypedData(f.account,f.domain,f.types_name,f.types,f.message)];case 29:return u=y.sent(),[3,31];case 30:return g=y.sent(),U.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=y.sent(),U.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 a=JSON.parse(t),i=JSON.parse(n),o=JSON.parse(s),console.log(a),console.log(i),console.log(o),u=this.wativeCore.account.showPrivateKey(e),[4,new f.ethers.Wallet(u).signTypedData(a,(l={},l[r]=i,l),o)];case 1:return c=d.sent(),console.log(c),[2,{status:!0,output:c}]}})})},e.prototype.signSolanaTransaction=function(e,t,r,n,s){return b(this,void 0,void 0,function(){var a,i,o,u,c,l,d,p,h,f,g,v,y,m,w,b,_,k,x,P;return S(this,function(S){switch(S.label){case 0:if(a=new q(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 I(c))]):[3,5];case 2:return l=S.sent().value,i.push(l),[4,F(1e3)];case 3:S.sent(),S.label=4;case 4:return o++,[3,1];case 5:return d=C.deserialize(Uint8Array.from(Buffer.from(t,"hex"))),(p=O.decompile(d)).instructions.push(M.setComputeUnitLimit({units:2e6})),p.instructions.push(M.setComputeUnitPrice({microLamports:1e3})),d=p.compileToV0Message(i),h=d,[4,a.getLatestBlockhash()];case 6:return h.recentBlockhash=S.sent().blockhash,[4,F(3e3)];case 7:return S.sent(),f=new j(d),g=this.wativeCore.account.showPrivateKey(e),v=B.fromSecretKey(new Uint8Array(T.decode(g))),y=new N(v),[4,a.simulateTransaction(f)];case 8:if(!(m=S.sent())||!m.value||0===m.value.unitsConsumed||m.value.err)return[2,{status:!1,output:m.value.err}];if(w=p.instructions.length,b=Math.trunc(1.2*m.value.unitsConsumed),p.instructions[w-2]=M.setComputeUnitLimit({units:b}),s&&"null"!=s)return[3,12];S.label=9;case 9:return S.trys.push([9,11,,12]),[4,this.getPrioritizationFee(n)];case 10:return s=S.sent(),[3,12];case 11:return S.sent(),s=2e5,[3,12];case 12:return s<1e4&&(s=1e4),s>5e5&&(s=5e5),p.instructions[w-1]=M.setComputeUnitPrice({microLamports:s}),d=p.compileToV0Message(i),[4,F(1e3)];case 13:return S.sent(),_=d,[4,a.getLatestBlockhash()];case 14:return _.recentBlockhash=S.sent().blockhash,(f=new j(d)).feePayer=y.publicKey,[4,F(3e3)];case 15:return S.sent(),[4,this.wativeCore.account.signTransaction(e,f,n)];case 16:return k=S.sent(),x=new j(k.output.message,k.output.signatures),P=x.message.serialize(),P=Buffer.from(P).toString("hex"),[2,{status:!0,output:{transactionHash:T.encode(k.output.signatures[0]),message:P,compute_units:m.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=[T.decode(t)],a=C.deserialize(Uint8Array.from(Buffer.from(r,"hex"))),i=new j(a,s),[4,this.wativeCore.account.sendSignedTransaction(e,i,n)];case 1:return[2,o.sent()]}})})},e.prototype.getPrioritizationFee=function(e){return b(this,void 0,void 0,function(){var t,r,n,s,a,i,o,u,c,l,d,p;return S(this,function(h){switch(h.label){case 0:return t=new I("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"),[4,(r=new q(e,"confirmed")).getSignaturesForAddress(t,{limit:5})];case 1:return n=h.sent(),[4,F(2e3)];case 2:for(h.sent(),s=[],o=0;o<n.length;o++)s.push(n[o].signature);return[4,r.getParsedTransactions(s,{maxSupportedTransactionVersion:0})];case 3:for(a=h.sent(),i=0,o=0;o<a.length;o++)for(u=a[o].transaction.message.instructions,c=0;c<u.length;c++)if("ComputeBudget111111111111111111111111111111"===u[c].programId.toBase58()){l=u[c].data;try{d=new L({keys:[],programId:new I("ComputeBudget111111111111111111111111111111"),data:Buffer.from(T.decode(l))}),p=K.decodeSetComputeUnitPrice(d).microLamports,i+=Number(p);continue}catch(e){}}return[2,Math.ceil(i/5)]}})})},e}(),F=function(e){return new Promise(function(t){return setTimeout(t,e)})};require("dotenv").config();var R=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=R.homedir(),t=v.join(e,".wative"),[4,k(t)];case 1:return r=d.sent(),n=r.ssh.listen,s=r.ssh.port,a="/etc/wative/id_rsa_server",i="wative_server",o="detake",u="/etc/wative/id_rsa_detake.pub",c=r.keystore.allowed_keystores,[4,(p=c,b(void 0,void 0,void 0,function(){var e,t,r;return S(this,function(n){for(e=[],t=0;t<p.length;t++)r=p[t].replace(/-/g,"_"),e.push(process.env[r]);return[2,e]})}))];case 2:return l=d.sent(),new E(a,i,[o],[u],[c],t,c,l).listen(n,s),[2]}var p})})});
|