From 85b7af04c7ca1ae9e1ff550c43f3ab5def9a18b9 Mon Sep 17 00:00:00 2001 From: 0xrookie <0xrookie@0xrookie.com> Date: Fri, 3 Jun 2022 15:33:43 +0800 Subject: [PATCH 1/2] feat(marketmaker): encrypt eth private key and cryptowatch api key --- encrypt-secret-key.js | 22 ++++++++++++++++++++++ marketmaker.js | 10 ++++++++-- package-lock.json | 25 +++++++++++++++++++++++++ package.json | 2 ++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 encrypt-secret-key.js diff --git a/encrypt-secret-key.js b/encrypt-secret-key.js new file mode 100644 index 0000000..74a1018 --- /dev/null +++ b/encrypt-secret-key.js @@ -0,0 +1,22 @@ +import CryptoJS from 'crypto-js' +import readlineSync from 'readline-sync' + +function encrypt() { + var ethPrivKey = readlineSync.question('please input eth private key: ',{hideEchoBack: true}); + var cryptowatchKey = readlineSync.question('please input cryptowatch key: ',{hideEchoBack: true}); + var passwd = readlineSync.question('please input your password: ',{hideEchoBack: true}); + var verifypasswd = readlineSync.question('please reinput your password: ',{hideEchoBack: true}); + + if (passwd != verifypasswd) { + console.log("your password mistach!") + return + } + var encryptEthPrivKey = CryptoJS.AES.encrypt(ethPrivKey, passwd).toString(); + var encryptCryptowatchKey = CryptoJS.AES.encrypt(cryptowatchKey, passwd).toString(); + + console.log("your encrypted eth private key: ", encryptEthPrivKey) + console.log("your encrypted cryptowatch key: ", encryptCryptowatchKey) +} + +eval(encrypt()) + diff --git a/marketmaker.js b/marketmaker.js index 8398897..30145ac 100644 --- a/marketmaker.js +++ b/marketmaker.js @@ -4,6 +4,8 @@ import ethers from 'ethers'; import dotenv from 'dotenv'; import fetch from 'node-fetch'; import fs from 'fs'; +import readlineSync from 'readline-sync' +import CryptoJS from 'crypto-js' dotenv.config(); @@ -22,6 +24,9 @@ let FEE_TOKEN = null; let uniswap_error_counter = 0; let chainlink_error_counter = 0; +// input decrypt password +var passwd = readlineSync.question('please input your password: ',{hideEchoBack: true}); + // Load MM config let MM_CONFIG; if (process.env.MM_CONFIG) { @@ -78,7 +83,7 @@ try { }); } for(let i=0; i= 0.8.0" + } + }, "node_modules/scrypt-js": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/scrypt-js/-/scrypt-js-3.0.1.tgz", @@ -2008,6 +2023,11 @@ "resolved": "https://registry.npmjs.org/chnl/-/chnl-1.2.0.tgz", "integrity": "sha512-g5gJb59edwCliFbX2j7G6sBfY4sX9YLy211yctONI2GRaiX0f2zIbKWmBm+sPqFNEpM7Ljzm7IJX/xrjiEbPrw==" }, + "crypto-js": { + "version": "4.1.1", + "resolved": "https://registry.npmmirror.com/crypto-js/-/crypto-js-4.1.1.tgz", + "integrity": "sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==" + }, "d": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz", @@ -2448,6 +2468,11 @@ "es-abstract": "^1.19.1" } }, + "readline-sync": { + "version": "1.4.10", + "resolved": "https://registry.npmmirror.com/readline-sync/-/readline-sync-1.4.10.tgz", + "integrity": "sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw==" + }, "scrypt-js": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/scrypt-js/-/scrypt-js-3.0.1.tgz", diff --git a/package.json b/package.json index 19da3cb..41ff261 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,11 @@ "author": "", "license": "ISC", "dependencies": { + "crypto-js": "^4.1.1", "dotenv": "^10.0.0", "ethers": "^5.5.1", "node-fetch": "^3.1.0", + "readline-sync": "^1.4.10", "ws": "^8.2.3", "zksync": "0.11.6" }, From ce908ba58c38e84a5d5d91f8f90a2d7885a1f8c4 Mon Sep 17 00:00:00 2001 From: 0xrookie <0xrookie@0xrookie.com> Date: Mon, 6 Jun 2022 23:47:53 +0800 Subject: [PATCH 2/2] feat(marketmaker): change encrypt key feature to an optional choice --- marketmaker.js | 20 +++++++++++++++----- package-lock.json | 11 +++++++++++ package.json | 1 + 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/marketmaker.js b/marketmaker.js index 30145ac..ebdad63 100644 --- a/marketmaker.js +++ b/marketmaker.js @@ -6,6 +6,7 @@ import fetch from 'node-fetch'; import fs from 'fs'; import readlineSync from 'readline-sync' import CryptoJS from 'crypto-js' +import minimist from 'minimist' dotenv.config(); @@ -24,8 +25,12 @@ let FEE_TOKEN = null; let uniswap_error_counter = 0; let chainlink_error_counter = 0; -// input decrypt password -var passwd = readlineSync.question('please input your password: ',{hideEchoBack: true}); +// Encrypt the eth private key and cryptowatch api key if you want +let args = minimist(process.argv.slice(2), {boolean: 'encrypt-key'}); +let passwd = null; +if (args['encrypt-key']) { + passwd = readlineSync.question('please input your password: ',{hideEchoBack: true}); +} // Load MM config let MM_CONFIG; @@ -83,7 +88,10 @@ try { }); } for(let i=0; i