Skip to content

Commit 57f0e4b

Browse files
committed
adds initial e2ee filesharing with Fleek, AWS S3 (Scaffold bootstrappeed)
1 parent 8df768f commit 57f0e4b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+26742
-0
lines changed

.gitignore

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
packages/buidler/*.txt
2+
**/aws.json
3+
4+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
5+
**/node_modules
6+
packages/buidler/artifacts
7+
packages/react-app/src/contracts
8+
packages/buidler/cache
9+
10+
# dependencies
11+
/node_modules
12+
/.pnp
13+
.pnp.js
14+
15+
# testing
16+
coverage
17+
18+
# production
19+
build
20+
21+
# misc
22+
.DS_Store
23+
.env*
24+
25+
# debug
26+
npm-debug.log*
27+
yarn-debug.log*
28+
yarn-error.log*
29+
30+
.idea

README.md

+45
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,48 @@ We plan on using the following technologies/ protocols:
1414
* NFT standards
1515
* Fleek / Filecoin/ Textile storage solutions
1616
* Ethereum DIDs
17+
18+
19+
## quickstart
20+
21+
```bash
22+
git clone https://github.com/consensolabs/signchain
23+
24+
cd signchain
25+
```
26+
27+
```bash
28+
29+
yarn install
30+
31+
```
32+
33+
> you might get node-gyp errors, ignore them and run:
34+
35+
```bash
36+
37+
yarn start
38+
39+
```
40+
41+
> in a second terminal window:
42+
43+
```bash
44+
45+
yarn chain
46+
47+
```
48+
49+
> in a third terminal window:
50+
51+
```bash
52+
53+
yarn deploy
54+
55+
```
56+
57+
🔏 Edit your smart contract `YourContract.sol` in `packages/buidler/contracts`
58+
59+
📝 Edit your frontend `App.jsx` in `packages/react-app/src`
60+
61+
📱 Open http://localhost:3000 to see the app

package.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "@scaffold-eth/monorepo",
3+
"version": "1.0.0",
4+
"keywords": [
5+
"ethereum",
6+
"react",
7+
"uniswap",
8+
"workspaces",
9+
"yarn"
10+
],
11+
"private": true,
12+
"scripts": {
13+
"react-app:build": "yarn workspace @scaffold-eth/react-app build --max-old-space-size=12288",
14+
"react-app:eject": "yarn workspace @scaffold-eth/react-app eject",
15+
"react-app:start": "yarn workspace @scaffold-eth/react-app start",
16+
"react-app:test": "yarn workspace @scaffold-eth/react-app test",
17+
"build": "yarn workspace @scaffold-eth/react-app build --max-old-space-size=12288",
18+
"chain": "yarn workspace @scaffold-eth/buidler chain",
19+
"node": "yarn workspace @scaffold-eth/buidler chain",
20+
"test": "yarn workspace @scaffold-eth/buidler test",
21+
"start": "yarn workspace @scaffold-eth/react-app start",
22+
"compile": "yarn workspace @scaffold-eth/buidler compile",
23+
"deploy": "yarn workspace @scaffold-eth/buidler deploy",
24+
"watch": "yarn workspace @scaffold-eth/buidler watch",
25+
"accounts": "yarn workspace @scaffold-eth/buidler accounts",
26+
"balance": "yarn workspace @scaffold-eth/buidler balance",
27+
"send": "yarn workspace @scaffold-eth/buidler send",
28+
"ipfs": "yarn workspace @scaffold-eth/react-app ipfs",
29+
"surge": "yarn workspace @scaffold-eth/react-app surge",
30+
"s3": "yarn workspace @scaffold-eth/react-app s3",
31+
"ship": "yarn workspace @scaffold-eth/react-app ship",
32+
"generate": "cd packages/buidler && npx buidler generate",
33+
"account": "cd packages/buidler && npx buidler account",
34+
"flatten": "cd packages/buidler && npx buidler flatten"
35+
},
36+
"workspaces": {
37+
"packages": [
38+
"packages/*"
39+
]
40+
}
41+
}

packages/buidler/.eslintrc.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
env: {
3+
mocha: true,
4+
},
5+
extends: ["airbnb", "plugin:prettier/recommended"],
6+
plugins: ["babel"],
7+
rules: {
8+
"prettier/prettier": ["error"],
9+
"import/extensions": [
10+
"error",
11+
"ignorePackages",
12+
{
13+
js: "never",
14+
ts: "never",
15+
},
16+
],
17+
"import/prefer-default-export": "off",
18+
"prefer-destructuring": "off",
19+
"prefer-template": "off",
20+
"no-console": "off",
21+
"func-names": "off",
22+
},
23+
};

packages/buidler/buidler.config.js

