Skip to content

Commit

Permalink
Merge pull request #3 from signchain/threadDb-signature-integration
Browse files Browse the repository at this point in the history
Stores document signing on threadDb
  • Loading branch information
koshikraj authored Dec 8, 2020
2 parents 94465de + a5c8d41 commit af946eb
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 73 deletions.
10 changes: 10 additions & 0 deletions packages/buidler/contracts/Signchain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,14 @@ contract Signchain is DocumentRegistry, SigningModule {

}

function saveNotarizeDoc(bytes32 documentHash, address notary) public payable{
require(msg.value == notaryFee, "Invalid Notary Fee");
notarizedDocs[documentHash] = Notarize(notary, msg.value, false);
}

function notarizeDoc(bytes32 documentHash) public {
notarizedDocs[documentHash].notarized = true;
payable(address(msg.sender)).transfer(notarizedDocs[documentHash].notaryFee);
emit DocumentNatarized(documentHash, now, msg.sender);
}
}
2 changes: 1 addition & 1 deletion packages/react-app/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function App() {
loadWeb3Modal();
}
if(address){
init(address).then(data => console.log(idx))
//init(address).then(data => console.log(idx))
}
}, [loadWeb3Modal, address]);

Expand Down
25 changes: 13 additions & 12 deletions packages/react-app/src/components/Documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { useEffect, useState } from "react";
import { Button, Icon, Loader, Table, Modal, Step } from "semantic-ui-react";
import { Badge } from "antd";
import {authorizeUser, getAllUsers, getAllFile, downloadFiles} from "../lib/threadDb";
import {authorizeUser, getAllUsers, getAllFile, downloadFiles, attachSignature, notarizeDoc} from "../lib/threadDb";

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

Expand Down Expand Up @@ -52,7 +52,7 @@ export default function Documents(props) {
const getAllDoc = async (client) => {
setLoading(true);
const userInfo = JSON.parse(loggedUser)
const doc = await getAllFile(client,userInfo.publicKey, props.tx, props.writeContracts, props.address)
const doc = await getAllFile(client,userInfo.publicKey, props.address, props.tx, props.writeContracts)
if (doc.length > 0) {
setDocs(doc);
}
Expand All @@ -62,18 +62,17 @@ export default function Documents(props) {
const downloadFile = (name, key, location) => {
setDownloading(name);
console.log("docment:",location)
downloadFiles(name, key, userInfo.email, location, password)
downloadFiles(name, key, userInfo.address, location, password)
.then(result => {setDownloading(null)});
};

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

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

return (
Expand Down Expand Up @@ -111,7 +110,7 @@ export default function Documents(props) {
</span>
</Table.Cell>

<Table.Cell>{new Date(value.timestamp).toDateString()}</Table.Cell>
<Table.Cell>{value.timestamp}</Table.Cell>

<Table.Cell>
{" "}
Expand All @@ -129,12 +128,14 @@ export default function Documents(props) {

<Table.Cell>
{value.notary === caller.address && !value.notarySigned ? (
<Button basic color="blue" icon labelPosition="left" onClick={() => notarizeDocument(value.hash)}>
<Button basic color="blue" icon labelPosition="left" onClick={() => notarizeDocument(value.docId,
value.hash)}>
<Icon name="signup" />
Notarize
</Button>
) : !value.partySigned ? (
<Button basic color="blue" icon labelPosition="left" onClick={() => signDocument(value.hash)}>
<Button basic color="blue" icon labelPosition="left" onClick={() => signDocument(value.hash,
value.docId)}>
<Icon name="signup" />
Sign Document
</Button>
Expand Down
8 changes: 3 additions & 5 deletions packages/react-app/src/components/Stepper/Steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,15 @@ const stepper = props => {
allParties.push(caller);
registerDoc(
allParties,
fileInfo.fileHash,
fileInfo.cipherKey,
fileInfo,
title,
fileInfo.fileKey,
fileInfo.fileName,
setSubmitting,
signer,
docNotary,
dbClient,
caller,
props.tx,
props.writeContracts,
props.writeContracts
);
}}
className="button"
Expand Down
40 changes: 36 additions & 4 deletions packages/react-app/src/components/database/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ export default function Database(){
address: { type: 'string'},
publicKey: { type: 'string'},
userType: { type: 'number'},
documentId: {
nonce: {type:'number'},
documentInfo: {
type:'array',
items: {
type: 'string'
type: 'object',
properties: {
documentId: {type:'string'},
signatureId: {type:'string'}
}
}
}
},
Expand All @@ -39,6 +44,7 @@ export default function Database(){
type: 'object',
properties: {
_id: {type:'string'},
title: {type:'string'},
documentHash : {type: 'string'},
fileLocation: {type: 'string'},
fileName: {type: 'string'},
Expand All @@ -47,14 +53,39 @@ export default function Database(){
items :{
type: 'object',
properties:{
email: {type: 'string'},
key: {type:'string'}
address: {type: 'string'},
cipherKey: {type:'string'}
}
}
}
},
}

const signatureDetails = {
$schema: 'http://json-schema.org/draft-07/schema#',
title: 'SignatureDetails',
type: 'object',
properties: {
_id: {type:'string'},
signers:{
type:'array',
items: {type:'string'}
},
signature: {
type: 'array',
items: {
type:'object',
properties:{
signer: {type:'string'}, //user address
signatureDigest: {type: 'string'},
timeStamp: {type: 'string'},
nonce: {type: 'number'}
}
},
}
}
}

const setThreadDb = async ()=>{
const userAuth = await createUserAuth(keyInfo.key,keyInfo.secret)
const privateKey = await PrivateKey.fromRandom()
Expand Down Expand Up @@ -84,6 +115,7 @@ export default function Database(){
console.log("Creating tables!!!")
const result1 = await dbClient.newCollection(threadID, {name:'RegisterUser', schema: registrationSchema})
const result2 = await dbClient.newCollection(threadID, {name:'Document', schema: documentSchema})
await dbClient.newCollection(threadID, {name:'SignatureDetails', schema: signatureDetails})
console.log("Tables created!!:")
setThreadID(threadID)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-app/src/lib/e2ee.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export const uploadDoc = async function(file, password, setSubmitting, storageTy
setSubmitting(false)
setFileInfo({
cipherKey: cipherKey,
fileKey: fileKey,
fileLocation: fileKey,
fileHash: fileHash,
fileName: file.name,
fileFormat: fileFormat
Expand Down
Loading

0 comments on commit af946eb

Please sign in to comment.