-
Notifications
You must be signed in to change notification settings - Fork 19
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: add open-attestation schema #57
Conversation
b8379aa
to
ce8f9fa
Compare
ded788d
to
4fea34a
Compare
src/privacy/privacy.ts
Outdated
@@ -73,12 +53,15 @@ export const obfuscateData = (_data: any, fields: string[] | string) => { | |||
}; | |||
}; | |||
|
|||
export const obfuscateDocument = (document: SignedDocument, fields: string[] | string): SignedDocument => { | |||
// TODO shouldn't document be any and shouldn't we validate first it's a valid document ? |
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.
We should validate the schema first, but document shouldnt be any (so we can make use of it's type later), unless you want to cast it after it has been validated.
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.
it depends if we want to trust consumer or not
- if people use typescript then no problems
- if they dont they can pass any value, it may fail without explanation
We should at least leave document as SignedDocument for people using TS, but extra validation would be nice also IMHO)
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.
My concern is that whether people use TS or not, there might be type issue during runtime. Especially when we download and upload document all the time now.
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.
Yes that's what I mean by extra validation would be nice
=> #59
In the meantime, keep the type correct, better for TS :)
145c32b
to
04e697b
Compare
Few other comments:
On W3C compatibility:
|
Also, since this is a breaking change, am wondering if we want to fix the naming of the function for |
|
Can export if you want
skip v1 and start with v2 and upgraded to v3
Yes, I thought about that, but it will be my problem soon so I might come back on this later without breaking change on the lib
I dont fully agree on this, I would rather than oa do something an do it well, than doing too many things, adding in the enhancement suggestion => #60
According to w3c doc, issuanceDate might be renamed to validFrom (same for validUntil). Keeping it like this for the moment
Will fix
|
Changed $template => template |
src/index.ts
Outdated
}; | ||
|
||
export const validateSchema = (document: WrappedDocument): boolean => { | ||
return validate(document, getSchema(`open-attestation/${document?.version || "2.0"}`)).length === 0; |
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.
actually I'm thinking instead of storing 3.0
in the version, does it make sense to store the version as open-attestation/3.0
so that it is unambiguous which version (OA schema or their subschema)? Dont hit me.
src/index.ts
Outdated
export { utils, isSchemaValidationError }; | ||
export * from "./@types/document"; | ||
export * from "./schema/3.0/w3c"; | ||
export { keccak256 } from "js-sha3"; |
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.
was thinking of it more from utils. if not the api looks a bit clunky.
recipient: { | ||
name: "Recipient Name" | ||
}, | ||
reference: "SERIAL_NUMBER_123", |
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.
would you like to fix this in this pr or can do in next one.
Remember to release this as a breaking change in the commit message. Might want to do a manual squash? https://github.com/semantic-release/semantic-release#commit-message-format |
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.
lgtm
c390b38
to
327f04e
Compare
BREAKING CHANGE: New schema to be w3c compliant Changes are: - issuers is not an array anymore. Consequence, proof.value is not an array anymore - issuer.id is a new mandatory field which must be an URI - issuer.identityProof.subject has been remove because it's not needed anymore - @context has been added for w3c compliance to help consumer provide terminology. It's an optional field - id has been updated to follow w3c compliance. It's an optional uri about the subject of the VC - reference has been added and is equal to the previous id - type has been added as the type of the VC (w3c compliance) - validFrom has been added (w3c compliance) - validUntil has been added (w3c compliance). It's an optional field - attachments.type has been updated to follow w3c compliance. It refers to a valid evidence type. - attachments.mimeType has been added and is equal to the previous attachments.type - rename $template to template Adding v2 schema which is a simple version of schema used in tradetrust and opencerts Generate types from schema. Types are exported Update wording: - sign => wrap - SignedDocument => WrappedDocument
327f04e
to
b9d307d
Compare
🎉 This PR is included in version 3.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
MAJOR RELEASE REQUESTED
Schema v2
I've added a v2 schema, it's the same as Tradetrust schema with added certificateStore object for OpenCerts document (https://github.com/TradeTrust/tradetrust-schema/blob/master/schema/1.0/schema.json)
The goal is to provide types, It's not possible to issue a v1 document (to help on adoption of the new schema), however it's possible to validate the schema
Schema v3
I've added open attestation schema v3 following https://github.com/Open-Attestation/adr/blob/master/generalised_verification_method.md. The schema is purposely closed for extension => we can make it less strict without breaking change. List of noticeable things:
Types
Automatic generation of types from the schema using
quicktype
. Types are not committed and are generated post installation (automatically)Usage example
Improvement for
SignedDocument
andSchematisedDocument
types.data
properties are automatically transformed to string using when the SignedDocument type.Improvement for
getData
function typings.APIs changes
issuedDocument
andissueDocuments
: