Skip to content

Commit

Permalink
feat: add annotation generation from Writer
Browse files Browse the repository at this point in the history
  • Loading branch information
joaosantos15 committed Jul 25, 2020
1 parent 53dce3a commit dced064
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 74 deletions.
10 changes: 5 additions & 5 deletions build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"files": {
"main.css": "/static/css/main.62dceea5.chunk.css",
"main.js": "/static/js/main.11dfc34b.chunk.js",
"main.js.map": "/static/js/main.11dfc34b.chunk.js.map",
"main.js": "/static/js/main.d224a6b4.chunk.js",
"main.js.map": "/static/js/main.d224a6b4.chunk.js.map",
"runtime-main.js": "/static/js/runtime-main.0d1674f1.js",
"runtime-main.js.map": "/static/js/runtime-main.0d1674f1.js.map",
"static/js/2.344354a5.chunk.js": "/static/js/2.344354a5.chunk.js",
"static/js/2.344354a5.chunk.js.map": "/static/js/2.344354a5.chunk.js.map",
"static/js/2.0b7e9956.chunk.js": "/static/js/2.0b7e9956.chunk.js",
"static/js/2.0b7e9956.chunk.js.map": "/static/js/2.0b7e9956.chunk.js.map",
"index.html": "/index.html",
"precache-manifest.0a171aca7a1d1f41856a5345cc635505.js": "/precache-manifest.0a171aca7a1d1f41856a5345cc635505.js",
"precache-manifest.ed2a8cbb9926c6074e7de6298d459189.js": "/precache-manifest.ed2a8cbb9926c6074e7de6298d459189.js",
"service-worker.js": "/service-worker.js",
"static/css/main.62dceea5.chunk.css.map": "/static/css/main.62dceea5.chunk.css.map"
}
Expand Down
2 changes: 1 addition & 1 deletion build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<head><link href="/static/css/main.62dceea5.chunk.css" rel="stylesheet"></head><div id="modal-window"></div><script src="/static/js/runtime-main.0d1674f1.js"></script><script src="/static/js/2.344354a5.chunk.js"></script><script src="/static/js/main.11dfc34b.chunk.js"></script>
<head><link href="/static/css/main.62dceea5.chunk.css" rel="stylesheet"></head><div id="modal-window"></div><script src="/static/js/runtime-main.0d1674f1.js"></script><script src="/static/js/2.0b7e9956.chunk.js"></script><script src="/static/js/main.d224a6b4.chunk.js"></script>
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
self.__precacheManifest = (self.__precacheManifest || []).concat([
{
"revision": "92900a42d25de9137f86b05e15411cc9",
"revision": "c43fd54a4965b1996f5df30c1728ca00",
"url": "/index.html"
},
{
"revision": "44185631019193624aad",
"revision": "a28fa6831911fa925777",
"url": "/static/css/main.62dceea5.chunk.css"
},
{
"revision": "04457536c507f29703f5",
"url": "/static/js/2.344354a5.chunk.js"
"revision": "e2fc79eb562202cd9ed6",
"url": "/static/js/2.0b7e9956.chunk.js"
},
{
"revision": "44185631019193624aad",
"url": "/static/js/main.11dfc34b.chunk.js"
"revision": "a28fa6831911fa925777",
"url": "/static/js/main.d224a6b4.chunk.js"
},
{
"revision": "e52355ce7cf88029702e",
Expand Down
2 changes: 1 addition & 1 deletion build/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");

importScripts(
"/precache-manifest.0a171aca7a1d1f41856a5345cc635505.js"
"/precache-manifest.ed2a8cbb9926c6074e7de6298d459189.js"
);

self.addEventListener('message', (event) => {
Expand Down
2 changes: 2 additions & 0 deletions build/static/js/2.0b7e9956.chunk.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/static/js/2.0b7e9956.chunk.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions build/static/js/2.344354a5.chunk.js

This file was deleted.

1 change: 0 additions & 1 deletion build/static/js/2.344354a5.chunk.js.map

This file was deleted.

2 changes: 0 additions & 2 deletions build/static/js/main.11dfc34b.chunk.js

This file was deleted.

1 change: 0 additions & 1 deletion build/static/js/main.11dfc34b.chunk.js.map

This file was deleted.

2 changes: 2 additions & 0 deletions build/static/js/main.d224a6b4.chunk.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/static/js/main.d224a6b4.chunk.js.map

Large diffs are not rendered by default.

28 changes: 23 additions & 5 deletions src/Components/Writer.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
import React, { useEffect, useState } from 'react';
import { connectMetamask, signV4 } from '../services/ethereum'

import Annotation from '../services/Annotation'
import Logo from '../images/logo'
import { ModalContext } from '../Contexts/ModalProvider';

const Reader = ({ setPage }) => {
const [web3Enabled, setWeb3Enabled] = useState(false)
const [title, setTitle] = useState("nothing...")
const [commentContent, setCommentContent] = useState('')
const issueAnnotation = async() => {
const tweetInfo = window.location.href.split('/')

if(tweetInfo[2] !== 'twitter.com' && tweetInfo[4] !== 'status') {
alert('This only works on Tweet pages')
}

const tweetAuthor = tweetInfo[3]
const tweetId = tweetInfo[5]

let annotation = new Annotation({content: commentContent, issuerEthAddress:"0x123", tweetAuthor, tweetId})
await annotation.sign()
alert(JSON.stringify(annotation))
}



return (
<ModalContext.Consumer>
Expand All @@ -19,16 +37,16 @@ const Reader = ({ setPage }) => {
<h3>{`Comment Editor`}</h3>
</div>
<div className="modal-content__comment-editor">
<TerciaryButton
<TerciaryButton
label="< Back to reading"
onClick={() => setPage('reader')}
/>
<CommentEditor />
<CommentEditor commentContent={commentContent} setCommentContent={setCommentContent} />
</div>
<div className="modal-content__confirm">
<PrimaryButton
label="Comment"
onClick={() => setPage('reader')}
onClick={issueAnnotation}
/>
</div>
</div>
Expand All @@ -42,8 +60,8 @@ const Reader = ({ setPage }) => {
export default Reader;


const CommentEditor = ({ }) => {
const [commentContent, setCommentContent] = useState('')
const CommentEditor = ({ setCommentContent, commentContent }) => {

const updateCommentContent = (e) => {
setCommentContent(e.target.value)
}
Expand Down
32 changes: 32 additions & 0 deletions src/services/Annotation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { sign as metamaskSign } from './ethereum'

class Annotation {
constructor({ content, issuerEthAddress, tweetAuthor, tweetId }) {
this.payload = {
["@context"]: ["https://pan.network/annotation/v1"],
issuanceDate: new Date().toJSON(),
issuer: `urn:ethereum:${issuerEthAddress}`,
credentialSubject: {
annotation: content,
content: `uri:tweet:${tweetAuthor}/${tweetId}`
},
proof: {
created: this.issuanceDate,
proofPurpose: "PANSubmission",
type: "EthereumECDSA",
verificationMethod: "urn:ethereum:messageHash"
},
type: ["VerifiableCredential", "PANCredential"]
}
}
async sign() {
try {
const signed = await metamaskSign(this.payload)
this.payload.proof.jws = signed
} catch (e) {
console.error(e)
}
}
}

export default Annotation
58 changes: 8 additions & 50 deletions src/services/ethereum.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,18 @@ export const connectMetamask = () => {
return false
}

export const signV4 = () => {

// const msgParams = JSON.stringify({
// domain: {
// chainId: 1,
// name: 'Ether Mail',
// verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
// version: '1'
// },
// message: {
// contents: 'Hello, Bob!',
// from: {
// name: 'Cow',
// wallets: [
// '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
// '0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF'
// ]
// },
// to: [
// {
// name: 'Bob',
// wallets: [
// '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
// '0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57',
// '0xB0B0b0b0b0b0B000000000000000000000000000'
// ]
// }
// ]
// },
// primaryType: 'Mail',
// types: {
// EIP712Domain: [
// { name: 'name', type: 'string' },
// { name: 'version', type: 'string' },
// { name: 'chainId', type: 'uint256' },
// { name: 'verifyingContract', type: 'address' }
// ],
// Group: [{ name: 'name', type: 'string' }, { name: 'members', type: 'Person[]' }],
// Mail: [
// { name: 'from', type: 'Person' },
// { name: 'to', type: 'Person[]' },
// { name: 'contents', type: 'string' }
// ],
// Person: [{ name: 'name', type: 'string' }, { name: 'wallets', type: 'address[]' }]
// }
// });

const msg2 = { "@context": ["https://pan.network/annotation/v1"], "credentialSubject": { "annotation": "text..", "content": "uri:tweet:joaosantos/1281904943700619265" }, "issuanceDate": "2010-01-01T19:23:24Z", "issuer": "urn:ethereum:0xaBfEEA201208fcD0eE6a7073dFF0141dd7D7B04c", "proof": { "created": "2017-06-18T21:19:10Z", "proofPurpose": "PANSubmission", "type": "EthereumECDSA", "verificationMethod": "urn:ethereum:0xbdda0c603b93571e089c63d96ab4914e00198aa8fba40a0c394a949c5c3b549fa643651f407ce8378cf7505ea9563d03117691a56a6b7c9e22ac9fd983bc55b8" }, "type": ["VerifiableCredential", "PANCredential"] }
const msgString = JSON.stringify(msg2, Object.keys(msg2).sort());
export const sign = (message) => {
console.log("😬",message)
// const msgString = JSON.stringify(message, Object.keys(message).sort());
const msgString = JSON.stringify(message);

var msg = ethUtil.bufferToHex(new Buffer(msgString, 'utf8'))

console.log("🚨",msgString,"🍕", msg)

if(!window.ethereum.selectedAddress) {
connectMetamask()
return
}
var from = window.ethereum.selectedAddress

// var params = [from, msgParams]
Expand Down

0 comments on commit dced064

Please sign in to comment.