-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: implement verifier manager #74
Conversation
661d150
to
e95508b
Compare
I've added tests for verifiers (testing the verifier only not internals) |
src/verify.integration.test.ts
Outdated
revokedOnAny: false, | ||
message: "Certificate has not been issued", | ||
status: "INVALID", | ||
type: "OpenAttestationEthereumDocumentStoreIssued" |
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.
Am thinking that the type should be succinct and general, serving more as a class of verification. We can put these as name
of the verification method instead.
Valid class of checks:
INTEGRITY
class verification methods checks if the document has been tampered with.
ISSUANCE_STATUES
class verification methods checks if the document has been issued and is in the right status (ie. not revoked)
ISSUER_IDENTITY
class verification methods checks for the issuer's identity.
In this case the default methods will be:
OpenAttestationTamperCheck -> INTEGRITY
OpenAttestationEthereumDocumentStoreIssued => ISSUANCE_STATUS
OpenAttestationEthereumDocumentStoreRevoked => ISSUANCE_STATUS
OpenAttestationDnsTxtIdentity => ISSUER_IDENTITY
Possible extension will look like:
OpenAttestationEthereumTokenRegistryIssued => ISSUANCE_STATUS
OpenCertsIdentityRegistry => ISSUER_IDENTITY
SomeCountryIdentityRegistry => ISSUER_IDENTITY
CustomExpiryCheck => ISSUANCE_STATUS
Using a known class, it can allow client application to check what type of checks has been performed it they like.
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.
done
src/verify.integration.test.ts
Outdated
}); | ||
{ | ||
message: 'Document issuers doesn\'t have "documentStore" or "token" property', | ||
status: "SKIPPED", |
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.
Just a question...
If I have the OpenCertsRegistry
extension:
- This method will show skipped
- OpenCertsRegistry method will show valid
How should I go about handling it in the method isValid
?
src/index.ts
Outdated
ReturnType<typeof verifyIssued>, | ||
ReturnType<typeof verifyRevoked>, | ||
Promise<boolean> | ||
import { verificationManager } from "./verifiers/verificationManager"; |
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.
import { verificationManager } from "./verifiers/verificationManager"; | |
import { verificationBuilder } from "./verifiers/verificationBuilder"; |
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.
done
src/index.ts
Outdated
.catch(() => false); | ||
|
||
return [hash, issued, revoked, valid]; | ||
const defaultVerificationManager = verificationManager(defaultVerifiers); |
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.
const defaultVerificationManager = verificationManager(defaultVerifiers); | |
const verify = verificationBuilder(defaultVerifiers); |
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.
done
src/index.ts
Outdated
export { | ||
verificationManager, | ||
isValid, | ||
isInvalid, | ||
openAttestationEthereumDocumentStoreIssued, | ||
openAttestationDnsTxtIdentity, | ||
openAttestationTamperCheck, | ||
openAttestationEthereumDocumentStoreRevoked, | ||
defaultVerifiers, | ||
defaultVerificationManager | ||
}; |
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.
export {
verify,
verificationBuilder,
isValid,
isInvalid,
defaultVerifiers,
verifiers
}
src/index.ts
Outdated
|
||
return [hash, issued, revoked, valid]; | ||
const defaultVerificationManager = verificationManager(defaultVerifiers); | ||
const isValid = (verificationFragments: VerificationFragment[]) => |
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.
isValid(document, requiredChecksClasses)
usage example
isValid(document, ["ISSUER_IDENTITY", "ISSUANCE_STATUS", "INTEGRITY"])
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.
Basically isValid checks the fragments that EVERY required checks classes to have at EVERY test either "VALID" or "SKIPPED" and has at least one "VALID".
For example for a documentStore
issued: valid
revoked: invalid
will result in "invalid"
In another case:
issued: valid
revoked: skipped
will result in "valid"
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.
done
0d43910
to
fc71611
Compare
return documentData.proof.method === v3.Method.TokenRegistry; | ||
} | ||
const documentData = getData(document); | ||
return documentData.issuers.every(issuer => "tokenRegistry" in issuer); |
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.
For token registry, we should check of any
/some
instead of every
.
The reason is that if it's using tokenRegistry it MUST be only one issuer, cannot mix it around with documentstore or other tokenregistry.
In the verify function we can throw INVALID
if it has been mixed
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.
done, returning error if more than one token registry or mix of methods
return documentData.proof.method === v3.Method.DocumentStore; | ||
} | ||
const documentData = getData(document); | ||
return documentData.issuers.every(issuer => "documentStore" in issuer || "certificateStore" in issuer); |
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 test using some
instead?
This will make the verify run for documents that mixes around documentStore and other methods, and that's where this function should throw?
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.
done, returning error if one of the issuer is invalid (i.e. doesnt have document store or certificate store)
BREAKING CHANGE implements https://github.com/Open-Attestation/adr/blob/master/verifier.md
7012bd0
to
5b569b1
Compare
🎉 This PR is included in version 2.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Quick summary
Implementation details
verificationManager
is a function that takes a list ofverifiers
and return a function. The function expect a signed document and some options as parameter. Options parameter expect the following:network
string (for instance ropsten)infuraApiKey
stringpromisesCallback
callback function that will provide back the promises resolving to the verifications.verifiers
:defaultVerificationManager
pre-built having in parameter all the verifiers available in this repositoryisValid
andisInvalid
verifier
is an object that expect 3 functions:TODO