Skip to content
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

network-score: change methods to suit the need of API spec #176

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 35 additions & 36 deletions demo/src/network-score-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { addNetworkMember } from './utils/createAuthorities'
import { createAccount } from './utils/createAccount'

async function main() {
const networkAddress = 'ws://127.0.0.1:9944'
const networkAddress = process.env.NETWORK_ADDRESS ? process.env.NETWORK_ADDRESS : 'ws://127.0.0.1:9944';
Cord.ConfigService.set({ submitTxResolveOn: Cord.Chain.IS_IN_BLOCK })
await Cord.connect(networkAddress)
const devAuthorIdentity = Cord.Utils.Crypto.makeKeypairFromUri(
'//Alice',
process.env.ANCHOR_URI ? process.env.ANCHOR_URI : '//Alice',
'sr25519'
)
console.log(`\n🌐 Network Score Initial Setup`)
Expand Down Expand Up @@ -135,7 +135,7 @@ async function main() {
console.log(`\n⏳ Network Rating Transaction Flow`)

console.log(`\n💠 Write Rating - (Genesis) Credit Entry `)
let ratingContent: Cord.IRatingContent = {
let ratingContent: IRatingContent = {
entityUid: Cord.Utils.UUID.generate(),
entityId: 'Gupta Kirana Store',
providerUid: Cord.Utils.UUID.generate(),
Expand All @@ -150,17 +150,19 @@ async function main() {
depth: null,
colors: true,
})
const entryDigest = Cord.Utils.Crypto.hashObjectAsHexStr(ratingContent);
const { totalRating, ...restOfRating} = ratingContent;

let transformedEntry: IRatingEntry = {
entry: {
...restOfRating,
providerDid: networkProviderDid.uri.replace('did:cord:', ''),
totalEncodedRating: Math.round(totalRating * 10),
},
messageId: Cord.Utils.UUID.generate(),
entryDigest,
};

let transformedEntry = await Cord.Score.buildFromContentProperties(
ratingContent,
networkProviderDid.uri,
async ({ data }) => ({
signature: networkProviderKeys.assertionMethod.sign(data),
keyType: networkProviderKeys.assertionMethod.type,
keyUri: `${networkProviderDid.uri}${networkProviderDid.assertionMethod![0].id
}` as Cord.DidResourceUri,
})
)
console.log(`\n🌐 Rating Information to API endpoint (/write-ratings) `)
console.dir(transformedEntry, {
depth: null,
Expand All @@ -171,12 +173,6 @@ async function main() {
transformedEntry,
chainSpace.uri,
networkAuthorDid.uri,
async ({ data }) => ({
signature: networkAuthorKeys.assertionMethod.sign(data),
keyType: networkAuthorKeys.assertionMethod.type,
keyUri: `${networkAuthorDid.uri}${networkAuthorDid.assertionMethod![0].id
}` as Cord.DidResourceUri,
})
)

console.log(`\n🌐 Rating Information to Ledger (API -> Ledger) `)
Expand Down Expand Up @@ -210,17 +206,26 @@ async function main() {
depth: null,
colors: true,
})
const revokeRatingEntry = await Cord.Score.buildFromRevokeProperties(
ratingUri,
transformedEntry.entry.entityUid,
networkProviderDid.uri,
async ({ data }) => ({
signature: networkProviderKeys.assertionMethod.sign(data),
keyType: networkProviderKeys.assertionMethod.type,
keyUri: `${networkProviderDid.uri}${networkProviderDid.assertionMethod![0].id
}` as Cord.DidResourceUri,
})
)

/* msgId can be decided by application */
const msgId = `msg-${Cord.Utils.UUID.generate()}`
const transactionTime = new Date().toISOString()

/* this is used for digest, but its again eco-system policy */
const entryTransform = { entryUri: ratingUri, msgId, provider: networkProviderDid.uri, transactionTime }

const revokeDigest = Cord.Utils.Crypto.hashObjectAsHexStr(entryTransform)

const revokeRatingEntry: IRatingRevokeEntry = {
entry: {
messageId: msgId,
entryDigest: revokeDigest,
referenceId: ratingUri,
},
entityUid: transformedEntry.entry.entityUid,
providerDid: networkProviderDid.uri,
}

console.log(
`\n🌐 Rating Revoke (Debit) Information to API endpoint (/amend-ratings) `
)
Expand All @@ -234,12 +239,6 @@ async function main() {
revokeRatingEntry,
chainSpace.uri,
networkAuthorDid.uri,
async ({ data }) => ({
signature: networkAuthorKeys.assertionMethod.sign(data),
keyType: networkAuthorKeys.assertionMethod.type,
keyUri: `${networkAuthorDid.uri}${networkAuthorDid.assertionMethod![0].id
}` as Cord.DidResourceUri,
})
)
console.log(
`\n🌐 Rating Revoke (Debit) Information to Ledger (API -> Ledger) `
Expand Down
6 changes: 0 additions & 6 deletions packages/network-score/src/Scoring.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import { uriToIdentifier, identifierToUri } from '@cord.network/identifier'
import { Chain } from '@cord.network/network'
import { ConfigService } from '@cord.network/config'
import { SDKErrors, DecoderUtils, DataUtils } from '@cord.network/utils'
import { verifySignature } from './Scoring.js'

/**
* Checks if a specific rating is stored in the blockchain.
Expand Down Expand Up @@ -225,11 +224,6 @@ export async function dispatchRevokeRatingToChain(
): Promise<RatingEntryUri> {
try {
const api = ConfigService.get('api')
verifySignature(
ratingEntry.entryDigest,
ratingEntry.authorSignature,
Did.getDidUri(ratingEntry.authorUri)
)

const authorizationId: AuthorizationId = uriToIdentifier(authorizationUri)

Expand Down
Loading