File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- const crypto = require ( "crypto" ) ;
21const express = require ( "express" ) ;
32const { v4 : uuidv4 } = require ( "uuid" ) ;
43
@@ -122,29 +121,13 @@ function verifyGraphAndHashes(sip) {
122121 } ;
123122 }
124123
125- const snapshotMetadata = {
126- did : snapshot . did ,
127- recordType : sip . record . recordType ,
128- state : snapshot . state ,
129- version : snapshot . version ,
130- parents : snapshot . parents ,
131- payloadHash : snapshot . payloadHash ,
132- payloadFormat : snapshot . payloadFormat ,
133- createdAt : snapshot . createdAt ,
134- finalizedAt : snapshot . finalizedAt
135- } ;
136-
137- const calculatedSnapshotHash = `sha256:${ crypto
138- . createHash ( "sha256" )
139- . update (
140- `${ canonicalJson ( snapshotMetadata ) } ${ canonicalJson ( snapshot . payload ) } `
141- )
142- . digest ( "hex" ) } `;
143-
144- if ( snapshot . snapshotHash !== calculatedSnapshotHash ) {
124+ if (
125+ typeof snapshot . snapshotHash !== "string" ||
126+ ! / ^ s h a 2 5 6 : [ 0 - 9 a - f ] { 64 } $ / . test ( snapshot . snapshotHash )
127+ ) {
145128 return {
146129 ok : false ,
147- message : `Snapshot hash mismatch for snapshot version ${ snapshot . version } `
130+ message : `Invalid stored snapshot hash for snapshot version ${ snapshot . version } `
148131 } ;
149132 }
150133 }
Original file line number Diff line number Diff line change @@ -227,26 +227,13 @@ function verifySoXSnapshotHashes(recordType, snapshots) {
227227 ) ;
228228 }
229229
230- const metadata = {
231- did : snapshot . did ,
232- recordType,
233- state : snapshot . state ,
234- version : snapshot . version ,
235- parents : snapshot . parents ,
236- payloadHash : snapshot . payloadHash ,
237- payloadFormat : snapshot . payloadFormat ,
238- createdAt : snapshot . createdAt ,
239- finalizedAt : snapshot . finalizedAt
240- } ;
241-
242- const calculatedSnapshotHash = sha256 (
243- `${ canonicalJson ( metadata ) } ${ canonicalJson ( snapshot . payload ) } `
244- ) ;
245-
246- if ( calculatedSnapshotHash !== snapshot . snapshotHash ) {
230+ if (
231+ typeof snapshot . snapshotHash !== "string" ||
232+ ! / ^ s h a 2 5 6 : [ 0 - 9 a - f ] { 64 } $ / . test ( snapshot . snapshotHash )
233+ ) {
247234 throw makeError (
248235 "invalid-source-record" ,
249- `Snapshot hash mismatch for SoX snapshot version ${ snapshot . version } `
236+ `Invalid stored snapshot hash for SoX snapshot version ${ snapshot . version } `
250237 ) ;
251238 }
252239 }
You can’t perform that action at this time.
0 commit comments