Skip to content

Commit

Permalink
Merge pull request #1285 from OriginTrail/prerelease/mainnet
Browse files Browse the repository at this point in the history
Update OT-JSON sort method
  • Loading branch information
djordjekovac authored Jun 17, 2020
2 parents 91c8113 + 57cb387 commit 2a6f6fd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions modules/ImportUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ class ImportUtilities {
if (!sortedDataset) {
sortedDataset = Utilities.copyObject(dataset);
}
ImportUtilities.removeGraphPermissionedData(sortedDataset['@graph']);
delete sortedDataset.signature;
return web3.eth.accounts.recover(JSON.stringify(sortedDataset), dataset.signature.value);
}
Expand Down
25 changes: 22 additions & 3 deletions modules/OtJsonUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ class OtJsonUtilities {
return dataset.datasetHeader.OTJSONVersion;
}

static _repackDataset(dataset) {
return {
'@id': dataset['@id'],
'@type': dataset['@type'],
datasetHeader: dataset.datasetHeader,
'@graph': JSON.parse(Utilities.sortObjectRecursively(dataset['@graph'])),
signature: dataset.signature,
};
}

/**
* Formats the dataset graph hash so that the graph hash can be calculated properly for that
* OT-JSON version
Expand Down Expand Up @@ -111,7 +121,10 @@ class OtJsonUtilities {
return datasetCopy;
case '1.1':
datasetCopy = Utilities.copyObject(dataset);
return JSON.parse(Utilities.sortObjectRecursively(datasetCopy));
if (datasetCopy.datasetHeader.transpilationInfo) {
return JSON.parse(Utilities.sortObjectRecursively(datasetCopy));
}
return this._repackDataset(datasetCopy);
default:
throw new Error('Unsupported ot-json version!');
}
Expand Down Expand Up @@ -300,7 +313,10 @@ class OtJsonUtilities {
return undefined;
case '1.1':
datasetCopy = Utilities.copyObject(dataset);
return JSON.parse(Utilities.sortObjectRecursively(datasetCopy));
if (datasetCopy.datasetHeader.transpilationInfo) {
return JSON.parse(Utilities.sortObjectRecursively(datasetCopy));
}
return this._repackDataset(datasetCopy);
default:
throw new Error('Unsupported ot-json version!');
}
Expand All @@ -323,7 +339,10 @@ class OtJsonUtilities {
return undefined;
case '1.1':
datasetCopy = Utilities.copyObject(dataset);
return JSON.parse(Utilities.sortObjectRecursively(datasetCopy));
if (datasetCopy.datasetHeader.transpilationInfo) {
return JSON.parse(Utilities.sortObjectRecursively(datasetCopy));
}
return this._repackDataset(datasetCopy);
default:
throw new Error('Unsupported ot-json version!');
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "origintrail_node",
"version": "4.1.3",
"version": "4.1.4",
"description": "OriginTrail node",
"main": ".eslintrc.js",
"config": {
Expand Down

0 comments on commit 2a6f6fd

Please sign in to comment.