Skip to content

Commit ec9e90b

Browse files
committed
updates
1 parent d84ea71 commit ec9e90b

3 files changed

Lines changed: 32 additions & 13 deletions

File tree

src/chat/chatLogic.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import { store, authn } from 'solid-logic'
99
import * as ns from '../ns'
1010
import * as $rdf from 'rdflib' // pull in first avoid cross-refs
1111
import * as utils from '../utils'
12+
import { signMsg } from '../signature'
13+
14+
const SEC = 'https://w3id.org/security#' // Proof, VerificationMethod
15+
const CERT = 'http://www.w3.org/ns/auth/cert#' // PrivatKey, PublicKey
1216

1317
/* The Solid logic for a 'LongChat'
1418
*/
@@ -51,22 +55,31 @@ export class ChatChannel {
5155

5256
const me = authn.currentUser() // If already logged on
5357

58+
const msg = {}
5459
if (oldMsg) { // edit message replaces old one
5560
sts.push($rdf.st(mostRecentVersion(oldMsg), ns.dct('isReplacedBy'), message, chatDocument))
61+
// do we need to rebuild oldMsg signaturen ?
5662
if (deleteIt) {
5763
sts.push($rdf.st(message, ns.schema('dateDeleted'), dateStamp, chatDocument))
64+
msg['dateDeleted'] = dateStamp
5865
}
5966
} else { // link new message to channel
6067
sts.push($rdf.st(this.channel, ns.wf('message'), message, chatDocument))
6168
}
6269
sts.push(
6370
$rdf.st(message, ns.sioc('content'), store.literal(text), chatDocument)
6471
)
72+
msg['content'] = text
73+
6574
sts.push(
6675
$rdf.st(message, ns.dct('created'), dateStamp, chatDocument)
6776
)
77+
msg['created'] = dateStamp
6878
if (me) {
6979
sts.push($rdf.st(message, ns.foaf('maker'), me, chatDocument))
80+
msg['maker'] = me
81+
// privateKey the cached private key of me, cache should be deleted after a certain time
82+
sts.push($rdf.st(message, $rdf.sym(`${SEC}Proof`), $rdf.sym(signMsg(msg, privateKey[me]), chatDocument)))
7083
}
7184
try {
7285
await store.updater.update([], sts)

src/chat/message.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import * as pad from '../pad'
1818
import * as style from '../style'
1919
import * as utils from '../utils'
2020
import * as widgets from '../widgets'
21+
import { verifySignature } from '../signature'
2122

2223
const dom = window.document
2324
const messageBodyStyle = style.messageBodyStyle
@@ -114,7 +115,19 @@ export function renderMessageRow (channelObject, message, fresh, options, userCo
114115
const date = store.any(message, ns.dct('created'))
115116
const latestVersion = mostRecentVersion(message)
116117
const content = store.any(latestVersion, ns.sioc('content'))
117-
118+
const signature = store.any(message, $rdf.sym(`${SEC}Proof`))
119+
120+
// verify signature
121+
msg= {}
122+
msg['id'] = message
123+
msg['created'] = created
124+
// this is not correct.
125+
// If the message has been edited/deleted we must verify the latest message and may be the intermediate ones
126+
msg['content'] = content
127+
msg['maker'] = creator
128+
129+
// pubKey could be store in a cache for all makers
130+
if(!verifySignature(signature, msg, pubKey[creator])) throw new Error()
118131
const originalMessage = originalVersion(message)
119132
const edited = !message.sameTerm(originalMessage)
120133

src/chat/signature.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,7 @@ export function serializeMsg (msg: UnsignedMsg): string {
7272
/* if (!validateMsg(msg))
7373
throw new Error("can't serialize message with wrong or missing properties") */
7474

75-
return JSON.stringify([
76-
0,
77-
msg.pubkey,
78-
msg.created_at,
79-
msg.kind,
80-
msg.tags,
81-
msg.content
82-
])
75+
return JSON.stringify(msg)
8376
}
8477

8578
export function getMsgHash (message: UnsignedMsg): string {
@@ -109,11 +102,11 @@ const isRecord = (obj: unknown): obj is Record<string, unknown> => obj instanceo
109102
return true
110103
} */
111104

112-
export function verifySignature (message: Message): boolean {
105+
export function verifySignature (sig, message: Message, pubKey): boolean {
113106
return schnorr.verify(
114-
message.sig,
115-
getMsgHash(message)
116-
// message.pubkey
107+
sig,
108+
getMsgHash(message),
109+
pubkey
117110
)
118111
}
119112

0 commit comments

Comments
 (0)