Skip to content

Commit

Permalink
Merge pull request #1 from signchain/threadDb-integration
Browse files Browse the repository at this point in the history
This PR adds threadDb for user-registration and document-storage
  • Loading branch information
koshikraj authored Nov 26, 2020
2 parents 42f30f3 + 783aa9e commit 94465de
Show file tree
Hide file tree
Showing 14 changed files with 1,062 additions and 154 deletions.
12 changes: 1 addition & 11 deletions packages/buidler/contracts/Signchain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,15 @@ contract Signchain is DocumentRegistry, SigningModule {
_;
}

function signAndShareDocument(bytes32 documentHash, string memory title, string memory documentLocation,
string[] memory key, address[] memory users, address[] memory signers,
function signAndShareDocument(bytes32 documentHash, string memory title, address[] memory signers,
uint nonce, bytes memory signature, address notary) public payable {

uploadDocument(
documentHash,
documentLocation,
key,
users);

if(notary!= address(0)) {
require(msg.value == notaryFee, "Invalid Notary Fee");
notarizedDocs[documentHash] = Notarize(notary, msg.value, false);
}

addDocument(documentHash, title, signers);

signDocument(documentHash, nonce, signature);

}

function notarizeDocument(bytes32 documentHash, uint nonce, bytes memory signature) isNotary public {
Expand Down
6 changes: 0 additions & 6 deletions packages/buidler/test/Signchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ describe("Signchain", function () {
const document = await contractInstance.connect(account1).signAndShareDocument(
docHash,
"test Doc",
"doc location",
["AesEncKeyPartyA","AesEncKeyPartyB"],
[account1._address,account2._address],
[account1._address,account2._address],
replayNonce,
signature,
Expand Down Expand Up @@ -84,9 +81,6 @@ describe("Signchain", function () {
const document = await contractInstance.connect(account1).signAndShareDocument(
docHash,
"test Doc",
"doc location",
["AesEncKeyPartyA","AesEncKeyPartyB"],
[account1._address,account2._address],
[account1._address, notary._address],
replayNonce,
signature,
Expand Down
1 change: 1 addition & 0 deletions packages/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@ethersproject/providers": "^5.0.5",
"@ethersproject/units": "^5.0.2",
"@fleekhq/fleek-storage-js": "^1.0.2",
"@textile/hub": "^1.0.0",
"@ramp-network/ramp-instant-sdk": "^1.8.1",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
Expand Down
85 changes: 40 additions & 45 deletions packages/react-app/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Profile from "./components/Profile";
import Layout from "./components/Layout";
import Steps from './components/Stepper/Steps'
import Verify from './components/Verify/Verify'
import Database from "./components/database/Database";
import { INFURA_ID, ETHERSCAN_KEY } from "./constants";

const Ceramic = require('@ceramicnetwork/ceramic-http-client').default;
Expand Down Expand Up @@ -89,6 +90,7 @@ function App() {
}, [loadWeb3Modal, address]);

const [route, setRoute] = useState();

useEffect(() => {
console.log("SETTING ROUTE",window.location.pathname)
setRoute(window.location.pathname)
Expand Down Expand Up @@ -123,7 +125,7 @@ function App() {
<div className="App">

<Switch>

<Route exact path="/db" component={Database} />
<Route exact path="/" render={(props) =>
<SignUpForm
address={address}
Expand Down Expand Up @@ -152,19 +154,17 @@ function App() {
/>}/>

<Layout
address={address}
localProvider={userProvider}
userProvider={userProvider}
mainnetProvider={mainnetProvider}
price={price}
web3Modal={web3Modal}
loadWeb3Modal={loadWeb3Modal}
logoutOfWeb3Modal={logoutOfWeb3Modal}
blockExplorer={blockExplorer}

address={address}
localProvider={userProvider}
userProvider={userProvider}
mainnetProvider={mainnetProvider}
price={price}
web3Modal={web3Modal}
loadWeb3Modal={loadWeb3Modal}
logoutOfWeb3Modal={logoutOfWeb3Modal}
blockExplorer={blockExplorer}
>

{/* <Steps/> */}
{/* <Steps/> */}
<Route exact path="/sign" render={(props) =>
<Steps
address={address}
Expand All @@ -174,38 +174,33 @@ function App() {
userProvider={userProvider}
{...props}
/>}/>
<Route exact path="/dashboard" render={(props) =>
<Dashboard

/>}/>
<Route exact path="/verify" render={(props) =>
<Verify
address={address}
tx={tx}
writeContracts={writeContracts}
readContracts={readContracts}
userProvider={userProvider}
{...props}
/>}/>

<Route exact path="/documents" render={(props) =>
<Documents
address={address}
tx={tx}
writeContracts={writeContracts}
userProvider={userProvider}
{...props}
/>}/>
<Route exact path="/profile" render={(props) =>
<Profile
address={address}
tx={tx}
writeContracts={writeContracts}
{...props}
ceramic={ceramic}
idx={idx}
/>}/>

<Route exact path="/dashboard" render={(props) => <Dashboard/>}/>
<Route exact path="/verify" render={(props) =>
<Verify
address={address}
tx={tx}
writeContracts={writeContracts}
readContracts={readContracts}
userProvider={userProvider}
{...props}
/>}/>
<Route exact path="/documents" render={(props) =>
<Documents
address={address}
tx={tx}
writeContracts={writeContracts}
userProvider={userProvider}
{...props}
/>}/>
<Route exact path="/profile" render={(props) =>
<Profile
address={address}
tx={tx}
writeContracts={writeContracts}
{...props}
ceramic={ceramic}
idx={idx}
/>}/>
</Layout>
</Switch>
</div>
Expand Down
60 changes: 37 additions & 23 deletions packages/react-app/src/components/Documents.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* eslint-disable */
import React, { useEffect, useState } from "react";
import { Button, Icon, Loader, Table, Modal, Step } from "semantic-ui-react";
import { InfoCircleOutlined, FieldTimeOutlined, EditOutlined } from "@ant-design/icons";
import { Badge } from "antd";
import {authorizeUser, getAllUsers, getAllFile, downloadFiles} from "../lib/threadDb";

const index = require("../lib/e2ee");

import { Collapse } from "antd";
const userType = { party: 0, notary: 1 };

Expand All @@ -13,6 +14,8 @@ const { Panel } = Collapse;

export default function Documents(props) {
const password = localStorage.getItem("password");
const loggedUser = localStorage.getItem("USER");
const userInfo = JSON.parse(loggedUser)

const [open, setOpen] = useState(false);
const [caller, setCaller] = useState({});
Expand All @@ -21,46 +24,56 @@ export default function Documents(props) {
const [docInfo, setDocInfo] = useState({});
const [loading, setLoading] = useState(false);
const [downloading, setDownloading] = useState(null);
const [dbClient,setDBClient] = useState(null)
const [identity, setIdentity] = useState(null)


useEffect(() => {
if (props.writeContracts) {
props.writeContracts.Signchain.on("DocumentSigned", (author, oldValue, newValue, event) => {
getAllDoc();
});
props.writeContracts.Signchain.on("DocumentNatarized", (author, oldValue, newValue, event) => {
getAllDoc();
});
getAllDoc();
setSigner(props.userProvider.getSigner());
index.getAllUsers(props.address, props.tx, props.writeContracts).then(result => {
setCaller(result.caller);
});

authorizeUser(password).then((client)=>{
setDBClient(client)
props.writeContracts.Signchain.on("DocumentSigned", (author, oldValue, newValue, event) => {
getAllDoc(client);
});
props.writeContracts.Signchain.on("DocumentNatarized", (author, oldValue, newValue, event) => {
getAllDoc(client);
});
getAllDoc(client);
setSigner(props.userProvider.getSigner());
getAllUsers(client, userInfo.publicKey).then(result => {
setCaller(result.caller);
});
})
}
}, [props.writeContracts]);


const getAllDoc = async () => {
const getAllDoc = async (client) => {
setLoading(true);
const result = await index.getAllFile(props.tx, props.writeContracts, props.address);
if (result.length > 0) {
setDocs(result);
const userInfo = JSON.parse(loggedUser)
const doc = await getAllFile(client,userInfo.publicKey, props.tx, props.writeContracts, props.address)
if (doc.length > 0) {
setDocs(doc);
}
setLoading(false);
};

const downloadFile = (name, docHash) => {

setDownloading(docHash);
index.downloadFile(name, docHash, password, props.tx, props.writeContracts).then(result => {setDownloading(null)});
const downloadFile = (name, key, location) => {
setDownloading(name);
console.log("docment:",location)
downloadFiles(name, key, userInfo.email, location, password)
.then(result => {setDownloading(null)});
};

const signDocument = async docHash => {
const result = await index.attachSignature(docHash, props.tx, props.writeContracts, props.userProvider.getSigner());
const result = await index.attachSignature(docHash, props.tx, props.writeContracts,
props.userProvider.getSigner());
};

const notarizeDocument = async docHash => {
const result = await index.notarizeDoc(docHash, props.tx, props.writeContracts, props.userProvider.getSigner());
const result = await index.notarizeDoc(docHash, props.tx, props.writeContracts,
props.userProvider.getSigner());
};

return (
Expand Down Expand Up @@ -133,7 +146,8 @@ export default function Documents(props) {
)}
</Table.Cell>
<Table.Cell collapsing textAlign="right">
<Button loading={downloading === value.hash} icon="download" onClick={() => downloadFile(value.title, value.hash)} />
<Button loading={downloading === value.hash} icon="download" onClick={() => downloadFile(value.title,
value.key, value.documentLocation)} />
</Table.Cell>
</Table.Row>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-app/src/components/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Layout } from "antd";
const { Content } = Layout;

export default function layout(props) {
console.log(props);
//console.log(props);

let history = useHistory()

Expand Down
33 changes: 19 additions & 14 deletions packages/react-app/src/components/Stepper/Steps.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
/* eslint-disable */

import React, {useEffect, useState} from 'react';
import Dashboard from '../Dashboard'
import 'antd/dist/antd.css';
import './stepper.css';
import { Steps, Button, message } from 'antd';
import { Grid, Image } from 'semantic-ui-react'
import SelectFiles from './SelectFiles'
import SelectParties from './SelectParties'
import Preview from './Preview'

const index = require('../../lib/e2ee.js')
import {authorizeUser, getAllUsers, registerDoc} from "../../lib/threadDb";

const { Step } = Steps;

Expand Down Expand Up @@ -52,6 +50,7 @@ const steps = [

const stepper = props => {
const password = localStorage.getItem("password");
const loggedUser = localStorage.getItem("USER");

const [signer, setSigner] = useState({});
const fileStorage = ["AWS", "Fleek"];
Expand All @@ -65,20 +64,24 @@ const stepper = props => {
const [storageType, setStorage] = useState("AWS");
const [fileInfo, setFileInfo] = useState({});
const [title, setTitle] = useState(null);
const [dbClient, setDbClient] = useState(null);

let fileInputRef = React.createRef();

useEffect(() => {
if (props.writeContracts) {
props.writeContracts.Signchain.on("DocumentSigned", (author, oldValue, newValue, event) => {
});
props.writeContracts.Signchain.on("DocumentSigned", (author, oldValue, newValue, event) => {});
setSigner(props.userProvider.getSigner());
index.getAllUsers(props.address, props.tx, props.writeContracts).then(result => {

setUsers(result.userArray);
setCaller(result.caller);
setNotaries(result.notaryArray);
});
const userInfo = JSON.parse(loggedUser)
authorizeUser(password).then(client=>{
setDbClient(client)
getAllUsers(client, userInfo.publicKey).then(result => {
console.log("USERS::",result)
setUsers(result.userArray);
setCaller(result.caller);
setNotaries(result.notaryArray);
});
})
}
}, [props.writeContracts]);

Expand Down Expand Up @@ -134,17 +137,19 @@ const stepper = props => {
onClick={() => {
const allParties = parties;
allParties.push(caller);
index.registerDoc(
registerDoc(
allParties,
fileInfo.fileHash,
fileInfo.cipherKey,
title,
fileInfo.fileKey,
fileInfo.fileName,
setSubmitting,
props.tx,
props.writeContracts,
signer,
docNotary,
dbClient,
props.tx,
props.writeContracts,
);
}}
className="button"
Expand Down
Loading

0 comments on commit 94465de

Please sign in to comment.