Skip to content

buildFromRatingProperties

buildFromRatingProperties(rating, chainSpace, authorUri): Promise<object>

Constructs a rating entry for dispatch to a blockchain, complete with validation and digital signature.

This function is responsible for taking a raw rating entry, validating its content, and ensuring it is correctly signed. It generates a unique URI for the rating, which encapsulates its identity on the blockchain. The function is primarily used by Rating Authors or Ledger/API Providers to ensure that the ratings they produce are valid, signed, and ready for dispatch to the specified blockchain space.

Parameters

rating: IRatingEntry

The raw rating entry that needs to be processed. It should include all necessary details like entityId, messageId, entryDigest, and providerSignature.

chainSpace: space:cord:${string}

Identifier for the blockchain space where the rating will be stored. This helps in routing the rating to the correct blockchain environment.

authorUri: did:cord:3${string}

The Decentralized Identifier (DID) URI of the author. This is used for signing the rating and linking it to its author.

Returns

Promise<object>

  • A promise that resolves to an object containing:
    • uri: A unique URI representing the rating entry on the blockchain.
    • details: An object containing the processed rating entry details ready for dispatch.

details

details: IRatingDispatch

uri

uri: RatingEntryUri

Throws

  • Thrown if there’s an issue with the rating’s content, signature, or any required fields.

Example

// Example of a rating entry object
const ratingEntry = {
entry: {
entityId: 'entity123',
// ... other rating entry properties ...
},
messageId: 'msg-123',
entryDigest: '0xabcdef12345',
providerSignature: {
// ... signature data ...
},
// ... other rating entry properties ...
};
// Usage
const chainSpace = 'chainSpace123';
const authorUri = 'did:example:author123';
try {
const result = await buildFromRatingProperties(ratingEntry, chainSpace, authorUri, signCallback);
console.log('Rating entry URI:', result.uri);
console.log('Rating entry details:', result.details);
} catch (error) {
console.error('Error building rating entry:', error);
}

Source

network-score/src/Scoring.ts:346