digitalbazaar / bedrock-ledger-node

A Bedrock module that supports the creation and management of decentralized ledgers.
Other
5 stars 4 forks source link

Add basic validation of ledgerConfiguration #15

Open dlongley opened 6 years ago

dlongley commented 6 years ago

I think we should have a basic requirement that ledgerConfiguration has a @context with a string value of https://w3id.org/webledger/v1 or an array value where that string is the first entry. There may be a few other requirements such as a consensusMethod, etc. These must be present for all ledger configs when using the bedrock-ledger-node APIs.

In short, bedrock-ledger-* libraries have some basic requirements that data conform to the core webledger context and we should minimally enforce this by requiring its presence in the @context value and we should enforce a basic shape that plugins, etc. would need to use. Other than that, we can allow extensions to add addition data that custom validator plugins can handle for specific ledgers.

Does anyone object to this approach?

mattcollier commented 6 years ago

Alright, time to deal with this issue.

In addition to the things previously mentioned, it is currently possible to change the value of ledger in the config which I assume should not be allowed. I am I correct in that assumption?

https://github.com/digitalbazaar/bedrock-ledger-node/blob/master/lib/ledger-node-config.js#L75

So, we need to do some JSON schema type validation and if I'm correct, ensure that the ledger value matches the existing config?

mattcollier commented 6 years ago

Here is a minimal ledgerConfiguration for the sake of discussion: https://github.com/digitalbazaar/bedrock-ledger-consensus-continuity/blob/master/test/mocha/mock.data.js#L30

{
  '@context': 'https://w3id.org/webledger/v1',
  type: 'WebLedgerConfiguration',
  ledger: 'did:v1:eb8c22dc-bde6-4315-92e2-59bd3f3c7d59',
  consensusMethod: 'Continuity2017'
}
dlongley commented 6 years ago

@gannan08 -- please check to see if your PR #33 closes this out.