Created
May 14, 2021 13:38
-
-
Save kuzdogan/444d6ef70c29596a343e71c66ce12532 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { | |
BbsBlsSignatureProof2020, | |
} = require("@mattrglobal/jsonld-signatures-bbs"); | |
const { | |
extendContextLoader, | |
purposes, | |
verify, | |
sign, | |
} = require("jsonld-signatures"); | |
const { documentLoaders } = require("jsonld"); | |
const keyPairOptions = { | |
id: "did:example:489398593#test", | |
controller: "did:example:489398593", | |
privateKeyBase58: "5D6Pa8dSwApdnfg7EZR8WnGfvLDCZPZGsZ5Y1ELL9VDj", | |
publicKeyBase58: | |
"oqpWYKaZD9M1Kbe94BVXpr8WTdFBNZyKv48cziTiQUeuhm7sBhCABMyYG4kcMrseC68YTFFgyhiNeBKjzdKk9MiRWuLv5H4FFujQsQK2KTAtzU8qTBiZqBHMmnLF4PL7Ytu", | |
}; | |
const exampleControllerDoc = { | |
"@context": "https://w3id.org/security/v2", | |
id: "did:example:489398593", | |
assertionMethod: ["did:example:489398593#test"], | |
}; | |
// cached contexts | |
const peerReviewContext = { | |
"@context": { | |
"@version": 1.1, | |
"@protected": true, | |
schema: "http://schema.org/", | |
PeerReviewCredential: { | |
"@id": | |
"https://raw.githubusercontent.com/kuzdogan/peer-review-verifiable-credentials-thesis/main/code/PeerReviewVC.json#PeerReviewCredential", | |
"@context": { | |
"@version": 1.1, | |
"@protected": true, | |
id: "@id", | |
type: "@type", | |
description: "schema:description", | |
name: "schema:name", | |
}, | |
}, | |
PeerReview: { | |
"@id": | |
"https://raw.githubusercontent.com/kuzdogan/peer-review-verifiable-credentials-thesis/main/code/PeerReviewVC.json#PeerReview", | |
"@context": { | |
"@version": 1.1, | |
"@protected": true, | |
id: "@id", | |
type: "@type", | |
title: "schema:headline", | |
content: "schema:text", | |
reviewDate: "schema:dateCreated", | |
competingInterestStatement: "schema:Text", | |
recommendation: "schema:Recommendation", | |
journal: { | |
"@id": | |
"https://raw.githubusercontent.com/kuzdogan/peer-review-verifiable-credentials-thesis/main/code/PeerReviewVC.json#journal", | |
"@context": { | |
"@version": 1.1, | |
"@protected": true, | |
id: "@id", | |
type: "@type", | |
name: "schema:name", | |
issn: "schema:issn", | |
}, | |
}, | |
manuscript: { | |
"@id": | |
"https://raw.githubusercontent.com/kuzdogan/peer-review-verifiable-credentials-thesis/main/code/PeerReviewVC.json#manuscript", | |
"@context": { | |
"@version": 1.1, | |
"@protected": true, | |
id: "@id", | |
type: "@type", | |
title: "schema:headline", | |
abstract: "schema:abstract", | |
}, | |
}, | |
author: | |
"https://raw.githubusercontent.com/kuzdogan/peer-review-verifiable-credentials-thesis/main/code/PeerReviewVC.json#author", | |
}, | |
}, | |
PeerReviewAuthor: { | |
"@id": | |
"https://raw.githubusercontent.com/kuzdogan/peer-review-verifiable-credentials-thesis/main/code/PeerReviewVC.json#PeerReviewAuthor", | |
"@context": { | |
"@version": 1.1, | |
"@protected": true, | |
id: "@id", | |
type: "@type", | |
givenName: "schema:givenName", | |
familyName: "schema:familyName", | |
institution: "schema:Organization", | |
email: "schema:email", | |
}, | |
}, | |
}, | |
}; | |
// _main(); | |
// cached contexts | |
const contexts = { | |
"did:example:489398593#test": keyPairOptions, | |
"did:example:489398593": exampleControllerDoc, | |
"https://raw.githubusercontent.com/kuzdogan/peer-review-verifiable-credentials-thesis/main/code/PeerReview.json": | |
peerReviewContext, | |
}; | |
const customDocLoader = (url) => { | |
const context = contexts[url]; | |
if (context) { | |
console.log(`Found cached ${url}, not requesting`); | |
return { | |
contextUrl: null, // this is for a context via a link header | |
document: context, // this is the actual document that was loaded | |
documentUrl: url, // this is the actual context URL after redirects | |
}; | |
} | |
return documentLoaders.node()(url); | |
}; | |
const documentLoader = extendContextLoader(customDocLoader); | |
const temp = { | |
"@context": [ | |
"https://www.w3.org/2018/credentials/v1", | |
"https://raw.githubusercontent.com/kuzdogan/peer-review-verifiable-credentials-thesis/main/code/PeerReview.json", | |
"https://w3id.org/security/bbs/v1", | |
], | |
id: "http://localhost:3000/reviews/609ac62276bfdce844d8ee6c/credential", | |
type: ["PeerReviewCredential", "VerifiableCredential"], | |
description: | |
"A Verifiable Credential representing a peer review that is done for a scholarly article.", | |
name: "Peer Review Credential version 0.1", | |
credentialSubject: { | |
id: "http://localhost:3000/users/609ac62276bfdce844d8ee6c", | |
type: "PeerReview", | |
competingInterestStatement: "No competing interests", | |
author: { | |
id: "orcid:0000-0001-7223-2669", | |
type: "PeerReviewAuthor", | |
email: "alice@test.com", | |
}, | |
journal: { | |
id: "http://localhost:3000", | |
issn: "2046-1402", | |
name: "International Journal of X", | |
}, | |
}, | |
issuanceDate: "2021-05-11T23:28:18.849Z", | |
issuer: "did:example:489398593", | |
proof: { | |
type: "BbsBlsSignatureProof2020", | |
created: "2021-05-11T23:28:18Z", | |
nonce: | |
"NxeHm6Dx0rEjVf8LguPDssE55ZhQryDnN9sbwG6Famiq/Jq018/Vye9dNlmQmKFmJpM=", | |
proofPurpose: "assertionMethod", | |
proofValue: | |
"ABwJbj/PtfHJmdtKn1wO2EwiYtNGvSuVJoW0JtNYORi2fTU0Ydd+JzT49mAteNzAkLcwjRxZrqM9rAQBTrZOOU7YOrEYZa2R7GmLhaVehsVc96aMiv1IENPJn4yhoI4WpKcuck+Qoy2/dPiGHRvP+Syx2r2liUUGJ49J0ZFKbZ0usJA6fYpQyiJddHgCqrHJYwELtW9PAAAAdIXMjNQ+rkc1inQhpevDRe8Fqr4A0N7sKMNM4W86+abmc2C7j0nWD6x68TD1WwDaGwAAAAI4CmOhzwpdq/MGJmBy7Aix2B8eD+RBpXMPe746R7EnKz0Msj81WCfkMcCWop5w+ZJhyn4gjZh+BAFKpgRx9Eh4raqJKa9Er7krTkL82tDuBR08Kq2KHPcBnpt7e05NFU+RizGVKzjnveE/x9J40bNKAAAACxoQWTRN2YuteVp0niJhzusD2oAcdQmuJQZwBkxKepnHHnTrukZoSh8oNUxVxhhphMNg8WnjxVSBpjM8cszKJBIUD0AmrHfCWMs7D0QrZAhmFpvL2h9O+qrdrUb8q1rmvW41u6JiYpFJyJsl/qKRmMJTdZx1qKAAN3wtvaVXXPA+WWNbByTimNUREAD3UOBPsq5K+hm3csQ5vtIUaMfn8vAzyPwGhhicyhgnjc1UR1pAxBqoTeBe8TecdbnhomaFGQXo8K6t2Qr26eGQU1Q50bpUPoICQJUP1seA6BrKJTJJCR6jTccJP9Z5IBKHWoGRF/VwOzXCu4nq8223lA+n09ZUbr39AsrLeNjgo9h7wtfkkoPyBbhoRRy+BpPuZc6DeB7YOCiHQZKbiZziRQQ/2K/Ka90Lwy7wLiJcTwSCnKGBEDh5x5FDZc7E5qK92Eo9djIhD5Cy0zYSAwDF+drM/z4=", | |
verificationMethod: "did:example:489398593#test", | |
}, | |
}; | |
async function verifySelectiveDisclosedCredential(derivedProof) { | |
const verified = await verify(temp, { | |
suite: new BbsBlsSignatureProof2020(), | |
purpose: new purposes.AssertionProofPurpose(), | |
documentLoader, | |
}); | |
console.log(verified); | |
return verified; | |
} | |
verifySelectiveDisclosedCredential(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment