Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(marketmaker): encrypt eth private key and cryptowatch api key #86

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions encrypt-secret-key.js
Original file line number Diff line number Diff line change
@@ -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())

18 changes: 17 additions & 1 deletion marketmaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ 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'
import minimist from 'minimist'

dotenv.config();

Expand All @@ -22,6 +25,13 @@ let FEE_TOKEN = null;
let uniswap_error_counter = 0;
let chainlink_error_counter = 0;

// Encrypt the eth private key and cryptowatch api key if you want
let args = minimist(process.argv.slice(2), {boolean: 'encrypt-key'});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the config.json as well. I would sugest adding a entry like: "encryptKey": true

Then do the if check like: if(MM_CONFIG?.encryptKey)

Dont think it is a good idea to change the usage for this function. We controlle verything else using the config as well.

let passwd = null;
if (args['encrypt-key']) {
passwd = readlineSync.question('please input your password: ',{hideEchoBack: true});
}

// Load MM config
let MM_CONFIG;
if (process.env.MM_CONFIG) {
Expand Down Expand Up @@ -78,6 +88,9 @@ try {
});
}
for(let i=0; i<keys.length; i++) {
if (args['encrypt-key']) {
keys[i] = CryptoJS.AES.decrypt(keys[i], passwd).toString(CryptoJS.enc.Utf8);
}
let ethWallet = new ethers.Wallet(keys[i]);
let syncWallet = await zksync.Wallet.fromEthSigner(ethWallet, syncProvider);
if (!(await syncWallet.isSigningKeySet())) {
Expand Down Expand Up @@ -551,7 +564,10 @@ async function setupPriceFeeds() {

async function cryptowatchWsSetup(cryptowatchMarketIds) {
// Set initial prices
const cryptowatchApiKey = process.env.CRYPTOWATCH_API_KEY || MM_CONFIG.cryptowatchApiKey;
let cryptowatchApiKey = process.env.CRYPTOWATCH_API_KEY || MM_CONFIG.cryptowatchApiKey;
if (args['encrypt-key']) {
cryptowatchApiKey = CryptoJS.AES.decrypt(cryptowatchApiKey, passwd).toString(CryptoJS.enc.Utf8)
}
const cryptowatchMarkets = await fetch("https://api.cryptowat.ch/markets?apikey=" + cryptowatchApiKey).then(r => r.json());
const cryptowatchMarketPrices = await fetch("https://api.cryptowat.ch/markets/prices?apikey=" + cryptowatchApiKey).then(r => r.json());
for (let i in cryptowatchMarketIds) {
Expand Down
36 changes: 36 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
"author": "",
"license": "ISC",
"dependencies": {
"crypto-js": "^4.1.1",
"dotenv": "^10.0.0",
"ethers": "^5.5.1",
"minimist": "^1.2.6",
"node-fetch": "^3.1.0",
"readline-sync": "^1.4.10",
"ws": "^8.2.3",
"zksync": "0.11.6"
},
Expand Down