-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add comments for buildFromReviseRatingProperties #195
Merged
amarts
merged 2 commits into
dhiway:develop
from
adi-a11y:add-comments-for-network-score
Mar 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -64,10 +64,7 @@ import { | |
resolveKey, | ||
signatureFromJson, | ||
} from '@cord.network/did' | ||
import { | ||
hashToUri, | ||
uriToIdentifier, | ||
} from '@cord.network/identifier' | ||
import { hashToUri, uriToIdentifier } from '@cord.network/identifier' | ||
import { Crypto, SDKErrors } from '@cord.network/utils' | ||
import { ConfigService } from '@cord.network/config' | ||
import * as Did from '@cord.network/did' | ||
|
@@ -274,7 +271,7 @@ async function createRatingObject( | |
messageId: string, | ||
chainSpace: SpaceUri, | ||
providerUri: DidUri, | ||
authorUri: DidUri, | ||
authorUri: DidUri | ||
): Promise<{ uri: RatingEntryUri; details: any }> { | ||
const ratingUri = await getUriForRatingEntry( | ||
entryDigest, | ||
|
@@ -349,7 +346,7 @@ async function createRatingObject( | |
export async function buildFromRatingProperties( | ||
rating: IRatingEntry, | ||
chainSpace: SpaceUri, | ||
authorUri: DidUri, | ||
authorUri: DidUri | ||
): Promise<{ uri: RatingEntryUri; details: IRatingDispatch }> { | ||
try { | ||
//validateRatingContent(rating.entry) | ||
|
@@ -368,7 +365,7 @@ export async function buildFromRatingProperties( | |
rating.messageId, | ||
chainSpace, | ||
Did.getDidUri(rating.entry.providerDid), | ||
authorUri, | ||
authorUri | ||
) | ||
|
||
const { providerId, entityId, ...chainEntry } = rating.entry | ||
|
@@ -428,7 +425,7 @@ export async function buildFromRatingProperties( | |
export async function buildFromRevokeRatingProperties( | ||
rating: IRatingRevokeEntry, | ||
chainSpace: SpaceUri, | ||
authorUri: DidUri, | ||
authorUri: DidUri | ||
): Promise<{ uri: RatingEntryUri; details: IRatingDispatch }> { | ||
try { | ||
validateRequiredFields([ | ||
|
@@ -445,7 +442,7 @@ export async function buildFromRevokeRatingProperties( | |
rating.entry.messageId, | ||
chainSpace, | ||
Did.getDidUri(rating.providerDid), | ||
authorUri, | ||
authorUri | ||
) | ||
|
||
details.entry = rating.entry | ||
|
@@ -458,10 +455,42 @@ export async function buildFromRevokeRatingProperties( | |
} | ||
} | ||
|
||
/** | ||
* Constructs a revised entry for a previously amended rating on the blockchain. | ||
* | ||
* This asynchronous function is responsible for building a rating object from revised rating properties. | ||
* It takes a rating entry, chain space URI, and author URI as parameters and returns a promise resolving | ||
* to an object containing the URI of the rating entry and its details. It verifies the signature of the amended rating, | ||
* validates required fields, and generates the necessary signatures for the revised entry. This is essential | ||
* for maintaining the integrity and trustworthiness of the rating system, especially in decentralized environments. | ||
* | ||
* This function is specifically designed for use by Rating Authors or Ledger/API Providers. | ||
* | ||
* @param rating - The rating revise entry to process. | ||
* This includes the original rating's digest, signature, and other relevant details. | ||
* @param chainSpace - The identifier of the blockchain space (as a URI) where the rating is being revoked. | ||
* This helps in pinpointing the exact location on the blockchain where the rating resides. | ||
* @param authorUri - The Decentralized Identifier (DID) URI of the author who is revoking the rating. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here - revoke or revise? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. Revised is the correct word. |
||
* This identifier is crucial for associating the revocation with the correct author. | ||
* @returns A promise resolving to an object with the following structure: | ||
uri: The URI of the rating entry. | ||
details: An object containing the details of the rating dispatch, including the entry and other metadata. | ||
|
||
* @throws { RatingPropertiesError } - if there is an error during the transformation process. | ||
* | ||
* @example | ||
* try { | ||
* const result = await buildFromReviseRatingProperties(ratingEntry, chainSpaceUri, authorUri); | ||
* console.log("Rating entry URI:", result.uri); | ||
* console.log("Rating details:", result.details); | ||
* } catch (error) { | ||
* console.error("Error building rating from revised properties:", error); | ||
* } | ||
*/ | ||
export async function buildFromReviseRatingProperties( | ||
rating: IRatingEntry, | ||
chainSpace: SpaceUri, | ||
authorUri: DidUri, | ||
authorUri: DidUri | ||
): Promise<{ uri: RatingEntryUri; details: IRatingDispatch }> { | ||
try { | ||
validateRequiredFields([ | ||
|
@@ -471,15 +500,15 @@ export async function buildFromReviseRatingProperties( | |
rating.entry.countOfTxn, | ||
rating.entry.totalEncodedRating, | ||
]) | ||
|
||
validateHexString(rating.entryDigest) | ||
const { uri, details } = await createRatingObject( | ||
rating.entryDigest, | ||
rating.entry.entityUid, | ||
rating.messageId, | ||
chainSpace, | ||
Did.getDidUri(rating.entry.providerDid), | ||
authorUri, | ||
authorUri | ||
) | ||
|
||
const { providerId, entityId, ...chainEntry } = rating.entry | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call it revoked? or revised?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. Revised is the correct word.