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

feat: masca-vc-plugin #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
51 changes: 51 additions & 0 deletions server/plugins/masca/index.mjs
Original file line number Diff line number Diff line change
@@ -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;

}
}
22 changes: 22 additions & 0 deletions server/plugins/masca/settings.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}