+240
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
const { usePlugin } = require("@nomiclabs/buidler/config");
2+
const { utils } = require("ethers");
3+
const fs = require("fs");
4+
5+
usePlugin("@nomiclabs/buidler-waffle");
6+
7+
const { isAddress, getAddress, formatUnits, parseUnits } = utils;
8+
9+
/*
10+
📡 This is where you configure your deploy configuration for 🏗 scaffold-eth
11+
12+
check out `packages/scripts/deploy.js` to customize your deployment
13+
14+
out of the box it will auto deploy anything in the `contracts` folder and named *.sol
15+
plus it will use *.args for constructor args
16+
*/
17+
18+
//
19+
// Select the network you want to deploy to here:
20+
//
21+
const defaultNetwork = "localhost";
22+
23+
function mnemonic() {
24+
try {
25+
return fs.readFileSync("./mnemonic.txt").toString().trim();
26+
} catch (e) {
27+
if (defaultNetwork !== "localhost") {
28+
console.log("☢️ WARNING: No mnemonic file created for a deploy account. Try `yarn run generate` and then `yarn run account`.")
29+
}
30+
}
31+
return "";
32+
}
33+
34+
module.exports = {
35+
defaultNetwork,
36+
37+
// don't forget to set your provider like:
38+
// REACT_APP_PROVIDER=https://dai.poa.network in packages/react-app/.env
39+
// (then your frontend will talk to your contracts on the live network!)
40+
// (you will need to restart the `yarn run start` dev server after editing the .env)
41+
42+
networks: {
43+
localhost: {
44+
url: "http://localhost:8545",
45+
/*
46+
notice no mnemonic here? it will just use account 0 of the buidler node to deploy
47+
(you can put in a mnemonic here to set the deployer locally)
48+
*/
49+
},
50+
rinkeby: {
51+
url: "https://rinkeby.infura.io/v3/c954231486fa42ccb6d132b406483d14",//<---- YOUR INFURA ID! (or it won't work)
52+
accounts: {
53+
mnemonic: mnemonic(),
54+
},
55+
},
56+
mainnet: {
57+
url: "https://mainnet.infura.io/v3/c954231486fa42ccb6d132b406483d14",//<---- YOUR INFURA ID! (or it won't work)
58+
accounts: {
59+
mnemonic: mnemonic(),
60+
},
61+
},
62+
ropsten: {
63+
url: "https://ropsten.infura.io/v3/c954231486fa42ccb6d132b406483d14",//<---- YOUR INFURA ID! (or it won't work)
64+
accounts: {
65+
mnemonic: mnemonic(),
66+
},
67+
},
68+
xdai: {
69+
url: 'https://dai.poa.network',
70+
gasPrice: 1000000000,
71+
accounts: {
72+
mnemonic: mnemonic(),
73+
},
74+
},
75+
},
76+
solc: {
77+
version: "0.6.6",
78+
optimizer: {
79+
enabled: true,
80+
runs: 200,
81+
},
82+
},
83+
};
84+
85+
const DEBUG = false;
86+
87+
function debug(text) {
88+
if (DEBUG) {
89+
console.log(text);
90+
}
91+
}
92+
93+
task("generate", "Create a mnemonic for builder deploys", async (_, { ethers }) => {
94+
const bip39 = require("bip39")
95+
const hdkey = require('ethereumjs-wallet/hdkey');
96+
const mnemonic = bip39.generateMnemonic()
97+
if (DEBUG) console.log("mnemonic", mnemonic)
98+
const seed = await bip39.mnemonicToSeed(mnemonic)
99+
if (DEBUG) console.log("seed", seed)
100+
const hdwallet = hdkey.fromMasterSeed(seed);
101+
const wallet_hdpath = "m/44'/60'/0'/0/";
102+
const account_index = 0
103+
let fullPath = wallet_hdpath + account_index
104+
if (DEBUG) console.log("fullPath", fullPath)
105+
const wallet = hdwallet.derivePath(fullPath).getWallet();
106+
const privateKey = "0x" + wallet._privKey.toString('hex');
107+
if (DEBUG) console.log("privateKey", privateKey)
108+
var EthUtil = require('ethereumjs-util');
109+
const address = "0x" + EthUtil.privateToAddress(wallet._privKey).toString('hex')
110+
console.log("🔐 Account Generated as " + address + ".txt and set as mnemonic in packages/buidler")
111+
console.log("💬 Use 'yarn run account' to get more information about the deployment account.")
112+
113+
fs.writeFileSync("./" + address + ".txt", mnemonic.toString())
114+
fs.writeFileSync("./mnemonic.txt", mnemonic.toString())
115+
});
116+
117+
task("account", "Get balance informations for the deployment account.", async (_, { ethers }) => {
118+
const hdkey = require('ethereumjs-wallet/hdkey');
119+
const bip39 = require("bip39")
120+
let mnemonic = fs.readFileSync("./mnemonic.txt").toString().trim()
121+
if (DEBUG) console.log("mnemonic", mnemonic)
122+
const seed = await bip39.mnemonicToSeed(mnemonic)
123+
if (DEBUG) console.log("seed", seed)
124+
const hdwallet = hdkey.fromMasterSeed(seed);
125+
const wallet_hdpath = "m/44'/60'/0'/0/";
126+
const account_index = 0
127+
let fullPath = wallet_hdpath + account_index
128+
if (DEBUG) console.log("fullPath", fullPath)
129+
const wallet = hdwallet.derivePath(fullPath).getWallet();
130+
const privateKey = "0x" + wallet._privKey.toString('hex');
131+
if (DEBUG) console.log("privateKey", privateKey)
132+
var EthUtil = require('ethereumjs-util');
133+
const address = "0x" + EthUtil.privateToAddress(wallet._privKey).toString('hex')
134+
135+
var qrcode = require('qrcode-terminal');
136+
qrcode.generate(address);
137+
console.log("‍📬 Deployer Account is " + address)
138+
for (let n in config.networks) {
139+
//console.log(config.networks[n],n)
140+
try {
141+
142+
let provider = new ethers.providers.JsonRpcProvider(config.networks[n].url)
143+
let balance = (await provider.getBalance(address))
144+
console.log(" -- " + n + " -- -- -- 📡 ")
145+
console.log(" balance: " + ethers.utils.formatEther(balance))
146+
console.log(" nonce: " + (await provider.getTransactionCount(address)))
147+
} catch (e) {
148+
if (DEBUG) {
149+
console.log(e)
150+
}
151+
}
152+
}
153+
154+
});
155+
156+
157+
async function addr(ethers, addr) {
158+
if (isAddress(addr)) {
159+
return getAddress(addr);
160+
}
161+
const accounts = await ethers.provider.listAccounts();
162+
if (accounts[addr] !== undefined) {
163+
return accounts[addr];
164+
}
165+
throw `Could not normalize address: ${addr}`;
166+
}
167+
168+
task("accounts", "Prints the list of accounts", async (_, { ethers }) => {
169+
const accounts = await ethers.provider.listAccounts();
170+
accounts.forEach((account) => console.log(account));
171+
});
172+
173+
task("blockNumber", "Prints the block number", async (_, { ethers }) => {
174+
const blockNumber = await ethers.provider.getBlockNumber();
175+
console.log(blockNumber);
176+
});
177+
178+
task("balance", "Prints an account's balance")
179+
.addPositionalParam("account", "The account's address")
180+
.setAction(async (taskArgs, { ethers }) => {
181+
const balance = await ethers.provider.getBalance(
182+
await addr(ethers, taskArgs.account)
183+
);
184+
console.log(formatUnits(balance, "ether"), "ETH");
185+
});
186+
187+
function send(signer, txparams) {
188+
return signer.sendTransaction(txparams, (error, transactionHash) => {
189+
if (error) {
190+
debug(`Error: ${error}`);
191+
}
192+
debug(`transactionHash: ${transactionHash}`);
193+
// checkForReceipt(2, params, transactionHash, resolve)
194+
});
195+
}
196+
197+
task("send", "Send ETH")
198+
.addParam("from", "From address or account index")
199+
.addOptionalParam("to", "To address or account index")
200+
.addOptionalParam("amount", "Amount to send in ether")
201+
.addOptionalParam("data", "Data included in transaction")
202+
.addOptionalParam("gasPrice", "Price you are willing to pay in gwei")
203+
.addOptionalParam("gasLimit", "Limit of how much gas to spend")
204+
205+
.setAction(async (taskArgs, { network, ethers }) => {
206+
const from = await addr(ethers, taskArgs.from);
207+
debug(`Normalized from address: ${from}`);
208+
const fromSigner = await ethers.provider.getSigner(from);
209+
210+
let to;
211+
if (taskArgs.to) {
212+
to = await addr(ethers, taskArgs.to);
213+
debug(`Normalized to address: ${to}`);
214+
}
215+
216+
const txRequest = {
217+
from: await fromSigner.getAddress(),
218+
to,
219+
value: parseUnits(
220+
taskArgs.amount ? taskArgs.amount : "0",
221+
"ether"
222+
).toHexString(),
223+
nonce: await fromSigner.getTransactionCount(),
224+
gasPrice: parseUnits(
225+
taskArgs.gasPrice ? taskArgs.gasPrice : "1.001",
226+
"gwei"
227+
).toHexString(),
228+
gasLimit: taskArgs.gasLimit ? taskArgs.gasLimit : 24000,
229+
chainId: network.config.chainId,
230+
};
231+
232+
if (taskArgs.data !== undefined) {
233+
txRequest.data = taskArgs.data;
234+
debug(`Adding data to payload: ${txRequest.data}`);
235+
}
236+
debug(txRequest.gasPrice / 1000000000 + " gwei");
237+
debug(JSON.stringify(txRequest, null, 2));
238+
239+
return send(fromSigner, txRequest);
240+
});

0 commit comments

Comments
 (0)