diff --git a/lib/feed-v1/index.js b/lib/feed-v1/index.js index 57d080b..574b078 100644 --- a/lib/feed-v1/index.js +++ b/lib/feed-v1/index.js @@ -44,7 +44,6 @@ function isEmptyObject(obj) { * @property {Record} metadata.tangles * @property {string} metadata.type * @property {string} metadata.who - * @property {number} metadata.when * @property {string} sig */ @@ -58,7 +57,6 @@ function isEmptyObject(obj) { * @typedef {Object} CreateOpts * @property {*} content * @property {string} type - * @property {number} when * @property {Keys} keys * @property {Record} tangles */ @@ -143,7 +141,6 @@ function create(opts) { tangles, type: opts.type, who: stripAuthor(opts.keys.id), - when: +opts.when, }, sig: '', } @@ -176,7 +173,6 @@ function createRoot(keys, type) { tangles: {}, type, who: stripAuthor(keys.id), - when: 0, }, sig: '', } diff --git a/lib/feed-v1/validation.js b/lib/feed-v1/validation.js index ede7c70..85630fb 100644 --- a/lib/feed-v1/validation.js +++ b/lib/feed-v1/validation.js @@ -142,13 +142,6 @@ function validateTangleRoot(msg, tangleId) { } } -function validateWhen(msg) { - if (msg.metadata.when && typeof msg.metadata.when !== 'number') { - // prettier-ignore - return new Error('invalid message: `when` is not a number, on feed: ' + msg.metadata.who); - } -} - function validateType(type) { if (!type || typeof type !== 'string') { // prettier-ignore @@ -190,7 +183,6 @@ function validateSync(msg, tangle, msgHash, rootHash) { let err if ((err = validateShape(msg))) return err if ((err = validateWho(msg))) return err - if ((err = validateWhen(msg))) return err if (msgHash === rootHash) { if ((err = validateTangleRoot(msg))) return err } else { diff --git a/lib/plugin.js b/lib/plugin.js index 3d059f6..e0735a4 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -231,7 +231,7 @@ exports.init = function initDB(peer, config) { const tangleTemplates = opts.tangles ?? [] tangleTemplates.push(feedRootHash) const tangles = populateTangles(tangleTemplates) - const fullOpts = { when: Date.now(), ...opts, tangles, keys } + const fullOpts = { ...opts, tangles, keys } // If opts ask for encryption, encrypt and put ciphertext in opts.content const recps = fullOpts.content.recps diff --git a/test/add.test.js b/test/add.test.js index 2cc16d0..eaab35d 100644 --- a/test/add.test.js +++ b/test/add.test.js @@ -24,13 +24,12 @@ test('add()', async (t) => { const rootHash = FeedV1.getMsgHash(rootMsg) const recRoot = await p(peer.db.add)(rootMsg, rootHash) - t.equals(recRoot.msg.metadata.when, 0, 'root msg added') + t.equals(recRoot.msg.metadata.size, 0, 'root msg added') const tangle = new FeedV1.Tangle(rootHash) tangle.add(recRoot.hash, recRoot.msg) const inputMsg = FeedV1.create({ keys, - when: 1514517067954, type: 'post', content: { text: 'This is the first post!' }, tangles: { diff --git a/test/create.test.js b/test/create.test.js index c04a684..ec40750 100644 --- a/test/create.test.js +++ b/test/create.test.js @@ -72,7 +72,6 @@ test('add() forked then create() merged', async (t) => { const msg3 = FeedV1.create({ keys, - when: Date.now(), type: 'post', content: { text: '3rd post forked from 1st' }, tangles: { diff --git a/test/erase.test.js b/test/erase.test.js index 40545aa..454a4ea 100644 --- a/test/erase.test.js +++ b/test/erase.test.js @@ -20,7 +20,7 @@ test('erase', async (t) => { await peer.db.loaded() - const rootHash = 'PpkBfa8C4sB8wHrqiNmHqe' + const rootHash = 'PGwQiuwFnB7EySQHBit2mA' const msgHashes = [] for (let i = 0; i < 5; i++) { const rec = await p(peer.db.create)({ diff --git a/test/feed-v1-create.test.js b/test/feed-v1-create.test.js index 5bf9301..707869b 100644 --- a/test/feed-v1-create.test.js +++ b/test/feed-v1-create.test.js @@ -12,18 +12,16 @@ tape('FeedV1.createRoot()', (t) => { t.equals(rootMsg.metadata.size, 0, 'size') t.equals(rootMsg.metadata.type, 'post', 'type') t.equals(rootMsg.metadata.who, FeedV1.stripAuthor(keys.id), 'who') - t.equals(rootMsg.metadata.when, 0, 'when') t.deepEquals(rootMsg.metadata.tangles, {}, 'tangles') rootHash = FeedV1.getMsgHash(rootMsg) - t.equals(rootHash, 'PpkBfa8C4sB8wHrqiNmHqe', 'root hash') + t.equals(rootHash, 'PGwQiuwFnB7EySQHBit2mA', 'root hash') t.end() }) tape('FeedV1.create()', (t) => { const keys = generateKeypair('alice') const content = { text: 'Hello world!' } - const when = 1652037377204 const tangle1 = new FeedV1.Tangle(rootHash) tangle1.add(rootHash, rootMsg) @@ -35,11 +33,10 @@ tape('FeedV1.create()', (t) => { tangles: { [rootHash]: tangle1, }, - when, }) t.deepEquals( Object.keys(msg1.metadata), - ['proof', 'size', 'tangles', 'type', 'who', 'when'], + ['proof', 'size', 'tangles', 'type', 'who'], 'metadata fields' ) t.equals( @@ -53,12 +50,11 @@ tape('FeedV1.create()', (t) => { t.equals(msg1.metadata.tangles[rootHash].depth, 1, 'tangle depth') t.deepEquals(msg1.metadata.tangles[rootHash].prev, [rootHash], 'tangle prev') t.deepEquals(msg1.metadata.size, 23, 'metadata.size') - t.equals(typeof msg1.metadata.when, 'number', 'metadata.when') t.deepEqual(msg1.content, content, 'content is correct') console.log(msg1) - const msgHash1 = 'YWbEeMtcU4eNwF6uJVTrKE' + const msgHash1 = 'M31mLeV2wNDwp9ZRkkF8pL' t.equals( FeedV1.getMsgId(msg1), @@ -80,11 +76,10 @@ tape('FeedV1.create()', (t) => { tangles: { [rootHash]: tangle2, }, - when: when + 1, }) t.deepEquals( Object.keys(msg2.metadata), - ['proof', 'size', 'tangles', 'type', 'who', 'when'], + ['proof', 'size', 'tangles', 'type', 'who'], 'metadata keys' ) t.equals( @@ -98,14 +93,13 @@ tape('FeedV1.create()', (t) => { t.deepEquals(msg2.metadata.tangles[rootHash].prev, [msgHash1], 'tangle prev') t.deepEquals(msg2.metadata.proof, 'XuZEzH1Dhy1yuRMcviBBcN', 'metadata.proof') t.deepEquals(msg2.metadata.size, 21, 'metadata.size') - t.equals(typeof msg2.metadata.when, 'number', 'metadata.when') t.deepEqual(msg2.content, content2, 'content is correct') console.log(msg2) t.deepEqual( FeedV1.getMsgId(msg2), - 'ppppp:message/v1/4mjQ5aJu378cEu6TksRG3uXAiKFiwGjYQtWAjfVjDAJW/post/R9XRXBL1ntSKRrrk86bhn8', + 'ppppp:message/v1/4mjQ5aJu378cEu6TksRG3uXAiKFiwGjYQtWAjfVjDAJW/post/MHLPVrHFzCLXVeXUkY1W4a', 'getMsgId' ) @@ -114,7 +108,6 @@ tape('FeedV1.create()', (t) => { tape('create() handles DAG tips correctly', (t) => { const keys = generateKeypair('alice') - const when = 1652037377204 const tangle = new FeedV1.Tangle(rootHash) tangle.add(rootHash, rootMsg) @@ -125,12 +118,11 @@ tape('create() handles DAG tips correctly', (t) => { tangles: { [rootHash]: tangle, }, - when: when + 1, }) const msgHash1 = FeedV1.getMsgHash(msg1) t.deepEquals( msg1.metadata.tangles[rootHash].prev, - ['PpkBfa8C4sB8wHrqiNmHqe'], + ['PGwQiuwFnB7EySQHBit2mA'], 'msg1.prev is root' ) @@ -143,7 +135,6 @@ tape('create() handles DAG tips correctly', (t) => { tangles: { [rootHash]: tangle, }, - when: when + 2, }) t.deepEquals( msg2A.metadata.tangles[rootHash].prev, @@ -158,7 +149,6 @@ tape('create() handles DAG tips correctly', (t) => { tangles: { [rootHash]: tangle, }, - when: when + 2, }) const msgHash2B = FeedV1.getMsgHash(msg2B) t.deepEquals( @@ -176,7 +166,6 @@ tape('create() handles DAG tips correctly', (t) => { tangles: { [rootHash]: tangle, }, - when: when + 3, }) const msgHash3 = FeedV1.getMsgHash(msg3) t.deepEquals( @@ -197,7 +186,6 @@ tape('create() handles DAG tips correctly', (t) => { tangles: { [rootHash]: tangle, }, - when: when + 4, }) t.deepEquals( msg4.metadata.tangles[rootHash].prev, diff --git a/test/feed-v1-invalid-prev.test.js b/test/feed-v1-invalid-prev.test.js index 173351d..a890096 100644 --- a/test/feed-v1-invalid-prev.test.js +++ b/test/feed-v1-invalid-prev.test.js @@ -19,7 +19,6 @@ tape('invalid msg with non-array prev', (t) => { tangles: { [rootHash]: tangle, }, - when: 1652030001000, }) msg.metadata.tangles[rootHash].prev = null const msgHash = FeedV1.getMsgHash(msg) @@ -47,7 +46,6 @@ tape('invalid msg with bad prev', (t) => { tangles: { [rootHash]: tangle, }, - when: 1652030001000, }) const msgHash1 = FeedV1.getMsgHash(msg1) tangle.add(msgHash1, msg1) @@ -59,7 +57,6 @@ tape('invalid msg with bad prev', (t) => { tangles: { [rootHash]: tangle, }, - when: 1652030002000, }) msg2.metadata.tangles[rootHash].depth = 1 msg2.metadata.tangles[rootHash].prev = [1234] @@ -92,7 +89,6 @@ tape('invalid msg with URI in prev', (t) => { tangles: { [rootHash]: tangle, }, - when: 1652030001000, }) const msgHash1 = FeedV1.getMsgHash(msg1) tangle.add(msgHash1, msg1) @@ -104,7 +100,6 @@ tape('invalid msg with URI in prev', (t) => { tangles: { [rootHash]: tangle, }, - when: 1652030002000, }) const msgHash2 = FeedV1.getMsgHash(msg2) const randBuf = Buffer.alloc(16).fill(16) @@ -139,7 +134,6 @@ tape('invalid msg with unknown prev', (t) => { tangles: { [rootHash]: tangle, }, - when: 1652030001000, }) const msgHash1 = FeedV1.getMsgHash(msg1) tangle.add(msgHash1, msg1) @@ -151,7 +145,6 @@ tape('invalid msg with unknown prev', (t) => { tangles: { [rootHash]: tangle, }, - when: 1652030001000, }) const unknownMsgHash = FeedV1.getMsgHash(unknownMsg) @@ -166,7 +159,6 @@ tape('invalid msg with unknown prev', (t) => { tangles: { [rootHash]: tangle2 }, - when: 1652030002000, }) const msgHash2 = FeedV1.getMsgHash(msg2) @@ -197,7 +189,6 @@ tape('invalid feed msg with a different who', (t) => { tangles: { [rootHash]: feedTangle, }, - when: 1652030002000, }) const msgHash = FeedV1.getMsgHash(msg) @@ -222,7 +213,6 @@ tape('invalid feed msg with a different type', (t) => { tangles: { [rootHash]: feedTangle, }, - when: 1652030002000, }) const msgHash = FeedV1.getMsgHash(msg) diff --git a/test/feed-v1-invalid-type.test.js b/test/feed-v1-invalid-type.test.js index 0462cc1..b113bed 100644 --- a/test/feed-v1-invalid-type.test.js +++ b/test/feed-v1-invalid-type.test.js @@ -10,7 +10,6 @@ tape('invalid type not a string', (t) => { FeedV1.create({ keys, content: { text: 'Hello world!' }, - when: 1652037377204, type: 123, }) }, @@ -28,7 +27,6 @@ tape('invalid type with "/" character', (t) => { FeedV1.create({ keys, content: { text: 'Hello world!' }, - when: 1652037377204, type: 'group/init', }) }, @@ -46,7 +44,6 @@ tape('invalid type with "*" character', (t) => { FeedV1.create({ keys, content: { text: 'Hello world!' }, - when: 1652037377204, type: 'star*', }) }, @@ -64,7 +61,6 @@ tape('invalid type too short', (t) => { FeedV1.create({ keys, content: { text: 'Hello world!' }, - when: 1652037377204, type: 'xy', }) }, @@ -82,7 +78,6 @@ tape('invalid type too long', (t) => { FeedV1.create({ keys, content: { text: 'Hello world!' }, - when: 1652037377204, type: 'a'.repeat(120), }) }, diff --git a/test/feed-v1-lipmaa.test.js b/test/feed-v1-lipmaa.test.js index 6a4a347..e2be01d 100644 --- a/test/feed-v1-lipmaa.test.js +++ b/test/feed-v1-lipmaa.test.js @@ -5,7 +5,6 @@ const { generateKeypair } = require('./util') tape('lipmaa prevs', (t) => { const keys = generateKeypair('alice') const content = { text: 'Hello world!' } - const when = 1652037377204 const rootMsg = FeedV1.createRoot(keys, 'post') const rootHash = FeedV1.getMsgHash(rootMsg) @@ -19,7 +18,6 @@ tape('lipmaa prevs', (t) => { tangles: { [rootHash]: tangle, }, - when: when + 1, }) const msgHash1 = FeedV1.getMsgHash(msg1) tangle.add(msgHash1, msg1) @@ -33,7 +31,6 @@ tape('lipmaa prevs', (t) => { tangles: { [rootHash]: tangle, }, - when: when + 2, }) const msgHash2 = FeedV1.getMsgHash(msg2) tangle.add(msgHash2, msg2) @@ -47,7 +44,6 @@ tape('lipmaa prevs', (t) => { tangles: { [rootHash]: tangle, }, - when: when + 3, }) const msgHash3 = FeedV1.getMsgHash(msg3) tangle.add(msgHash3, msg3) @@ -65,7 +61,6 @@ tape('lipmaa prevs', (t) => { tangles: { [rootHash]: tangle, }, - when: when + 4, }) const msgHash4 = FeedV1.getMsgHash(msg4) tangle.add(msgHash4, msg4) @@ -79,7 +74,6 @@ tape('lipmaa prevs', (t) => { tangles: { [rootHash]: tangle, }, - when: when + 5, }) const msgHash5 = FeedV1.getMsgHash(msg5) tangle.add(msgHash5, msg5) @@ -93,7 +87,6 @@ tape('lipmaa prevs', (t) => { tangles: { [rootHash]: tangle, }, - when: when + 6, }) const msgHash6 = FeedV1.getMsgHash(msg6) tangle.add(msgHash6, msg6) @@ -107,7 +100,6 @@ tape('lipmaa prevs', (t) => { tangles: { [rootHash]: tangle, }, - when: when + 7, }) const msgHash7 = FeedV1.getMsgHash(msg7) tangle.add(msgHash7, msg7) diff --git a/test/feed-v1-tangles.test.js b/test/feed-v1-tangles.test.js index 246f570..9f6a749 100644 --- a/test/feed-v1-tangles.test.js +++ b/test/feed-v1-tangles.test.js @@ -23,7 +23,6 @@ tape('simple multi-author tangle', (t) => { tangles: { [rootHashA]: tangleA, }, - when: 1652030001000, }) const msgHash1 = FeedV1.getMsgHash(msg1) t.deepEquals( @@ -43,7 +42,6 @@ tape('simple multi-author tangle', (t) => { [rootHashB]: tangleB, [msgHash1]: tangleX, }, - when: 1652030002000, }) t.deepEquals( @@ -73,7 +71,6 @@ tape('lipmaa in multi-author tangle', (t) => { const keysB = generateKeypair('bob') const content = { text: 'Hello world!' } - const when = 1652037377204 const rootMsgA = FeedV1.createRoot(keysA, 'post') const rootHashA = FeedV1.getMsgHash(rootMsgA) @@ -92,7 +89,6 @@ tape('lipmaa in multi-author tangle', (t) => { tangles: { [rootHashA]: tangleA, }, - when: when + 1, }) const msgHash1 = FeedV1.getMsgHash(msg1) tangleA.add(msgHash1, msg1) @@ -113,7 +109,6 @@ tape('lipmaa in multi-author tangle', (t) => { [rootHashB]: tangleB, [msgHash1]: tangleThread, }, - when: when + 2, }) const msgHash2 = FeedV1.getMsgHash(msg2) tangleB.add(msgHash2, msg2) @@ -133,7 +128,6 @@ tape('lipmaa in multi-author tangle', (t) => { [rootHashB]: tangleB, [msgHash1]: tangleThread, }, - when: when + 3, }) const msgHash3 = FeedV1.getMsgHash(msg3) tangleB.add(msgHash3, msg3) @@ -153,7 +147,6 @@ tape('lipmaa in multi-author tangle', (t) => { [rootHashA]: tangleA, [msgHash1]: tangleThread, }, - when: when + 4, }) const msgHash4 = FeedV1.getMsgHash(msg4) tangleB.add(msgHash4, msg4) diff --git a/test/feed-v1-validate.test.js b/test/feed-v1-validate.test.js index c6221ac..4c8dc96 100644 --- a/test/feed-v1-validate.test.js +++ b/test/feed-v1-validate.test.js @@ -33,7 +33,6 @@ tape('validate 2nd msg with existing root', (t) => { tangles: { [rootHash]: tangle, }, - when: 1652030001000, }) const msgHash1 = FeedV1.getMsgHash(msg1) tangle.add(msgHash1, msg1) @@ -61,7 +60,6 @@ tape('validate 2nd forked msg', (t) => { [rootHash]: tangle, }, existing: new Map(), - when: 1652030001000, }) const msgHash1A = FeedV1.getMsgHash(msg1A) @@ -72,7 +70,6 @@ tape('validate 2nd forked msg', (t) => { tangles: { [rootHash]: tangle, }, - when: 1652030002000, }) const msgHash1B = FeedV1.getMsgHash(msg1B) @@ -100,7 +97,6 @@ tape('invalid msg with unknown previous', (t) => { tangles: { [rootHash]: tangle, }, - when: 1652030001000, }) const msgHash1 = FeedV1.getMsgHash(msg1) diff --git a/test/on-record-added.test.js b/test/on-record-added.test.js index 2dd3e7d..08df6a5 100644 --- a/test/on-record-added.test.js +++ b/test/on-record-added.test.js @@ -33,7 +33,7 @@ test('onRecordAdded', async (t) => { t.equal(listened.length, 2) t.deepEquals(listened[0].msg.content, null, 'root') - t.deepEquals(listened[0].msg.metadata.when, 0, 'root') + t.deepEquals(listened[0].msg.metadata.size, 0, 'root') t.deepEquals(listened[1], rec1, 'actual record') remove()