From 4d35bf3b9d99b9e5549a6774365ceb28e71475a9 Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Mon, 10 Jun 2019 20:24:06 -0400 Subject: [PATCH 1/2] Includes signing_ts into params for insert_comment --- schema/comments_ddl.sql | 3 ++- src/writes.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/schema/comments_ddl.sql b/schema/comments_ddl.sql index 5960824..af06eb8 100644 --- a/schema/comments_ddl.sql +++ b/schema/comments_ddl.sql @@ -14,6 +14,7 @@ CREATE TABLE IF NOT EXISTS COMMENT ( ParentId TEXT DEFAULT NULL, Signature TEXT DEFAULT NULL, Timestamp INTEGER NOT NULL, + SigningTs TEXT DEFAULT NULL, CONSTRAINT COMMENT_PRIMARY_KEY PRIMARY KEY (CommentId) ON CONFLICT IGNORE, CONSTRAINT COMMENT_SIGNATURE_SK UNIQUE (Signature) ON CONFLICT ABORT, CONSTRAINT COMMENT_CHANNEL_FK FOREIGN KEY (ChannelId) REFERENCES CHANNEL(ClaimId) @@ -22,7 +23,7 @@ CREATE TABLE IF NOT EXISTS COMMENT ( ON UPDATE CASCADE ON DELETE NO ACTION -- setting null implies comment is top level ); -ALTER TABLE COMMENT ADD COLUMN SigningTs TEXT DEFAULT NULL; +-- ALTER TABLE COMMENT ADD COLUMN SigningTs TEXT DEFAULT NULL; -- DROP TABLE IF EXISTS CHANNEL; CREATE TABLE IF NOT EXISTS CHANNEL( diff --git a/src/writes.py b/src/writes.py index 981ad1d..d293c8c 100644 --- a/src/writes.py +++ b/src/writes.py @@ -16,7 +16,7 @@ def create_comment(conn: sqlite3.Connection, comment: str, claim_id: str, channe try: comment_id = insert_comment( conn=conn, comment=comment, claim_id=claim_id, channel_id=channel_id, - signature=signature, parent_id=parent_id + signature=signature, parent_id=parent_id, signing_ts=signing_ts ) return get_comment_or_none(conn, comment_id) except sqlite3.IntegrityError as ie: From bdaa9b00d166357eeff2756a40687386b0423a3b Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Mon, 10 Jun 2019 23:51:23 -0400 Subject: [PATCH 2/2] fixes up code --- src/database.py | 5 ++--- src/writes.py | 6 ++++-- tests/database_test.py | 2 ++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/database.py b/src/database.py index 5ee10d9..c71bdff 100644 --- a/src/database.py +++ b/src/database.py @@ -94,9 +94,8 @@ def insert_comment(conn: sqlite3.Connection, claim_id: str = None, comment: str channel_id: str = None, signature: str = None, signing_ts: str = None, parent_id: str = None) -> str: timestamp = int(time.time()) - prehash = ':'.join((claim_id, comment, str(timestamp),)) - prehash = bytes(prehash.encode('utf-8')) - comment_id = nacl.hash.sha256(prehash).decode('utf-8') + prehash = b':'.join((claim_id.encode(), comment.encode(), str(timestamp).encode(),)) + comment_id = nacl.hash.sha256(prehash).decode() with conn: conn.execute( """ diff --git a/src/writes.py b/src/writes.py index d293c8c..8030cca 100644 --- a/src/writes.py +++ b/src/writes.py @@ -2,8 +2,10 @@ import logging import sqlite3 from src.database import get_comment_or_none -from src.database import insert_comment, insert_channel -from src.misc import validate_channel, validate_signature +from src.database import insert_comment +from src.database import insert_channel +from src.misc import validate_channel +from src.misc import validate_signature logger = logging.getLogger(__name__) diff --git a/tests/database_test.py b/tests/database_test.py index 39371e6..427b6a5 100644 --- a/tests/database_test.py +++ b/tests/database_test.py @@ -75,6 +75,7 @@ class TestCommentCreation(DatabaseTestCase): signing_ts='asdasd' ) self.assertIsNotNone(comment) + self.assertIn('signing_ts', comment) previous_id = comment['comment_id'] reply = create_comment( conn=self.conn, @@ -88,6 +89,7 @@ class TestCommentCreation(DatabaseTestCase): ) self.assertIsNotNone(reply) self.assertEqual(reply['parent_id'], comment['comment_id']) + self.assertIn('signing_ts', reply) def test04UsernameVariations(self): self.assertRaises(