From fa70749348b33a97179cc6736a20ce40f05fbc33 Mon Sep 17 00:00:00 2001 From: sethvincent Date: Thu, 31 Aug 2023 12:12:01 -0700 Subject: [PATCH 1/3] add hash in attachments to observation schema --- proto/observation/v5.proto | 1 + schema/observation/v5.json | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/proto/observation/v5.proto b/proto/observation/v5.proto index dd807e29..6823a321 100644 --- a/proto/observation/v5.proto +++ b/proto/observation/v5.proto @@ -32,6 +32,7 @@ message Observation_5 { bytes driveId = 1; string name = 2; AttachmentType type = 3; + string hash = 4; } repeated Attachment attachments = 8; diff --git a/schema/observation/v5.json b/schema/observation/v5.json index 912e7f40..4cf55e81 100644 --- a/schema/observation/v5.json +++ b/schema/observation/v5.json @@ -100,6 +100,10 @@ "UNRECOGNIZED": "future attachment type" }, "enum": ["photo", "video", "audio", "UNRECOGNIZED"] + }, + "hash": { + "type": "string", + "description": "SHA256 hash of the attachment" } }, "required": ["driveId", "name", "type"] From e9a2147a28d2379b9f57dce337bdf5c3dcda4fa0 Mon Sep 17 00:00:00 2001 From: sethvincent Date: Thu, 31 Aug 2023 14:56:46 -0700 Subject: [PATCH 2/3] fix tests and build --- schema/observation/v5.json | 2 +- src/lib/decode-conversions.ts | 4 ++-- src/lib/encode-converstions.ts | 1 + test/fixtures/cached.js | 5 ++++- test/fixtures/good-docs-completed.js | 1 + 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/schema/observation/v5.json b/schema/observation/v5.json index 4cf55e81..318860a6 100644 --- a/schema/observation/v5.json +++ b/schema/observation/v5.json @@ -106,7 +106,7 @@ "description": "SHA256 hash of the attachment" } }, - "required": ["driveId", "name", "type"] + "required": ["driveId", "name", "type", "hash"] } }, "tags": { diff --git a/src/lib/decode-conversions.ts b/src/lib/decode-conversions.ts index 9bd50e65..43b59a1a 100644 --- a/src/lib/decode-conversions.ts +++ b/src/lib/decode-conversions.ts @@ -55,8 +55,8 @@ export const convertObservation: ConvertFunction<'observation'> = ( ...jsonSchemaCommon, ...rest, refs: message.refs?.map(({ id }) => ({ id: id.toString('hex') })), - attachments: message.attachments?.map(({ driveId, name, type }) => { - return { driveId: driveId.toString('hex'), name, type } + attachments: message.attachments?.map(({ driveId, name, type, hash }) => { + return { driveId: driveId.toString('hex'), name, type, hash } }), tags: convertTags(message.tags), metadata: message.metadata || {}, diff --git a/src/lib/encode-converstions.ts b/src/lib/encode-converstions.ts index 15f85ad2..d053e3bf 100644 --- a/src/lib/encode-converstions.ts +++ b/src/lib/encode-converstions.ts @@ -83,6 +83,7 @@ export const convertObservation: ConvertFunction<'observation'> = ( driveId: Buffer.from(attachment.driveId, 'hex'), name: attachment.name, type: attachment.type, + hash: attachment.hash, } }) diff --git a/test/fixtures/cached.js b/test/fixtures/cached.js index 58c5b950..63a4363d 100644 --- a/test/fixtures/cached.js +++ b/test/fixtures/cached.js @@ -10,7 +10,10 @@ export const cachedValues = { coreId: randomBytes(32).toString('hex'), createdAt: date, updatedAt: date, - attachments: { driveId: randomBytes(32).toString('hex') }, + attachments: { + driveId: randomBytes(32).toString('hex'), + hash: randomBytes(32).toString('hex'), + }, metadata: { position: { timestamp: date, diff --git a/test/fixtures/good-docs-completed.js b/test/fixtures/good-docs-completed.js index f48f1116..f0927a2c 100644 --- a/test/fixtures/good-docs-completed.js +++ b/test/fixtures/good-docs-completed.js @@ -25,6 +25,7 @@ export const goodDocsCompleted = [ name: 'myFile', type: 'photo', driveId: cachedValues.attachments.driveId, + hash: cachedValues.attachments.hash, }, ], tags: { From 1021818e84a1c0292c8054fb9de6b61facc30e44 Mon Sep 17 00:00:00 2001 From: sethvincent Date: Wed, 6 Sep 2023 13:45:22 -0700 Subject: [PATCH 3/3] set attachment hash protobuf to bytes, convert in encode/decode --- proto/observation/v5.proto | 2 +- src/lib/decode-conversions.ts | 2 +- src/lib/encode-converstions.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/proto/observation/v5.proto b/proto/observation/v5.proto index 6823a321..fe154b83 100644 --- a/proto/observation/v5.proto +++ b/proto/observation/v5.proto @@ -32,7 +32,7 @@ message Observation_5 { bytes driveId = 1; string name = 2; AttachmentType type = 3; - string hash = 4; + bytes hash = 4; } repeated Attachment attachments = 8; diff --git a/src/lib/decode-conversions.ts b/src/lib/decode-conversions.ts index 43b59a1a..81fb63aa 100644 --- a/src/lib/decode-conversions.ts +++ b/src/lib/decode-conversions.ts @@ -56,7 +56,7 @@ export const convertObservation: ConvertFunction<'observation'> = ( ...rest, refs: message.refs?.map(({ id }) => ({ id: id.toString('hex') })), attachments: message.attachments?.map(({ driveId, name, type, hash }) => { - return { driveId: driveId.toString('hex'), name, type, hash } + return { driveId: driveId.toString('hex'), name, type, hash: hash.toString('hex') } }), tags: convertTags(message.tags), metadata: message.metadata || {}, diff --git a/src/lib/encode-converstions.ts b/src/lib/encode-converstions.ts index d053e3bf..c95fc58a 100644 --- a/src/lib/encode-converstions.ts +++ b/src/lib/encode-converstions.ts @@ -83,7 +83,7 @@ export const convertObservation: ConvertFunction<'observation'> = ( driveId: Buffer.from(attachment.driveId, 'hex'), name: attachment.name, type: attachment.type, - hash: attachment.hash, + hash: Buffer.from(attachment.hash, 'hex'), } })