-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from OriginTrail/feature/network-and-assertio…
…n-modules Network + Assertion Modules
- Loading branch information
Showing
15 changed files
with
302 additions
and
102 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const { assertionMetadata, calculateRoot, formatGraph } = require('assertion-tools'); | ||
|
||
class AssertionOperationsManager { | ||
constructor(services) { | ||
this.nodeApiService = services.nodeApiService; | ||
this.inputService = services.inputService; | ||
} | ||
|
||
/** | ||
* Formats the content provided, producing both a public and, if available, a private assertion. | ||
* | ||
* @param {Object} content - The content object containing optional public and private properties. | ||
* @returns {Promise<Object>} a promise that resolves with an object containing the | ||
* formatted public assertion and, if available, the private assertion. | ||
*/ | ||
async formatGraph(content) { | ||
return formatGraph(content); | ||
} | ||
|
||
/** | ||
* Calculates and returns the Merkle root of the public assertion from the provided content. | ||
* | ||
* @param {Object} content - The content object containing optional public and private properties. | ||
* @returns {Promise<String>} a promise that resolves with a string representing the | ||
* Merkle root of the formatted public assertion. | ||
*/ | ||
async getPublicAssertionId(content) { | ||
const assertions = await formatGraph(content); | ||
return calculateRoot(assertions.public); | ||
} | ||
|
||
/** | ||
* Calculates and returns the size in bytes of the public assertion from the provided content. | ||
* | ||
* @param {Object} content - The content object containing optional public and private properties. | ||
* @returns {Promise<Number>} a promise that resolves with a number representing the | ||
* size in bytes of the formatted public assertion. | ||
*/ | ||
async getSizeInBytes(content) { | ||
const assertions = await formatGraph(content); | ||
return assertionMetadata.getAssertionSizeInBytes(assertions.public); | ||
} | ||
|
||
/** | ||
* Calculates and returns the number of triples of the public assertion from the provided content. | ||
* | ||
* @param {Object} content - The content object containing optional public and private properties. | ||
* @returns {Promise<Number>} a promise that resolves with a number representing the | ||
* number of triples of the formatted public assertion. | ||
*/ | ||
async getTriplesNumber(content) { | ||
const assertions = await formatGraph(content); | ||
return assertionMetadata.getAssertionTriplesNumber(assertions.public); | ||
} | ||
|
||
/** | ||
* Calculates and returns the number of chunks of the public assertion from the provided content. | ||
* | ||
* @param {Object} content - The content object containing optional public and private properties. | ||
* @returns {Promise<Number>} a promise that resolves with a number representing the | ||
* number of chunks of the formatted public assertion. | ||
*/ | ||
async getChunksNumber(content) { | ||
const assertions = await formatGraph(content); | ||
return assertionMetadata.getAssertionChunksNumber(assertions.public); | ||
} | ||
} | ||
module.exports = AssertionOperationsManager; |
Oops, something went wrong.