diff --git a/server/plugins/masca/index.mjs b/server/plugins/masca/index.mjs new file mode 100644 index 0000000..dfa61f0 --- /dev/null +++ b/server/plugins/masca/index.mjs @@ -0,0 +1,51 @@ + +export default class MascaPlugin { + /** + * This will initialize all of the hooks used by this plugin. + * A plugin can register multiple hooks, each hook being linked to a function that will be executed when the hook is triggered + */ + async init() { + return { + HOOKS: { + "validate": (stream) => this.isValid(stream), + }, + }; + } + + /** Will check if a valid credential is being saved */ + async isValid(stream) { + + // Check if issuer is in credential + + let validIssuer = false; + let validSchema = false; + if (!stream.content.issuer){ + console.log('failed at issuer') + return false; + } + if(typeof stream.content.issuer === 'string') { + if(stream.content.issuer === this.issuer) + validIssuer = true; + } + else if(stream.content.issuer.id && stream.content.issuer.id === this.issuer) + { + validIssuer = true; + } + + // Check if schema is in credential + if (!stream.content.credentialSchema) { + console.log('failed at schema') + return false; + } + if(typeof stream.content.credentialSchema === 'string') { + if(stream.content.credentialSchema === this.schema) + validSchema = true; + } + else if(stream.content.credentialSchema.id && stream.content.credentialSchema.id === this.schema){ + validSchema = true; + } + + return validIssuer && validSchema; + + } +} \ No newline at end of file diff --git a/server/plugins/masca/settings.json b/server/plugins/masca/settings.json new file mode 100644 index 0000000..e9fcae0 --- /dev/null +++ b/server/plugins/masca/settings.json @@ -0,0 +1,22 @@ +{ + "id": "masca", + "name": "Masca", + "logo": "/img/gitcoin-passport-logo.png", + "description": "Add a way to check for valid credentials in your app.", + "full_description": "This is a plugin that allows you to filter verifiable credentials based on issuer & credential schema.", + "hooks": ["validate"], + "variables": [ + { + "name": "Credential Issuer", + "description": "The credential issuer required for this context.", + "per_context": true, + "id": "issuer" + }, + { + "name": "Credential Schema URL", + "description": "URL of the credential schema.", + "per_context": true, + "id": "schema" + } + ] +}